本文介绍了iText xmlWorker上边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行此代码时,我在文档的顶部获得了一个边距。
When i run this code, I get a margin at the top of the document.
我不知道如何摆脱它。我正在运行最新版本的iText和XMLWorker。
And I have no idea on how to get rid of it. I'm running the latest versions of iText and XMLWorker.
Document document = new Document(PageSize.A5.rotate(), 0f, 0f, 0f, 0f);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:/itext/test.pdf"));
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(false);
cssResolver.addCss("p{color: #a00; font-size: 20pt; margin: 0; padding: 0;}", true);
Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser xmlParser = new XMLParser(worker);
document.open();
String htmlData = "<html> <p>Lorem ipsum</p> </html>";
xmlParser.parse(new StringReader(htmlData));
document.close();
推荐答案
HTML < p> ;
标签通常在上方和下方有填充。如果您使用< div>
标签,也许您会得到您想要的结果?
The HTML <p>
tag normally has padding above and below. Perhaps you'll get the result you're looking for if you use a <div>
tag instead?
这篇关于iText xmlWorker上边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!