|
PDFsharp - moved to http://forum.pdfsharp.net/ Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
|
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.
View previous topic :: View next topic |
Author |
Message |
dsmeltz
Joined: 24 Jan 2008 Posts: 13
|
Posted: Thu Jan 31, 2008 2:57 pm Post subject: Reading existing Outlines |
|
|
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 |
|
|
cvanling
Joined: 11 Jan 2008 Posts: 5
|
Posted: Tue Aug 12, 2008 2:04 pm Post subject: Reading outlines from existing document |
|
|
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 |
|
|
BillE
Joined: 02 Mar 2008 Posts: 4
|
Posted: Tue Aug 12, 2008 8:07 pm Post subject: |
|
|
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 |
|
|
|
|
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
|
|