我有一个带有文本,图像的html页面,我正在将HTML内容解析为iText以生成PDF.在生成的PDF中,未显示包含的图像,仅显示文本.
如果我传递绝对路径,如D:/Deiva/CRs/HTMLPage/article-101-horz.jpg那么图像将被打印.但是如果我尝试从服务器上打印图像就像
http://localhost:8085/content/dam/article-101-h1.jpg or http://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif
那么它不会在PDF中打印出来.
注意:我使用itextpdf-5.2.1.jar生成PDF.
我的HTML代码(Article.html):
<html>
<head>
</head>
<body>
<p>Generate PDF with image using iText.</p>
<img src="http://localhost:8085/content/dam/article-10-h1.jpg"></img>
<img src="http://www.google.co.in/intl/en_ALL/images/logos/imgs_logo_lg.gif"></img>
<img class="right horz" src="D:/Deiva/CRs/HTMLPage/article-101-horz.jpg"></img>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我使用以下java代码生成PDF:
private void createPDF (){
String path = "D:/Deiva/Test.pdf";
PdfWriter pdfWriter = null;
//create a new document
Document document = new Document();
try {
//get Instance of the PDFWriter
pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(path));
//document header attributes
document.addAuthor("betterThanZero");
document.addCreationDate();
document.addProducer();
document.addCreator("MySampleCode.com");
document.addTitle("Demo for iText XMLWorker");
document.setPageSize(PageSize.LETTER);
//open …Run Code Online (Sandbox Code Playgroud)