1

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...)

ingham
  • 1,636
  • 15
  • 30

1 Answers1

0

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

Community
  • 1
  • 1
yms
  • 10,361
  • 3
  • 38
  • 68
  • Thanks. One (more) problem: If there is a "big" object (a Line for example) that starts inside of the rectangle, but ends really far out... It will be included too, isn't it ? Is it possible to "reduce" this object so it fits perfectly with the rectangle ? – ingham Oct 26 '11 at 07:15
  • ingham GetObjectsInRectangle allows you to choose if you want to keep the intersected items or not, but if you want to keep only a portion of each of them, then you will need to use clipping, sorry. – yms Oct 26 '11 at 15:47
  • I'm trying your solution, I'm able to get an Array with desired IacObject, but I don't find how to copy these items in a new page (nor how to delete all other objects)... – ingham Nov 23 '11 at 13:21