html缩放比例转为pdf,缩小HTML页面并转换为A4尺寸pdf

将html页面转换为pdf。当我将页面转换为pdf时,html页面内容不适合A4页面。我希望将整个html页面转换为pdf,而不会丢失任何内容。缩小HTML页面并转换为A4尺寸pdf

我已经具有转换HTML到PDF

String tempOutFileNameXHTML = "/Users/Common/index" + i + DOT + "xhtml";

String tempOutFileNamePDF = "/Users/Common/index" + i + DOT + PDF;

File targetFile = targetFiles.get(i); // gets all the specified html files

CleanerProperties props = new CleanerProperties();

props.setTranslateSpecialEntities(true);

props.setTransResCharsToNCR(true);

props.setOmitComments(true);

//checking of starting and ending tags are in proper

HtmlCleaner htmlCleaner = new HtmlCleaner(props);

TagNode tagNode = htmlCleaner.clean(targetFile);

PrettyXmlSerializer prettyXmlSerializer = new PrettyXmlSerializer(props);

prettyXmlSerializer.writeToFile(tagNode, tempOutFileNameXHTML, "utf-8");

File xhtmlpath = new File(tempOutFileNameXHTML);

File pdfPath = new File(tempOutFileNamePDF);

com.itextpdf.text.Document pdfDocument = null;

PdfWriter pdfWriter = null;

pdfDocument = new com.itextpdf.text.Document(com.itextpdf.text.PageSize.A4); // TODO handle this

pdfWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(pdfPath));

pdfDocument.open();

Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 25, Font.BOLD);

pdfDocument.add(new Paragraph("Target : " + targetFile.getParentFile().getName(), catFont));

XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, (com.itextpdf.text.Document) pdfDocument,

new FileInputStream(xhtmlpath), null);

pdfDocument.close();

这里的问题是,当html页面宽度过长,不适合在A4大小的PDF格式的代码。无论如何收缩或使其成为没有任何内容丢失的pdf。 ? 我该怎么做? HTML页面可以缩小并转换为PDF?任何想法如何做到这一点?

2013-01-11

Muthu

+0

看看这篇文章。可能帮助http://stackoverflow.com/questions/14089883/how-to-create-several-pages-with-dompdf/14089936#14089936 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值