2

I'm trying to convert my website/book (HTML+CSS) to a single PDF for reading on Amazon Kindle but unfortunately Kindle does not support transparent GIF/PNG images (I have a lot of equations on my website that have transparent background).

I tried several approaches:

1) KindleGen v2.3 -- even though my html is quite simple it contains tables, images, CSS and the result of conversion is not pretty.

2) I tried wkhtmltopdf but there was another problem: I have a table in my HTML that is wide and wkhtmltopdf didn't scale it. It just extended dimensions of the whole pdf document which is quite annoying.

3) I tried mpdf library for creating PDF from HTML and the result is nice but blank spaces are shown instead of transparent images.

  • I'm trying to change background of images (equations) according to the background on which they are placed. It can be done, in my case, via DOM but it is not really elegant solution. How would you do that?

How do you convert complex HTML to PDF for Kindle? Thanks!

MartyIX
  • 27,828
  • 29
  • 136
  • 207

4 Answers4

2

You can generate .mobi files from HTML with kindlegen (well, prc, but that's almost the same...)

If you are not satisfied with the results, another tool to consider is Calibre which is the swiss army knife of ebook cataloging and conversion (and it can create mobis from HTML).

Regarding transparent images: yeah, Kindle can't do that (yet). A recommended solution is to use something like white background... but that's not ideal. You can use something like imagemagick, to prepare to the proper format as described here.

About PDFs on the Kindle: IMO it's less than ideal (except Kindle DX)... You can't reflow the text with different font size. The margins on PDF pages are useless from a reader point of view (and there are tools the get rid of them in PDF files)... So I'd recommend .(mobi|prc).

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
  • Yes, I tried kindlegen as I wrote in the question. I know Calibre but I was not aware that it can convert HTML to mobi, thanks!! I've come up with a imagemagick command for adding the background but as you have said it is not ideal. I convert to PDF because I'm not sure how much limited is mobi format (e.g., if it can handle tables) and because I don't have much control over the process of conversion whereas I can create PDF with various tools and set different settings. – MartyIX Jan 29 '12 at 19:47
  • I'm aware of the fact that reflowing is problematic with PDFs but I can create several PDFs with various font sizes which partially solves the problem. On the other hand I may struggle with mobi format because it was not designed for what I'm doing. http://wiki.mobileread.com/wiki/MOBI – MartyIX Jan 29 '12 at 19:51
  • Here are the supported `HTML` tags' table: http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen&File=TagRef_OEB.htm and some info on using tables: http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen&File=tables.htm – Zsolt Botykai Jan 29 '12 at 20:41
  • 1
    I can speak only from my point of view, but I would never pick a PDF on my Kindle if the `.mobi` or `.prc` is available. Anyway, it's your decision... – Zsolt Botykai Jan 29 '12 at 20:47
  • 1
    The PDF creation process is better known, but the result is awful for ebook readers - even if it is used on devices with good support like the Sonys. The problem is not solved as PDF de facto forbids text size changes for the user. I am not exactly sure why you think that mobi is not designed for what you are doing. – Hauke Ingmar Schmidt Jan 29 '12 at 20:51
  • his: I'm simply concerned that the result of html -> mobi|prc won't as good (nicely shown on Kindle) as html -> pdf conversion. But I will give it a try. – MartyIX Jan 30 '12 at 15:01
  • 1
    Please do, the users/readers will thank you. PDF is for pixel/mm-perfect layout which is ok when you print (as long as you print on exactly the defined paper format, that is). Just this (PDF defining) property makes it an awful format for ebook readers - especially with the Kindle which has not top-of-the-herd PDF rendering capabilities. – Hauke Ingmar Schmidt Jan 30 '12 at 15:18
1

I've heard wkhtmltopdf is a good project that uses WebKit.

It's free, so it won't hurt to try it.

Blender
  • 289,723
  • 53
  • 439
  • 496
  • I tried it. Forgot to mention that but there was another problem: I have a table in my HTML that is wide and wkhtmltopdf didn't scale it. It just extended dimensions of the whole pdf document which is quite annoying. – MartyIX Jan 29 '12 at 14:42
  • That's the way that it renders on your browser. You can force your document to be a certain width by using CSS, though: `max-width: 8in;`. – Blender Jan 29 '12 at 14:53
  • You may come up with a table that is simply not able to fit in the 8 inches because font sizes, wrapping and minimal width of cells. So it works in majority of cases but not always and in my case it won't work. Unfortunately, there was no plan for Kindle edition when the website was created. – MartyIX Jan 29 '12 at 19:40
  • What is your expected behavior for large tables? – Blender Jan 29 '12 at 19:44
  • I don't want to be picky: Scaling or simply cut the table between columns and put the rest of the table under the first part would be good. Any solution that would keep the size of page fixed to 8in is good for me. – MartyIX Jan 29 '12 at 19:56
1

I'll wait for Kindle Format 8 (KF8) because it should provide everything I need and I'll use a PDF meanwhile.

All conversions from html to mobi format are simply not good enough. ePub format would be great but that is not supported on Amazon Kindle 3.

Thank you all for help!

MartyIX
  • 27,828
  • 29
  • 136
  • 207
0

If you want a fluid design, I've found the happy path to be going from ODT to HTML in Open Office, then opening that in Sigil and cleaning up the HTML, then breaking into chapters, assigning book cover and building TOC, all in Sigil, then checking with Sigil's built in validator, FlightCrew, and Kindle Previewer.

If you've got a comic book with exacting requirements for images, take someone else's advice.

Hope this helps!

Diane
  • 1
  • 2