0
我试图将html转换为java的aspose单词中的pdf文档。 (版本是17.4.0)从HTML转换为PDF时定义PageSize
我的问题是: 如何在html中设置页面大小和页边距?
在documentation这听起来像我必须设置部分(div元素)的宽度,高度和边距。
我的HTML看起来像这样:
<!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>
我的Java代码:
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);
我的问题是,生成的PDF有215,9 X页面大小279.4毫米(而不是210×297毫米),顶部边距也不为0.
任何人都可以告诉我如何在我的html中定义这个值?
感谢您的回答。如果我使用你的代码,文件看起来是正确的。我的希望是,我可以在我的HTML中设置所有需要的布局功能。 –
是的,在HTML中设置页面布局属性不会影响HTML到PDF的转换结果。 –