Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Convert HTML to PDF using script

I would like to change an HMTL file to a PDF - output must be Legal size, Landscape, and shrink the content to Calibri 8, using a script.
Is this possible?
Thank you. 
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

Take a look here https://gallery.technet.microsoft.com/scriptcenter/Convertto-PDFFile-dda02118
There's a Powershell script wich should be useful 
I use adobe acrobat for this myself. It is very easy to just "Create from file" or "Create from web page".  Other software that can do this include https://www.tracker-software.com/product/pdf-xchange-editor or https://www.foxitsoftware.com/blog/pdf-to-html-conversion/

I use Acrobat the most and adjusting the settings are part of the workflow.
1) First test the HTML for syntax errors.

https://validator.w3.org/nu/ provides a highly useful tester.

2) If syntax is valid, use the soffice command line tool (part of LibreOffice) to do you conversion.

3) If syntax is invalid, use an editor. As Scott suggested, acrobat works well for this.
Hi,

If you need that the user generate the PDF from the web page you will need PHP and a script like
HTML2PDF https://github.com/spipu/html2pdf
It uses TCPDF for the PDF part  and allow more CSS than other script.
Note CSS is always limited with PDF so you need to keep it as simple as possible and do not use huge CSS file.
If you don't use Composer you can download directly https://php-download.com/package/spipu/html2pdf
select the create-project version.
You can set the font, direction, header / footer etc.
Avatar of skullnobrains
skullnobrains

i second all the above for the conversion.

if you want calibri, you can use css or inline styling to set that in the original html.

achieving legal file size and landscape might proove challenging. some converters understand css print hints. fpdf can be hacked to create a page in landscape then import html.

html2pdf is a simple linux tool thay has -1 option for landscape. i am unsure whether there is a windows port.
@skullnobrains Sorry but I think you are confused about what  Html2Pdf is

 Html2Pdf  I'm referring to is not a linux tool!
 Html2Pdf is a HTML to PDF converter written in PHP.
 It is a PHP code that use TCPDF librairy and it has landscape option.

You just set it using L option
$html2pdf = new HTML2PDF('L', 'A4', 'en');

Open in new window


both exist and they are 2 different tools
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.