PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Important Notice: We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024. If you wish to migrate to our paid hosting service, please contact billing@hostonnet.com.
Reading existing Outlines

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
dsmeltz



Joined: 24 Jan 2008
Posts: 13

PostPosted: Thu Jan 31, 2008 2:57 pm    Post subject: Reading existing Outlines Reply with quote

Has anybody had any success trying to get PDFSharp to read Outlines from an existing PDF document?

I have no problem creating new outlines and saving them to a new document, but reading existing outlines seems to be a missing feature.
Back to top
View user's profile Send private message
cvanling



Joined: 11 Jan 2008
Posts: 5

PostPosted: Tue Aug 12, 2008 2:04 pm    Post subject: Reading outlines from existing document Reply with quote

Yes, I have written some code to do this. It is posted on sourceforge, look for PdfMerge.

This required using some of the lower level features of PdfMerge, but it is certainly possible.

https://sourceforge.net/projects/pdfmerge/
Back to top
View user's profile Send private message
BillE



Joined: 02 Mar 2008
Posts: 4

PostPosted: Tue Aug 12, 2008 8:07 pm    Post subject: Reply with quote

Here is a quicky snippet from some code that walks the outline collection and renders it into a Windows Tree Control.

Oh, and PS did you ever work for GHR?

void DoWork(object obj)
{
PdfDocument doc = PdfReader.Open(Path);
using (doc)
{
ParseOutline(doc);
}
}

void ParseOutline(PdfDocument doc)
{
Trace.WriteLine(doc.FullPath + " is open.");
PdfOutline rootOutline = doc.Outlines.Parent;

//PdfItem keysValue = rootOutline.Elements["/First"];
//PdfDictionary titleDictionary = doc.Internals.AllObjects.OfType<PdfDictionary>().Where
// ((PdfDictionary d) => d.Elements["/Title"] != null).First<PdfDictionary>();

//PdfObjectID objID = PdfInternals.GetObjectID(titleDictionary);
//Trace.WriteLine(objID.ToString() + " " + titleDictionary);

//PdfOutline outline = new PdfOutline(titleDictionary);

Form.Invoke(Form.addNode, new object[] { ProcessNode(doc, null, rootOutline) });
}

TreeNode AddOutlineTreeNode(TreeNode parent, PdfOutline outline)
{
TreeNode tn = new TreeNode(outline.Title);
tn.Tag = outline;

if (parent != null )
parent.Nodes.Add(tn);

return tn;
}

TreeNode ProcessNode(PdfDocument doc, TreeNode parent, PdfOutline outline )
{
TreeNode returnNode = null;

PdfReference first = outline.Elements.GetReference("/First");
PdfReference last = outline.Elements.GetReference("/Last");

if (first == null || last == null)
return returnNode;

PdfOutline firstOutline = new PdfOutline(first.Value as PdfDictionary);
PdfOutline lastOutline = new PdfOutline(last.Value as PdfDictionary);
PdfOutline iterator = firstOutline;

do
{
PdfReference next = iterator.Elements.GetReference("/Next");
if (next != null)
{
PdfOutline nextOutline = new PdfOutline(next.Value as PdfDictionary);
returnNode = AddOutlineTreeNode(parent, nextOutline);
ProcessNode(doc, returnNode, nextOutline);
iterator = nextOutline;
}
else
{
// special case only called from the root outline.
returnNode = AddOutlineTreeNode(parent, iterator);
ProcessNode(doc, returnNode, iterator);
}
}
while (PdfInternals.GetObjectID(iterator) != PdfInternals.GetObjectID(lastOutline));
return returnNode;
}

}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com