[英]How to edit named destination in PDF file using iTextSharp with C#?
Here I want to edit the already exist named destination in PDF file using C# with iTextSharp.dll. 在这里,我想使用带有iTextSharp.dll的C#编辑PDF文件中已经存在的命名目标。
Here I am showing sample PS script. 在这里,我展示了示例PS脚本。
OLD: 旧:
[/Dest /bmkaff1 /View [/FitR 59 516 435 504] /DEST pdfmark
Updated: 更新:
[/Dest /bmkaff1 /View [/XYZ 59 516 0] /DEST pdfmark
PDF Dictionary Screen shot: PDF词典屏幕截图:
Original PDF File 原始PDF文件
Updated PDF file 更新的PDF文件
Note: 注意:
Updated PDF file is generated by updating the PS file 通过更新PS文件生成更新的PDF文件
I got solution for my question. 我为我的问题找到了解决方案。
First I am using GetNamedDestination()
method to read the namded destionation and then checking with condition and then editing the named destination values. 首先,我使用
GetNamedDestination()
方法读取命名的目标,然后检查条件,然后编辑命名的目标值。
Here my C# code: 这是我的C#代码:
string pdfFilePath = @"D:\Raja\Testing\AuthorQuery\xxx.pdf";
string dPDFFile = @"D:\Raja\Testing\AuthorQuery\YYY.pdf";
PdfReader pdfR = new PdfReader(pdfFilePath);
Dictionary<object, PdfObject> nDest = new Dictionary<object, PdfObject>();
nDest = pdfR.GetNamedDestination();
List<object> nDesColl = new List<object>();
nDesColl.Clear();
foreach (KeyValuePair<object, PdfObject> sEntry in nDest)
{
PdfArray pArr = (PdfArray)sEntry.Value;
if(pArr.ArrayList.Count== 6)
{
if (pArr[1].ToString() == "/FitR")
{
nDesColl.Add(sEntry.Key);
}
}
}
if (nDesColl.Count > 0)
{
foreach (object keyVal in nDesColl)
{
PdfNumber pNo = new PdfNumber(0);
PdfArray pArr = (PdfArray)nDest[keyVal];
pArr[1] = PdfName.XYZ;
pArr[4] = (PdfObject)pNo;
pArr.ArrayList.RemoveAt(5);
PdfObject fVal = (PdfObject)pArr;
nDest[keyVal] = fVal;
}
}
using (PdfStamper stamper = new PdfStamper(pdfR, new FileStream(dPDFFile, FileMode.Create)))
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.