我正在尝试使用iTextSharp为现有PDF添加命名目标,但example code I've found online无效(原始示例在javascript中)。难道我做错了什么?以下是我正在使用的代码,New Text Document.pdf
是从txt
文件创建的单页PDF。
var sourcePdfPath = @"C:\Temp\New Text Document.pdf";
var destPdfPath = @"C:\Temp\New Text Document_bettered.pdf";
using (var reader = new PdfReader(sourcePdfPath))
{
using (var stamper = new PdfStamper(reader, new FileStream(destPdfPath, FileMode.Create)))
{
var destination = new PdfDestination(PdfDestination.FIT);
var writer = stamper.Writer;
writer.AddNamedDestination("Destination.Name", 1, destination);
stamper.Close();
}
reader.Close();
}