1
votes

I'm trying to crop a PDF using .NET (using PDF4NET or iTextSharp, but not closed to these ones) or Objective-C (CGContextXXX, CGPDFXXX, etc.)... But without keeping the invisible content !

Currently, I'm able to do the crop operation using the Crop Box or a Clip Region, but all content invisible is still present in the PDF...

Is it possible ?

Thanks (and sorry, I'm french...)

1

1 Answers

0
votes

You could try Amyuni PDF Creator .Net for this task. You could use the method IacDocument.GetObjectsInRectangle to retrieve all the "graphic objects" of your interest:

IacDocument.GetObjectsInRectangle Method

The GetObjectsInRectangle method gets all the objects that are in the specified rectangle.

Then you can iterate all the objects in the page and delete those that you are not interested in:

//open a pdf document
document.Open (testfile,"");
IacPage page1 = document.GetPage (1);
Amyuni.PDFCreator.IacAttribute attribute = page1.AttributeByName ("Objects");
// listobj is an array list of graphic objects
System.Collections.ArrayList listobj = (System.Collections.ArrayList) attribute.Value;
foreach ( object pdfObj in listobj )
{
   // if pdfObj is not in the collection of interest
   // then call pdfObj.Delete();
}

Update:
Amyuni PDF Creator .Net version 5.0 adds a new method IacDocument.Redact which might also be helpful in this kind of scenario:

The Redact method retrieves all the objects of the specified type in the specified rectangle, deletes them, and draws a solid color rectangle at their place.

Disclaimer: I work for Amyuni Technologies