how to use pisa.CreatePDF(dataString,file('filename.pdf','wb')) to change pdf page size?

1,232 views
Skip to first unread message

pyStone

unread,
Mar 29, 2012, 4:51:45 AM3/29/12
to xhtm...@googlegroups.com
dataString = '''
<html>
  <head>
    <title>tool by pyStone</title>
  </head>
  <body>
    <div id="big-container" style="width:2100px;background-color:#FFFFFF;">
      <div id="header" style="background-color:#FFFFFF;clear:both;text-align:center;">
        <h3>tool@pyStone</h3>
      </div>
      <div id="legend" style="background-color:#FFFFFF;clear:both;text-align:center;">
      ...
      <div>
      <div style="width:700px;background-color:#FFFFFF;float:left;"><div>
      <div style="width:700px;background-color:#FFFFFF;float:left;"><div>
      <div style="width:700px;background-color:#FFFFFF;float:left;"><div>
      <div id="footer" style="background-color:#FFFFF0;clear:both;text-align:center;"> Hach Company</div>
    </div>
  </body>
</html>
'''

pisa.CreatePDF(dataString,file('filename.pdf','wb'))

You can see is a real big pdf page 2100px width. How could i defined my pdf page size?

It seems the secret hidden in here:
pisa.CreatePDF(src, dest=None, path=None, link_callback=None, debug=0, default_css=None, xhtml=False, encoding=None, xml_output=None, raise_exception=True, capacity=100*1024)

but still no clue. I got page size of 8.27 * 11.69 in every time. And the div layout comes to no layout .

Thanks.

Jan Börner

unread,
Jul 22, 2013, 10:16:48 AM7/22/13
to xhtm...@googlegroups.com
Nop.... the secret is in the html file.

Add this to your css:
@page { 
            /*first value is width second value it height*/
            size: 400pt 300pt;
}

Reply all
Reply to author
Forward
0 new messages