logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
simon.molino@smokeball.com Posted: Tuesday, August 13, 2019 10:04:02 PM(UTC)
 
Perfect. that worked a treat. thankyou.
Paul Rayman Posted: Tuesday, August 13, 2019 9:27:15 PM(UTC)
 
Hi,

Try to save document with RemoveUnusedObjects flag

NoIncremenal | RemoveUnusedObjects
simon.molino@smokeball.com Posted: Tuesday, August 6, 2019 6:35:27 PM(UTC)
 
Hi Support,

Can you confirm the recommended approach to cleaning up annotation object resources when an annotation is removed from a pages Annots collection.

For example:
We create a PdfFreeTextAnnotation, setting various objects to it's normal appearance.

Code:
myAnnot.CreateEmptyAppearance(AppearanceStreamModes.Normal);
...
myAnnot.NormalAppearance.Add(...);
...
myAnnot.GenerateAppearance(AppearanceStreamModes.Normal); // This creates several object resources in the PdfIndirectList and PdfCrossReferenceTable.

page.Annots.Add(myAnnot);


Then when we want to delete the annotation, we call:

Code:
page.Annots.remove(myAnnot);


????? However at this point, objects that were created in the PdfIndirectList and PdfCrossReferenceTable collections are NOT removed.

What is the recommended approach to remove these unused object references?

We currently remove objects from the PdfIndirectList and PdfCrossReferenceTable collections whose ObjectNumber does NOT exist in the PdfRefObjectsCollection.


Code:

            //Get a cross-reference table and a list of indirect objects in the document 
            var list = PdfIndirectList.FromPdfDocument(document);
            var cross = PdfCrossReferenceTable.FromPdfDocument(document);

            //Receive a list of objects that have at least one reference in the document
            var refObjects = PdfRefObjectsCollection.FromPdfDocument(document);

            var objectsToRemove = new List<int>();
            foreach( var item in list)
            {
                if ( refObjects.FirstOrDefault(a=>a.ObjectNumber == item.ObjectNumber) == null )
                    objectsToRemove.Add(item.ObjectNumber);
            }

            foreach (var objectNumber in objectsToRemove)
                list.Remove(objectNumber);

            objectsToRemove = new List<int>();
            foreach (var item in cross)
            {
                if (refObjects.FirstOrDefault(a => a.ObjectNumber == item.ObjectNumber) == null)
                    objectsToRemove.Add(item.ObjectNumber);
            }

            foreach (var objectNumber in objectsToRemove)
                cross.Remove(objectNumber);