本文介绍了如何使用iTextSharp将缩放级别设置为pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用iTextSharp将缩放级别设置为75%到pdf文件。我正在使用以下代码来设置缩放级别。
I need to set the zoom level 75% to pdf file using iTextSharp. I am using following code to set the zoom level.
PdfReader reader = new PdfReader("input.pdf".ToString());
iTextSharp.text.Document doc = new iTextSharp.text.Document(reader.GetPageSize(1));
doc.OpenDocument();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("Zoom.pdf", FileMode.Create));
PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 0.75f);
doc.Open();
PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);
writer.SetOpenAction(action);
doc.Close();
但是我收到错误第1页是请求但文档只有0页 doc.Close();
But I am getting the error "the page 1 was request but the document has only 0 pages" in the doc.Close();
推荐答案
你需要使用 PdfStamper
(由mkl表示)而不是 PdfWriter
(由Chris Haas明确表示)。请查看示例:
You need to use PdfStamper
(as indicated by mkl) instead of PdfWriter
(as made clear by Chris Haas). Please take a look at the AddOpenAction
example:
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, reader.getPageSize(1).getHeight(), 0.75f);
PdfAction action = PdfAction.gotoLocalPage(1, pdfDest, stamper.getWriter());
stamper.getWriter().setOpenAction(action);
stamper.close();
reader.close();
}
结果是。
这篇关于如何使用iTextSharp将缩放级别设置为pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!