私はitext7ライブラリを使用していくつかの既存のPDFを操作しています。何らかの理由で、アウトラインからページ番号を取得できません。私はどうにかしてPdfDestinationから取得するべきだと思うが、そのサブクラスのどのマッチングメソッドも見つけることができない。 iText5で文書の概要(ブックマーク)からページ番号を取得
PdfDocument pdfDoc = new PdfDocument(new PdfReader("example.pdf"));
var root = pdfDoc.GetOutlines(false);
foreach (PdfOutline ol in root.GetAllChildren()) {
Console.WriteLine(ol.GetTitle());
PdfDestination d = ol.GetDestination();
// how to get the page number from the destination object
}
私は、「ページ」のエントリを含む辞書のリストを返しSimpleBookmark.GetBookmark(reader)
を使用 - しかし、この機能はiText7で削除されているようです。
編集: 私はjavaのために同じ(Github上PdfExplicitDestination.getDestinationPage()の純実装を見ていた私は、このメソッドのパラメータの目的を理解していない私はnullを渡すと、上で動作するようです。 pdfsは、ToString()を使用してアウトライン階層内の1つのレベルのみを使用します。つまり、ゼロインデックス付きのページ番号を文字列として返すことを意味します(PDFの場合はページ番号が見つかりません) 。
PdfDocument pdfDoc = new PdfDocument(new PdfReader("example.pdf"));
var root = pdfDoc.GetOutlines();
foreach (PdfOutline ol in root.GetAllChildren()) {
Console.WriteLine(ol.GetTitle());
var d = ol.GetDestination();
if (d is PdfExplicitDestination) {
string PageNoStr = d.GetDestinationPage(null).ToString();
// this is the content of the method (less the ToString()
//string PageNoStr = ((PdfArray)d.GetPdfObject()).Get(0).ToString();
int pageNo;
if (Int32.TryParse(PageNoStr, out pageNo)) {
Console.WriteLine("Page is " + pageNo);
} else {
Console.WriteLine("Error page");
}
}
}
だから私はまだこれを理解しようとしています。
ありがとうございます。それは私が予想していた以上に複雑でした! –