C# iTextSharp-如何定位PDF页码
我知道如何使用代码针对任何PDF页面的任何文本:C# iTextSharp-如何定位PDF页码,c#,pdf,pdf-generation,itextsharp,C#,Pdf,Pdf Generation,Itextsharp,我知道如何使用代码针对任何PDF页面的任何文本: Anchor click = new Anchor("Click to go to Target"); click.Reference = "#target"; Paragraph p1 = new Paragraph(); p1.Add(click); doc.Add(p1); Anchor target = new Anchor("Target"); target.Name = "ta
Anchor click = new Anchor("Click to go to Target");
click.Reference = "#target";
Paragraph p1 = new Paragraph();
p1.Add(click);
doc.Add(p1);
Anchor target = new Anchor("Target");
target.Name = "target";
doc.Add(target);
我的问题是如何根据页面的编号确定页面的目标。例如,如果目标页码为6,单击锚文本应转到第6页。而不是
锚,您需要块
。对于该块
您需要添加一个pdp部分
。行动必须是行动
例如:
Chunk chunk = New Chunk("Go to page 5");
PdfAction action = PdfAction.GotoLocalPage(5, New PdfDestination(0), writer);
chunk.SetAction(action);
iTextSharp.text.Document doc = new iTextSharp.text.Document();
Chunk chunk = new Chunk("Go to page 5");
var writer = PdfWriter.GetInstance(doc, new FileStream(highLightFile, FileMode.Create));
var des = new PdfDestination(0,10f);
PdfAction action = PdfAction.GotoLocalPage(5, des, writer);
doc.Open();
chunk.SetAction(action);
Paragraph p1 = new Paragraph();
p1.Add(chunk);
doc.Add(p1);
doc.Close();