java - Define PageSize when converting from HTML to PDF -


i'm trying convert html pdf-document in aspose words java. (version 17.4.0)

my question is: how can set page size , page margins in html?

in documentation sounds have set width, height , margin section (div-element).

my html looks this:

<!doctype html>  <html>    <head>      <title>hello pdf</title>  </head>    <body>      <div class="page" style="width:210mm; height:297mm; margin-top:0cm; margin-bottom:1cm; margin-left:1cm; margin-right:1cm;">          <p>hello world</p>      </div>  </body>    </html>

my java code:

string baseuri = "path/to/doc/";  loadoptions loadoptions = new loadoptions(); loadoptions.setencoding(charset.forname("utf-8")); document doc = new document(baseuri + "test.html", loadoptions);  outputstream outputstream = new fileoutputstream(baseuri + "test.pdf"); doc.save(outputstream, saveformat.pdf); 

my problem resulting pdf has page size of 215,9 x 279,4mm (instead of 210 x 297mm) , margin top not 0.

can tell me how define values in html?

please note aspose.words mimics same behavior ms word does. page settings fine in html. if load input html in ms word , convert pdf, generate document 215,9 x 279,4mm pagesize well.

however, may change page setting of section per requirement using aspose.words api following.

i'm tilal, developer evangelist @ aspose.

string baseuri = "path/to/doc/";  loadoptions loadoptions = new loadoptions(); loadoptions.setencoding(charset.forname("utf-8")); com.aspose.words.document doc = new com.aspose.words.document(baseuri +"test.html", loadoptions);  (section sectoin : doc.getsections()) {        pagesetup ps = sectoin.getpagesetup();        ps.setpapersize(papersize.a4);        ps.settopmargin(0.0);        ps.setbottommargin(1.0);        ps.setleftmargin(1.0);        ps.setrightmargin(1.0);  }  outputstream outputstream = new fileoutputstream(baseuri +"test.pdf"); doc.save(outputstream, com.aspose.words.saveformat.pdf); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -