我有一个 PDF 文件,其中包含一个索引页面,其中包含带有目标页面的部分。
“book15.pdf”默认缩放百分比将为 68%,当我以编程方式将缩放百分比更改为 100% 时,原来的超链接丢失了?为什么?
这是我的示例代码。参考网址:http ://wskidmore.com/2011/03/pdf-initial-view-settings-itextsharp/
string FileName = AppDomain.CurrentDomain.BaseDirectory + "BooK15.pdf";
Document doc = new Document();
PdfReader reader = new PdfReader(FileName);
using (MemoryStream memoryStream = new MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
doc.Open();
PdfAction zoom = PdfAction.GotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, -1, -1, (float)Int32.Parse("100") / 100), writer);
writer.SetOpenAction(zoom);
doc.AddDocListener(writer);
PdfContentByte cb = writer.DirectContent;
for (int p = 1; p <= reader.NumberOfPages; p++)
{
doc.SetPageSize(reader.GetPageSize(p));
doc.NewPage();
PdfImportedPage page = writer.GetImportedPage(reader, p);
int rot = reader.GetPageRotation(p);
if (rot == 90 || rot == 270)
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(p).Height);
else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0);
}
reader.Close();
doc.Close();
File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + "BooK151.pdf", memoryStream.ToArray());
}
当我使用以下代码阅读索引页页码链接时:
int _count= pdfReader.GetLinks(PageNo).Count;
PdfDictionary PageDictionary = pdfReader.GetPageN(PageNo);
PdfArray Annots = PageDictionary.GetAsArray(PdfName.ANNOTS);
但这仅返回 0。有任何想法吗?这是我的屏幕截图...
带有可点击链接的原始 PDF
转换后链接丢失