Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can WeasyPrint fit to Paper Size Automatically

I used to work for an organization that used Prince XML to generate PDF's of HTML documents. That organization has since folded, and I no longer have access to that Prince license. Since I don't have four grand between the couch cushions, I've been attempting to use WeasyPrint to render HTML invoices to PDF. My HTML & CSS are both quite simple, so Weasy has no problem rendering them accurately, with on caveat. I cannot get the page to scale down automatically to the paper size like I could in prince using:

@page {
prince-shrink-to-fit:auto;
}

Does anyone know if Weasy supports any similar command before I rework the CSS of the entire site to generate smaller documents?

like image 703
user1119648 Avatar asked Aug 06 '13 20:08

user1119648


Video Answer


2 Answers

By looking around for some ideas to format the pdf rendered by weasyprint, I found this question which might answer your question.

@page {
            size: Letter;
            margin: 0in 0.44in 0.2in 0.44in;
    }

WeasyPrint page size wrong. (8.27in x 11.69 in)

like image 168
Joey Jiao Avatar answered Sep 30 '22 03:09

Joey Jiao


WeasyPrint does not support anything like this at the moment. Prince’s documentation is pretty sparse on what it does exactly. How is "the width of the content" determined? Given a proper specification of the feature, I could tell how hard it would be to add to WeasyPrint.

By the way, I do not usually watch StackOverflow for WeasyPrint question. Writing to WeasyPrint’s mailing list or issue tracker will get more response.

like image 44
Simon Sapin Avatar answered Sep 30 '22 03:09

Simon Sapin