Convert PHP result to PDF using PHP? - HTML2FPDF - php

So I've been working a bit with HTML2FPDF, and I have converting HTML to PDF working all fine. However, I cannot get any PHP to work. Not even static PHP like
echo "hello world";
it is just completely ignored. I thought this would render as HTML and it then would be included in the PDF, but it doesn't.
I wanna be able to run some PHP functions and then for the result to come out as HTML like it normally would. Is there a way to do this?
I am thinking that one way of doing this is to load the PHP function first. Then when the function has run and the result shows as HTML, then convert the page. I have tried this for a few hours now, with all sorts of solutions, but I can just not get it to work in any way.
Is there a way to convert PHP results to PDF as well?

Sounds like you don't have it installed properly.
You have just to launch the following command on the root folder of your project:
composer require spipu/html2pdf

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

dompdf and php (mysql data)

I would like to pull data from a mysql db.
This data is then inserted into a html file which is then converted to a pdf using dompdf.
The template is perfect and display's well when I run call dompdf.
However as soon as I try and insert php code, the template still shows perfectly, how ever the php code is displays nothing. If I open the page its shows, so I know it works.
In the options file I have done this :
private $isPhpEnabled = true;
my php file to call the template (LeaseBase.php):
<?php
$options = new Options(); $options->set('isPhpEnabled','true');
$leasefile = file_get_contents("Leases/LeaseBase.php");
$dompdf = new Dompdf($options); $dompdf->loadHtml($leasefile);
$dompdf->stream(); $output = $dompdf->output(); file_put_contents('Leases/NewLeases.pdf', $output);
?>
I also can't seem to pick up anything in the log files.
Any assistance is appreciated
However as soon as I try and insert php code, the template still shows
perfectly, how ever the php code is displays nothing.
Answer: It shows nothing because when a php page is executed, it outputs html (and not the php code). If you don't have an echo or print or any code that generates html code from the php script, the page will in fact be blank.
It's important to remember that php is serverside code WHICH CAN generate html code as long as you instruct it accordingly.
With versions of Dompdf prior to 0.6.1 you could load a PHP document and the PHP would be processed prior to rendering. Starting with version 0.6.1 Dompdf no longer parses PHP at run time. This means that if you have a PHP-based document you have to pre-render it to HTML, which does not happen when using file_get_contents().
You have two options:
First: Use output buffering to capture the rendered PHP.
ob_start();
require "Leases/LeaseBase.php";
$leasefile = ob_get_contents();
ob_end_clean();
Second: Fetch the PHP file via your web server:
$leasefile = file_get_contents('http://example.com/Leases/Leasebase.php');
...though, actually, if I were loading the file into a variable and feeding it to dompdf without doing any further manipulation I would use dompdf to fetch the file instead. In this way you are less likely to have to deal with external resource (images, stylesheets) reference problems:
$dompdf->load_html_file('http://example.com/Leases/Leasebase.php');

How to add text on pdf using PDFJam

I am using PDF Jam for manipulating pdf. I need to add a text line at the bottom of generated file. I tried it but not able to made it.
Can anybody guide me how to do it?
I did in my php code as
$command = '-----------------';
exec($command);
As you know, PDFJAM is for manipulating pds. It is a small collection of shell scripts which provide a simple interface to much of the functionality of the excellent pdf pages. See the Ubuntu Manual
pdfjam - A shell script for manipulating PDF files
You should create your sheet as your doing (5x6) and create a separate sheet of minimal page size with required information than merge both the file into one.
Else in first step create your sheet and use pdflib to add text as second step. It very good tool. I hope its a good solution of your problem.
I love pdftk and so wanted to find a solution using that. The following worked for me.
pdfjam --preamble '\usepackage{fancyhdr} \topmargin 85pt \oddsidemargin 140pt \cfoot{\thepage}' --pagecommand '\thispagestyle{plain}' --landscape --nup 2x1 --frame false --clip true --trim ".5in 0.5in 0.5in .65in" --delta '-0.25in 0' tmp.pdf
I cribbed it from: Page Numbering with the "{page} of {pages}", removing the "of pages" part.
Command converts pdf to 2x1, trims margins, and crops. Output is landscape.
\topmargin and \oddsidemargin seem to tell pdflatex where to put the numbers.

How to print out file with help PHP

Is there any way to print out (to cups for example) html file with help PHP (linux server without X) ?
except shell_exec(), system() etc...
And when i mean print html file means print not source code, means print rendered result.
is it possible with help PHP ?
I know thath there is some possibilities like,
- run X server,
- run browser,
- exec terminal command which will ask browser open and print out html file
but without shell_exec is it possible ?
You'll need to render the file yourself into some sort of printable format such as a postscript or PDF file. There is a good PHP5 library to create PDFs from HTML called dompdf.
So generate the HTML output and store it into a string, you may want to use output buffering to do this. See the PHP manual.
Then you can use dompdf to render the HTML contents into a PDF file. Storing it into a temp directory probably makes sense if you don't need to keep the file.
Then, you can use the cups cli to print the file, see the cups documentation. e.g.
shell_exec('lp '.$filename);

Categories