PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

how to get a pdf document outlines
https://forum.pdfsharp.net/viewtopic.php?f=2&t=109
Page 1 of 1

Author:  jiuqiangjiang [ Sat Mar 31, 2007 3:02 am ]
Post subject:  how to get a pdf document outlines

I want to get outlines from a exist document and I write code like
this:
PdfDocument pdfFile = PdfReader.Open(@"C:\Downloads\pdf_reference.pdf", PdfDocumentOpenMode.Import);
PdfOutline.PdfOutlineCollection outlineCollection = pdfFile.Outlines;
foreach (PdfOutline outline in outlineCollection)
{
System.Console.WriteLine(outline.Title);
}

and then raise a error :
no appropriate constructor fond for type:PdfOutline

now,how can I solve my problem?
thanks!

Author:  IQDragon [ Wed Jul 11, 2007 1:06 pm ]
Post subject:  Outlines

This is correct, to my knowledge a lot of stuff won't work with existing PDF documents.

I downloaded the 0.9.653 code myself (only can use .NET 1.1 for this project) and found that error to.

The trick is to have the following constructor:

public PdfOutline(PdfDictionary dictionary) : base(dictionary)
{
}

This does not fix the issue with existing outlines, you'll soon notice it retuning an empty collection.

If you need a fix for this let me know I'll be happy to share it.
It did take considerable time to find a workaround though lol.

Author:  ACS [ Tue Dec 04, 2007 5:41 am ]
Post subject: 

I'm actually looking for a fix for this as well. I need to access the outline structure of an existing PDF and it's very frustrating that I can't do it! :(

IQDragon, if you have a fix, please share!

Author:  cvanling [ Sun Feb 17, 2008 7:23 pm ]
Post subject:  Outlines

It can be done using PdfSharp, but a little coding is required.

First you need to access the document outline:

// get the outline object
PdfDictionary outline = (PdfDictionary)inputDocument.Internals.Catalog.Elements.GetObject("/Outlines");

// you can then access the first outline using:
PdfDictionary first = (PdfDictionary)outline.Elements.GetObject("/First");

// you can then access the title of the first outline using:
string title = first.Elements.GetString("/Title");

There is a fully worked out demo for this on sourceforge (see the pdfmerge project). It gets a little complicated because there are lot of variations in outline formats, especially for new acrobat documents which support outlining to various points on a single page.

Author:  Blocked [ Fri Apr 12, 2013 2:02 pm ]
Post subject:  Re: how to get a pdf document outlines

Ok.But how to show all bookmarks?With help of your code i wirte this
Code:
ICollection<String> s =outline.Elements.Keys;

In this Keys is only the name of the first outline (plus "/Count","First","Last").

Author:  MonkFox [ Fri Apr 19, 2013 12:45 pm ]
Post subject:  Re: how to get a pdf document outlines

There is a PDFMerge project that has an AddBookmarksFromFile function that gets a file's outline items. Look at that.

download the source here.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/