How can I convert HTML to pdf?

2

1

I want to read and annotate internet articles like books on my iPad so I would like to convert HTML to PDF. Is there a way of doing this that

  • preserves every font as is
  • can make PDF out of selection
  • handle javascript source code highlighting libraries well
  • doesn't add anything (ads from shareware or logos etc) to every page

I will be happy with any solution applicable to iPad or OSX. I have tried some converters I have found online but none fit the criteria above.

kissgyorgy

Posted 2013-06-27T01:02:57.470

Reputation: 612

Answers

0

You don't have to use extra programs always if you have Google Chrome. In google chrome open the HTML file, then Go Settings-->Print and then printing page will be opened. On this page click "Change" button which is next to destination section and then select "Save as a PDF" --> OK Then "print" button will turn into "save" button. Now press the save button and save your HTML file as a PDF. [ For online web pages it's very very usefull for example if you fill form on the web page your form informations will be appeared on the pdf file.] Enjoy!

BARIS KURT

Posted 2013-06-27T01:02:57.470

Reputation: 56

4

One possibility would be to use wkhtmltopdf:

Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.

Given a directory that contains HTML files, you could run this from a terminal:

for i in *html; do wkhtmltopdf $i $i.pdf; done

Not sure what you mean about javascript. If you want to make pdfs with code highlighting of the actual source code (without rendering the HTML), see my answer here. I also don't know what you mean by "make PDF out of selection".

terdon

Posted 2013-06-27T01:02:57.470

Reputation: 45 216

See this article: http://blueprintforge.com/blog/2012/01/24/measuring-optimising-database-performance-in-django/ it highlights the example codes, with a nice, green background, but even wkhtmltopdf don't fully render the page either, so it doesn't convert the colors :( and all I got is a black and white pdf with pictures

– kissgyorgy – 2013-06-27T01:19:39.933

1@Walkman You may want to go to the previous release of wkhtmltopdf. IIRC, there were some issues with the latest on up there, especially related to the graphics. – John Szakmeister – 2013-06-27T01:27:09.847

@Walkman I get pretty good results as long as I specify the CSS style sheet. I saved the link you posted as "foo.html" and its assiciated files in "foo_files", then ran wkhtmltopdf --user-style-sheet foo_files/screen.css foo.html foo.pdf and got this pdf which has colors and syntax highlighting.

– terdon – 2013-06-27T01:37:57.373

@jszakmeister THIS IS (almost) PERFECT thank you! I downloaded the version 0.10.0_rc2 and this renders the page nicely, even with colors, without any other option.

– kissgyorgy – 2013-06-27T01:43:34.287

Now I only have to figure it out how to convert only part of the page? for example the main article without any clutter – kissgyorgy – 2013-06-27T01:44:04.587

@Walkman I don't know how you could stop it from converting to pdf. You could, however, use something like PDF tool kit to extract only the pages you want from the PDF.

– terdon – 2013-06-27T02:25:50.853

PDF toolkit can only cut whole pages, not lines, but thanks for the tip. This will be another question I guess. – kissgyorgy – 2013-06-27T02:38:05.753

0

Try this service. Creates a PDF from a website as you see it in the browser. https://lomotoh.com/ Preserves fonts and layouts. As well as original links to the website. (I am affiliated with this site).

David Herse

Posted 2013-06-27T01:02:57.470

Reputation: 101

Are you perhaps affiliated with this service, seeing how you’re eager to advertise it? – Daniel B – 2016-10-15T21:57:54.867

0

The best and easy way for conversion is to use pdf conversion extension that very accurate and useful.

Word to PDF

Antonio Cristian

Posted 2013-06-27T01:02:57.470

Reputation: 1

1

Welcome to Super User! Please read how to recommend software in answers, particularly the bits in bold; then edit your answer to follow the guidelines there. Thanks!

– bertieb – 2019-01-07T06:56:15.573

-1

You can use evernote web clipper plugin for chrome, to save web pages as PDF and they will be instantly available in your evernote account. Or you can use Pocket which is a wonderful read it later service. Although it wont allow you to save pages as PDF but it converts web pages in easy to read article format, and you can read them using its iPhone, iPad, android or chrome app.

Amritanshu Pandey

Posted 2013-06-27T01:02:57.470

Reputation: 69

I can't seem to save the selected area as PDF (greyed out) did you mean this funcionality? The whole point is annotation on a tablet, which you can't do with either Pocket or Evernote. – kissgyorgy – 2013-06-27T03:18:25.023