ITextSharp 在页面索引处使用缩放打开 pdf
ITextSharp open pdf at page index with zoom
我有一些包含很多表格的 pdf。
我在这些文件中进行了搜索,并且有一个列表,其中包含找到该字符串的页码。
现在我必须将这些文件打开到确切的页面,可能带有缩放和显示结果的矩形。
有什么想法吗?
P.S。我用于阅读和打开 pdf 文件的代码是:
Dim reader As New PdfReader(FileToOpen)
Dim stamper As New PdfStamper(reader, New System.IO.FileStream("j:\Zoom.pdf", FileMode.Open, FileAccess.ReadWrite))
Dim pdfDest As New PdfDestination(PdfDestination.FITH)
Dim OA As PdfAction = PdfAction.GotoLocalPage(2, pdfDest, stamper.Writer)
stamper.Writer.SetOpenAction(OA)
stamper.Close()
reader.Close()
我差点把这个问题当作 How to set initial view properties? because I found the question in the official iText documentation with a link to Stack Overflow: How to set initial view properties?
的副本来解决
作为 How to set zoom level to pdf using iTextSharp? (see How to set the zoom level of a PDF using iTextSharp?)
的副本
不过,我发现官方 iText 网站上的答案比 Stack Overflow 上的答案要好,因为它结合了您需要知道的一切。
简而言之:你需要一个开放的行动:
//Create a destination that fit's width (fit horizontal)
var D = new PdfDestination(PdfDestination.FITH);
//Create an open action that points to a specific page using this destination
var OA = PdfAction.GotoLocalPage(1, D, stamper.Writer);
//Set the open action on the writer
stamper.Writer.SetOpenAction(OA);
显然,您可以在定义 D
时选择创建另一个目的地。
如果您有机会使用 iText 7,那么您应该阅读 chapter 7 of the iText 7: Building Blocks tutorial to learn about the open action, and chapter 6,其中解释了所有可能的目的地(XYZ、FitH、FitB 等)。
请在发布问题前阅读文档。
我有一些包含很多表格的 pdf。 我在这些文件中进行了搜索,并且有一个列表,其中包含找到该字符串的页码。 现在我必须将这些文件打开到确切的页面,可能带有缩放和显示结果的矩形。
有什么想法吗?
P.S。我用于阅读和打开 pdf 文件的代码是:
Dim reader As New PdfReader(FileToOpen)
Dim stamper As New PdfStamper(reader, New System.IO.FileStream("j:\Zoom.pdf", FileMode.Open, FileAccess.ReadWrite))
Dim pdfDest As New PdfDestination(PdfDestination.FITH)
Dim OA As PdfAction = PdfAction.GotoLocalPage(2, pdfDest, stamper.Writer)
stamper.Writer.SetOpenAction(OA)
stamper.Close()
reader.Close()
我差点把这个问题当作 How to set initial view properties? because I found the question in the official iText documentation with a link to Stack Overflow: How to set initial view properties?
的副本来解决作为 How to set zoom level to pdf using iTextSharp? (see How to set the zoom level of a PDF using iTextSharp?)
的副本不过,我发现官方 iText 网站上的答案比 Stack Overflow 上的答案要好,因为它结合了您需要知道的一切。
简而言之:你需要一个开放的行动:
//Create a destination that fit's width (fit horizontal)
var D = new PdfDestination(PdfDestination.FITH);
//Create an open action that points to a specific page using this destination
var OA = PdfAction.GotoLocalPage(1, D, stamper.Writer);
//Set the open action on the writer
stamper.Writer.SetOpenAction(OA);
显然,您可以在定义 D
时选择创建另一个目的地。
如果您有机会使用 iText 7,那么您应该阅读 chapter 7 of the iText 7: Building Blocks tutorial to learn about the open action, and chapter 6,其中解释了所有可能的目的地(XYZ、FitH、FitB 等)。
请在发布问题前阅读文档。