|
|
Perfect. that worked a treat. thankyou.
|
|
|
Hi,
Try to save document with RemoveUnusedObjects flag
NoIncremenal | RemoveUnusedObjects
|
|
|
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);
|
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close