Crop PDF without keeping invisible content (.NET or ObjC)

江枫思渺然 提交于 2020-01-24 20:27:06

问题


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:


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



来源:https://stackoverflow.com/questions/7890101/crop-pdf-without-keeping-invisible-content-net-or-objc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!