【发布时间】:2017-04-06 10:29:51
【问题描述】:
我正在尝试将 html 转换为 pdf 文档,用 java 的 aspose 单词。 (版本为 17.4.0)
我的问题是: 如何在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 x 297 毫米),并且顶部的边距也不为 0。
谁能告诉我如何在我的 html 中定义这些值?
【问题讨论】:
标签: java html pdf aspose aspose.words