convert php file to pdf using mpdf - php

I can convert html page to pdf and send it via email with out any problem, but I am facing trouble with converting php file to pdf.
is it possible to convert php file to pdf using mpdf or do I need to use some other php class for this?
Thanks!

The option seems to be like, first convert the output of the php file to html file, save it and pass that file to mpdf.
Thought my solution may seem other way round but it worked well for me.
Or otherwise this Link
<?php
$file = '/home/user/Desktop/myfile.html';
$result = file_get_contents("url/of/ur/page");
echo $result; //view source now
file_put_contents($file, $result);
?>
now u can pass this file to mpdf. Realie sorie bt i havnt used mpdf till date. May be this solution works for you.
Also, other option is curl.

Related

how to get html code from pdf,docx,doc using php

I want to convert any pdf,docx,doc file into html code using php. with same style as in pdf. I am not getting proper solution.
Config::set('pdftohtml.bin', 'C:/poppler-0.37/bin/pdftohtml.exe');
// change pdfinfo bin location
Config::set('pdfinfo.bin', 'C:/poppler-0.37/bin/pdfinfo.exe');
// initiate
$pdf = new Gufy\PdfToHtml\Pdf($item);
// convert to html and return it as [Dom Object](https://github.com/paquettg/php-html-parser)
$html = $pdf->html();
Not working for me.
I had a similar problem and i found a github that i used with word docs. It worked fairly good then but i havent tested it of late. try it.
https://github.com/benbalter/Convert-Word-Documents-to-HTML
I think that this post could help you in a first time. With this one, you'll be able to convert any pdf into HTML code using PHP.
After this, you can use the help provided by this post to convert .doc and .docx to PDF using PHP.
I think that you can now built a function for each document extension that you want to convert into HTML.
Good luck.
I've come across a web service which presents an API for converting documents. I haven't tested it very thoroughly but it does seem to produce decent results at converting Word to HTML:
https://cloudconvert.org/

How to convert html into *.xlsx using php?

Good morning.
I have a test.html file. I would like to convert into test.xlsx using php.
Now, I could create test.xls file using php, whereas it is having only html tags due to that this file could not open directly in excel and it shows extension error. so if the file is having test.xlsx format gets opened smoothly.
I did not know that how to proceed further to get an expected results.
Please help if possible.
Thanks in advance.
Best regards,
Balraj
Use PHPExcel_Reader_HTML function of PHPExcel

Force download html to pdf using php

I try to make force download html-file to pdf and use the code below
<?php
header('Content-disposition: attachment; filename=\''. basename($file) .'\'.pdf');
header("Content-type: application/pdf");
echo file_get_contents($_SERVER['DOCUMENT_ROOT'].'/index-1.html');
?>
I get some file with .pdf extention but when I try to open it, i get an error `not PDF or corrupted'. What's wrong and how to make it work?
Telling the browser that some data is a PDF will not magically transform the data into a PDF.
You'll need to do that yourself, e.g. using the PHP PDF library or Prince.
You have to create a properly PDF file. You can do this using some PHP classes like HTML2PDF or wkhtmltopdf.
You can't just put html in a pet file and expect it to work you need to use something like dompdf to convert html to a pdf file: https://code.google.com/p/dompdf/
For even better results and support for floats I would use the following library. I got extremely good results with it. The reason why this one is working so well is because they use the WebKit browser rendering engine to render the html before converting it to pdf giving you almost 1 on 1 results when comparing it to the browser.
https://code.google.com/p/wkhtmltopdf/

pdftotext with external URLs (PHP)

I want to make PDFs from external URLs searchable. I'm using pdftotext from XPDF.
It's working fine with PDFs already on my webspace, but I keep getting an error message when trying to use external PDFs instead. Specifically I get:
"Error: Couldn't open file 'https://www.vericoa.com/sandbox/test2.pdf' "
Here is my code
$path = 'https://www.vericoa.com/sandbox/test2.pdf';
echo shell_exec('pdftotext -enc UTF-8 '.$path.' pdf.txt 2>&1');
$file = file_get_contents('pdf.txt');
echo $file;
Is it even possible to extract text from external PDF sources? Are there any alternatives (I spent the last hours searching, but found nothing).
Thanks in advance
Matthias
You could perhaps try downloading the external URL in php, saving it to a file and passing that to the pdftotext script?

Webpage convert to PDF button

I have a website now and I want to create a button on it to convert this page to PDF.
Is there any code to make this happen? I cannot find it on the internet.
So I want to have a button and when I press on it it converts the page to a .PDF file.
I do not want to use a third party website to generate the PDF's. I want to use it for internal purposes to generate files with PHP. So I need the code what can make a PDF for each page.
I use wkhtmltopdf - works very well - http://code.google.com/p/wkhtmltopdf/ there is a PHP wrapper
Updated based on comments below on usage :
How to use the integration class:
require_once('wkhtmltopdf/wkhtmltopdf.php'); // Ensure this path is correct !
$html = file_get_contents("http://www.google.com");
$pdf = new WKPDF();
$pdf->set_html($html);
$pdf->render();
$pdf->output(WKPDF::$PDF_EMBEDDED,'sample.pdf');
Use FPDF. It's a well-respected PDF-generating library for PHP that is written in pure PHP (so installing it should be dead simple for you).
Try this:
http://www.macronimous.com/resources/Converting_HTML2PDF_using_PHP.asp
It will convert HTML to a PDF using FPDF and HTML2PDF class.
Also found this:
http://www.phpclasses.org/package/3168-PHP-Generate-PDF-documents-from-HTML-pages.html

Categories