this was my original question I was stuck and tried to solve my problem by trying something and got stuck again
I need to extract name of candidate and his id from a pdf ,so after using pdfparser I extracted the text and downloaded the html page using php
<?php
$filename = 'filename.html';
header('Content-disposition: attachment; filename=' . $filename);
header('Content-type: text/html');
// ... the rest of your file
?>
<?php
// Include Composer autoloader if not already done.
include 'C:\Users\amite\Downloads\pdfparser-master (1)\pdfparser-master\vendor\autoload.php';
// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('C:\Users\amite\Desktop\Data\001.ApplicationForm-CSE-2015-1-omokop (3).pdf');
$text = $pdf->getText();
echo $text;
?>
I did this cause the info I need that was on line 12 and 13 of the view source page and this was was with all the pdf's I need ,so after downloading the html file I used the code below to see the source page of html file
<?php
show_source("filename.html");
?>
now when I run the above program I got the source page of html file which I downloaded, now I need to extract data from line 12 and 13 , the output of program looks like this :-
<html>
text
text
text
text
text
text
there are no tags except html tag and info I need is on line 12,13, if you need any clarification please ask me I will tell you.
how should I extract text from line 12,13, if there is another way tell me pls. I am stuck again, if the question is vague I will clarify it or improve it, please help me.
Store the file source into an array with $source = file('filename.html'); and extract line 12 and 13 via array index 11 and 12 like this echo $source[11]; //line 12
Is this what you need?
<?php
$str = "1text
2text
3text
4text
5text
6text
7text
8text
9text
10text
11text
12text
13text
";
$k = array_slice(explode("\n",$str),11,1);
print_r($k);
Related
please I need help I'm trying to create a SEPA XML file so I downloaded the sepa-xml with coenter image description heremposer in my project then I make the same code in the documentation to test if work or not so when I enter image description hereadded the code and generate the file I get an empty file. but when I dump the variable I get a result .
I get this page
I referred here. Looks like you need to download the generated xml code.
[Git link][1].
Code will be like this.
header('Content-disposition: attachment; filename="newfile.xml"');
header('Content-type: "text/xml"; charset="utf8"');
echo $directDebit->asXML();
exit;
In this case the generated code will be saved as newfile.xml and download the file automatically. Hope it solves your problem
[1]: https://github.com/php-sepa-xml/php-sepa-xml/blob/master/doc/direct_debit.md
This question already has answers here:
How to return a file in PHP
(4 answers)
Closed 3 years ago.
Hi i got an xml file and i want to display it on a website.
I tried everything what i found and tried to do it my self but im a newbie to any code language.
My code is this right now:
<?php
header('Content-type: text/xml');
$xml = simplexml_load_file(xmlfile.xml) ;
echo $xml ;
?>
And the output what i see when i go to my website is nothing just a warning about: This XML file does not appear to have any style information associated with it. The document tree is shown below.
But i cant see anything. So please can someone help me write a code that outputs the whole xml file including xml declaration , tags and node values?
You do not have to use the simplexml_load_file: there is another function to read a file, this function is file_get_contents($filename).
Here is a simple code to use:
<?php
// Set the encoding to XML
header('Content-type: text/xml');
// Get contents of the file
$xml = file_get_contents("xmlfile.xml") ;
// Print contents
echo $xml;
?>
I hope it helped you! And sorry for the language mistakes ;)
Try this code. It works for me.
<?php
header("Content-type: text/xml");
$yourFile = "xmlfile.xml";
$file = file_get_contents($yourFile);
echo $file;
If you insist on simple xml you can write like this.
$xml = simplexml_load_file("xmlfile.xml");
echo $xml->asXML();
I have a piece of code which polls a CRM system and finds a specific document via a URL..... from the document which is found, this is then added to a PHP variable - however if I then print the PHP variable it's just garbage. How can I take the PHP variable and out the contents to PDF (it is a PDF already stored in the variable).... so it can be either downloaded or opened to screen?
Here is the code being used:
**$url = "accounting/invoices/55120.pdf?template=30&api_key='My-API-Key'";
$pdf = $thisbooks->get($url, array(), array('decode_json' => false));
// Ensure the response looks like a PDF
if (!preg_match('/^\%PDF\-1\.4\s/', $pdf)) {
$thisbooks->log('ERROR: Unexpected response: is it a PDF?', $pdf, 'error');
}
$thisbooks->log('Fetched PDF', $pdf);
print $pdf;**
Now when I print the $pdf variable I can see the script code, but it doesn't do anything else.....
Thanks in advance
Damian
did you try to use file_get_contents to read your variable?
or use this header: header('Content-type: application/pdf');
If you send your code maybe we can help more.
I have a FlipBook jquery page and too many ebooks(pdf format) to display on it. I need to keep these PDF's hidden so that I would like to get its content with PHP and display it with my FlipBook jquery page. (instead of giving whole pdf I would like to give it as parts).
Is there any way i can get whole content of PDF file with PHP?
I need to seperate them according to their pages.
You can use PDF Parser (PHP PDF Library) to extract each
and everything from PDF's.
PDF Parser Library Link: https://github.com/smalot/pdfparser
Online Demo Link: https://github.com/smalot/pdfparser/blob/master/doc/Usage.md
Documentation Link: https://github.com/smalot/pdfparser/tree/master/doc
Sample Code:
<?php
// Include Composer autoloader if not already done.
include 'vendor/autoload.php';
// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('document.pdf');
$text = $pdf->getText();
echo $text;
?>
Regarding another part of your Question:
How To Convert Your PDF Pages Into Images:
You need ImageMagick and GhostScript
<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
?>
The [0] means page 1.
In the last few hours I found script for php which converts a .doc file to a .html file but I've not been successful yet.
I just made some simple code for it, like this:
<?php
header("Content-type: application/html");
header("Content-Disposition: attachment;Filename=as.html");
echo $content = readfile('abc.doc');
?>
It makes an output like the one shown below in the image.
any other way to do this ? as same to same as .doc file ?
Did you already search for a solution? I just found this link, perhaps it might help you:
http://www.daniweb.com/web-development/php/threads/130342/convert-.doc-to-html-or-txt-on-fly-during-upload-with-php