gpt4 book ai didi

html-parsing - iText xmlWorker 上边距

转载 作者:行者123 更新时间:2023-12-04 05:26:09 25 4
gpt4 key购买 nike

当我运行此代码时,文档顶部有一个边距。

image

我不知道如何摆脱它。我正在运行最新版本的 iText 和 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>,也许您会得到想要的结果。标签?

关于html-parsing - iText xmlWorker 上边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13187019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com