Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 07-25-2025, 07:36 PM   #1
martinmcu
Junior Member
martinmcu began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Jan 2025
Device: Kindle PW5SE
Fixed Layout EPUB to PDF Failure

Hello,

i am pulling my hair out trying to get this book to convert. It should never have been created as an EPUB in the first place, as every page has a background image that covers 100% of the page, and all the text is designed to precisely overlay those graphics. As a result, it renders horrifically on my Kindle (jailbroken with KOReader). Rant aside, please help!

I have attached an epub that renders correctly in Calibre 8.7.0 that contains only the table of contents page. I have edited this using the built-in epub editor, and running "Check book" comes back error free. Reading this epub in Calibre produces the following page:



However, the PDF output is atrocious (But it does seem to match the rendering inside of KOReader):



I am attempting the conversion from the command line using the following command:

Code:
ebook-convert 'Minecraft_ Guide to Combat - Mojang Ab.epub' .pdf -u devicepixel --custom-size 838x1188 --disable-font-rescaling --embed-all-fonts -vv -d ./Debug --pdf-page-margin-right=0 --pdf-page-margin-left=0 --pdf-page-margin-bottom=0 --pdf-page-margin-top=0 --pdf-no-cover --uncompressed-pdf
The desired output would be a PDF that is an exact representation of that page, with no border around the outside. The page size was chosen based on the following portion of the CSS:

Code:
#spread_6-div-1 {
  -webkit-transform: translate(0, 0) rotate(0deg) skew(0deg) scale(1, 1);
  -webkit-transform-origin: 0% 0%;
  height: 1188px;
  left: 0;
  position: absolute;
  top: 0;
  transform: translate(0, 0) rotate(0deg) skew(0deg) scale(1, 1);
  transform-origin: 0% 0%;
  width: 838px;
}
There was something similar for every page in the full epub, with consistent width/height dimensions.

In looking through the debug output, the html generated at the processed step renders the same in Calibre as the input epub. I converted to epub as follows and imported it into Calibre

Code:
cd Debug/processed
zip -r processed.epub *
Attached Files
File Type: epub Minecraft_ Guide to Combat - Mojang Ab.epub (230.0 KB, 6 views)
File Type: pdf Minecraft_ Guide to Combat - Mojang Ab.pdf (697.6 KB, 5 views)
File Type: epub processed.epub (892.5 KB, 3 views)
martinmcu is offline   Reply With Quote
Old 07-25-2025, 10:14 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibre does not support fixed layout books.
kovidgoyal is offline   Reply With Quote
Advert
Old Yesterday, 12:05 AM   #3
martinmcu
Junior Member
martinmcu began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Jan 2025
Device: Kindle PW5SE
In what way does Calibre not support them? The viewer is rendering the book correctly, and all of the processing steps up until PDF output seem to be preserving the properly formatted EPUB. What is the rendering engine for this final step?

Thanks for your prompt initial reply! I'm really hoping to find a way to make this book usable for my kid.
martinmcu is offline   Reply With Quote
Old Yesterday, 05:28 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It doesnt support them in any way. If it happens to work in the viewer, that is entirely accidental.
kovidgoyal is offline   Reply With Quote
Old Yesterday, 09:48 AM   #5
martinmcu
Junior Member
martinmcu began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Jan 2025
Device: Kindle PW5SE
Ahhh, understood. I will enjoy the happy accident of it working in the viewer then. Thanks so much! Calibre is one of the greatest pieces of software ever, and makes having a library of ebooks possible and enjoyable.
martinmcu is offline   Reply With Quote
Advert
Old Yesterday, 07:12 PM   #6
martinmcu
Junior Member
martinmcu began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Jan 2025
Device: Kindle PW5SE
Solved!! Admittedly, not entirely within the framework of Calibre, but worth documenting for others. Here are the steps that I took:
  1. Edit the epub inside of Calibre. The CSS needed to be updated to define the page size properly. These were the lines that were added to force a precise page size with no margins:
    Code:
    @page {
      size: 838px 1188px;
      margin: 0;
    }
    After the CSS was updated, I made sure that "Check book" came back clean
  2. Unzip the epub to a temporary working folder.
  3. (Optional) Optimize background images. While the CSS defined a page size of 838x1188 pixels, the actual images were much larger. Using Imagemagick on Linux made this trivial:
    Code:
    cd /tmp/book/OEBPS/images
    for i in $(ls -1 page*jpg); do convert $i -resize 838x1188 small_$i; mv small_$i $i; done
  4. Remove links from table of contents page. Unfortunately, I could not figure out a way to keep the links valid. After converting, they were referring to the absolute paths to the expanded xhtml files on my computer. In this case, a simple sed script cleaned this out:
    Code:
    cd /tmp/book/OEBPS/xhtml
    sed -re 's:<a href=\"spread_[0-9]+.xhtml\">::g;s:</a>::g' -i spread_6.xhtml
  5. Convert each individual xhtml file to PDF using WeasyPrint:
    Code:
    cd /tmp/book/OEBPS/xhtml
    for htm in $(ls -1 *xhtml); do weasyprint --optimize-images --full-fonts --hinting $htm ${htm}.pdf; done
    rename 's/_(\d)\./_0\1./' *pdf
    The rename command was necessary to put the pages in the correct order to join them into one PDF. Otherwise, page 5 would have wound up between pages 49 and 50.
  6. Create a single PDF from the individual pages
    Code:
    pdfunite $(ls -1 *pdf | xargs) book.pdf
  7. Create a table of contents for the PDF. This was done using pdftk by dumping the PDF data, writing a list of bookmarks, and then merging it back in:
    Code:
    pdftk book.pdf dump_data > book.info
    Lines like the following were added to the book.info file
    Code:
    BookmarkBegin
    BookmarkTitle: Contents
    BookmarkLevel: 1
    BookmarkPageNumber: 6
    BookmarkBegin
    BookmarkTitle: Before You Begin
    BookmarkLevel: 2
    BookmarkPageNumber: 8
    BookmarkBegin
    BookmarkTitle: Be Prepared
    BookmarkLevel: 1
    BookmarkPageNumber: 11
    BookmarkBegin
    BookmarkTitle: Making Sense of the Screen
    BookmarkLevel: 2
    BookmarkPageNumber: 12
    This was slightly painful, as I couldn't find a good way to automate the generation of these lines. Still, there weren't that many that were needed. Once the bookmarks were written, it was time to merge them back into the PDF:
    Code:
    pdftk book.pdf update_info book.info output book2.pdf
  8. Finally, this PDF could be brought back into Calibre by "Add books > Add files to selected book records"
martinmcu is offline   Reply With Quote
Reply

Tags
failed convert, fixed layout epubs, pdf


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a Fixed Layout EPUB to Searchable PDF [Graphical Guide] Mercury's Priest PDF 4 05-18-2024 09:12 AM
Pdf to fixed layout epub scissors Workshop 18 02-16-2021 03:35 PM
From PDF to EPUB 3 Fixed Layout with selectable text Chang ePub 1 05-09-2017 03:37 AM
Fixed layout epub curiousgeorge ePub 3 01-18-2013 04:27 PM
Fixed-layout epub bhuvana786 ePub 2 04-07-2011 08:00 AM


All times are GMT -4. The time now is 08:09 AM.


MobileRead.com is a privately owned, operated and funded community.