cloudify / sPDF

Create PDFs from Scala using plain old HTML and CSS. Uses wkhtmltopdf on the back-end which renders HTML using Webkit.
Other
199 stars 53 forks source link

Any experience with css metrics? #2

Closed pixelogik closed 10 years ago

pixelogik commented 10 years ago

Hi again,

does anybody have experience when it comes to css metrics in the html?

I just try to center a div using cm as metric, but is wont work. I have a page size of 20x20cm as set by

    pageWidth := "200"
    pageHeight := "200"

and position the div with

but it is not in the middle. I tried already setting the page size for print media with

but it did not help.

After searching a lot it seems that this is a general problem of wkhtmltopdf. I am just wondering if anybody here knows a solution to this?

Thanks Ole

pixelogik commented 10 years ago

I solved the problem by using divs as pages, setting their sizes accordingly

<html>
    <head>
        <style type='text/css'>
            .myPage{width:20cm; height:20cm;margin:0cm;padding:0cm;}
        </style>
    <head>
    <body style='margin:0cm; padding:0cm;'>
        <div class='myPage' style='background-color:#0000ff;'>
            <div style='position:absolute; left:10cm;top:0cm;width:1cm;height:10cm;background-color:black;'>
            </div>
        </div>
    <body>
</html>
cloudify commented 10 years ago

Hi @pixelogik, I had the same need a while ago and I solved it in exactly the same way, I use DIVs that have the width and height equal to the page and then I relative positioning inside. I recall it was a bit tricky to find the right numbers for the body of the page and the borders...

pixelogik commented 10 years ago

Hi @cloudify ,

alright. Thanks for letting me know!