-
how to use pymudpdf to convert html (with page break div and customized font ttf font fact) or epub to pdf? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
This depends on some details of your situation. You may want to have look at the features around the new
Because HTML / CSS are being used as specification language, you can do pretty much most of what is possible with HTML, e.g. also using your own fonts via |
Beta Was this translation helpful? Give feedback.
-
Thank you. Any direct method like calibre? Input an html/epub address, output an pdf. |
Beta Was this translation helpful? Give feedback.
-
Below code works. import pathlib htmlpath = pathlib.Path("myhtml.html") csspath = pathlib.Path("mycss.css")HTML = htmlpath.read_bytes().decode() CSS = csspath.read_bytes().decode()story = fitz.Story(html=HTML, user_css=CSS)story = fitz.Story(html=HTML) writer = fitz.DocumentWriter("output.pdf") # create the writer MEDIABOX = fitz.paper_rect("letter") # output page format: LetterMEDIABOX = fitz.paper_rect("A3") # output page format: Letter while more: # loop outputting the story writer.close() # close output file |
Beta Was this translation helpful? Give feedback.
-
base64 image in html code is missing in pdf. Local font did not effect.
|
Beta Was this translation helpful? Give feedback.
-
import io
import fitz
fileptr = io.BytesIO()
writer = fitz.DocumentWriter(fileptr)
# story processing here ...
...
writer.close()
doc = fitz.open("pdf", fileptr) # reopen memory PDF
doc.subset_fonts() # build subsets for eligible fonts
doc.ez_save("myfile.pdf") # save using compression and duplicate object elimination |
Beta Was this translation helpful? Give feedback.
-
It works to compress file size, now pdf size is 153kb. |
Beta Was this translation helpful? Give feedback.
-
Thank you. I tried chrome headless, it seems fine to work. |
Beta Was this translation helpful? Give feedback.
Archive
class - a generalized container concept: you can mix file folders and ZIP or TAR archives in onefitz.Archive
.fitz.DocumentWriter
you can use "compress" to reduce the resulting PDF file size. In addition, instead of a file, you can let DpcumentWriter write to a Python file pointer and reopen the resulting memory PDF for your own post processing. This is an example which builds font subsets and other methods for size reduction: