gpt4 book ai didi

java - iText - PDF 不好

转载 作者:行者123 更新时间:2023-11-30 04:57:29 25 4
gpt4 key购买 nike

我有以下 HTML:

<div align='center' style='height:50px'>
<H1>A Simple Sample Web Page</H1>
<IMG SRC='http://sheldonbrown.com/images/scb_eagle_contact.jpeg'>
<H4>By Sheldon Brown</H4>
<H2>Demonstrating a few HTML features</H2>
</div>
HTML is really a very simple language. '
<P>
'command, which will insert a blank line.If you would like to make a link or
bookmark to this page, the URL is:
<BR>
http://sheldonbrown.com/web_sample1.html
</center>

但是图像出现在文本后面而不是下面!

出了什么问题?

如果 iText 无法处理它 - 哪个库更好?

这是我的代码:

// step 1
Document document = new Document();

// step 2
PdfWriter.getInstance(document, new FileOutputStream("C:\\hello-world.pdf"));

document.open();
String content = "<div align='center' style='height:50px'><H1>A Simple Sample Web Page</H1><IMG SRC='http://sheldonbrown.com/images/scb_eagle_contact.jpeg'><H4>By Sheldon Brown</H4><H2>Demonstrating a few HTML features</H2></div>HTML is really a very simple language. '<P>' command, which will insert a blank line.If you would like to make a link or bookmark to this page, the URL is:<BR> http://sheldonbrown.com/web_sample1.html</center>";

// use the snippet for the PDF document
List<Element> objects = HTMLWorker.parseToList(new StringReader(content), null);
for (Element element : objects)
document.add(element);
document.close();

最佳答案

你有任何CSS应用到这个HTML吗?您是否能够使用浏览器(哪个)以任何其他方式查看此 HTML?它的呈现方式就像您在此处描述的那样:http://jsfiddle.net/TjUSJ/

也许您想删除 <div> 上的高度样式属性?看起来好像是在中间渲染,但实际上是在距顶部 50px 处渲染。请参阅另一个 fiddle ,没​​有 height造型:http://jsfiddle.net/TjUSJ/1/

另外,请记住 <center> tag is deprecated

关于java - iText - PDF 不好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8078853/

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