I am currently working on a project using GroupDocs.Redaction and have encountered an issue regarding the functionality for redacting specific areas in a PDF document based on coordinates provided in points. My objective is to redact both text and images within these coordinates. The redaction needs to be applied across multiple pages of the PDF without converting the pdf into image.
Details:
- Library Version: GroupDocs.Redaction
- License: The license we are using is valid from December 23, 2023.
- Coordinates Format: The coordinates are provided in points.
- Document Structure: The document can contain multiple pages, and the coordinates can reference areas that have either text or images within them.
- Process: My current approach involves splitting the PDF into individual pages, redacting each page using the provided coordinates, and then merging the pages back into a single document. I also require the final output to be a proper text-based PDF.
Problem:
I have searched through the GroupDocs documentation and tried using methods like PageAreaRedaction
or RegionReplacementOptions
, but the function to redact based on coordinates for both text and images doesn’t seem to exist in my version of the library.
Aspose has this feature, i implemented it through trial version but i only have groupdocs license so i want to do it with that
@kashafvidizmo
To redact specific areas in a PDF document using GroupDocs.Redaction based on provided coordinates, you can utilize the PageAreaRedaction
feature. This allows you to specify rectangular areas for redaction that can contain both text and images, ensuring that the final output remains a text-based PDF rather than a collection of images.
Here’s a general approach to achieve this:
-
Initialize the Redactor: Create an instance of the Redactor
class with your PDF document.
-
Define the Redaction Area: Use the PageAreaRedaction
class to specify the coordinates and size of the area you want to redact. The coordinates should be provided in points.
-
Apply Redaction: Use the Apply
method of the Redactor
class to apply the redaction to the specified areas across multiple pages.
-
Save the Document: After applying the redactions, save the document to ensure the changes are written to the PDF.
Here is a sample code snippet demonstrating how to redact a specific area in a PDF:
using System;
using System.Drawing;
using GroupDocs.Redaction;
using GroupDocs.Redaction.Options;
using GroupDocs.Redaction.Redactions;
class Program
{
static void Main()
{
// Initialize the Redactor with the PDF file
using (Redactor redactor = new Redactor("path/to/your/document.pdf"))
{
// Define the area to redact (x, y, width, height)
Point startPoint = new Point(100, 100); // Starting coordinates
Size areaSize = new Size(200, 150); // Size of the area
// Create a PageAreaRedaction object
PageAreaRedaction redaction = new PageAreaRedaction(new PageAreaFilter(startPoint, areaSize));
// Apply the redaction
RedactorChangeLog result = redactor.Apply(redaction);
// Check if the redaction was successful
if (result.Status != RedactionStatus.Failed)
{
// Save the changes to the PDF
redactor.Save();
}
}
}
}
Important Notes:
- Ensure that the coordinates you provide are accurate and correspond to the areas you wish to redact.
- The
PageAreaRedaction
can be applied to multiple pages by adjusting the filters accordingly.
- The output will remain a text-based PDF, preserving the document’s structure.
If you encounter any issues or need further assistance, consider checking the latest updates or documentation for GroupDocs.Redaction, as there may be enhancements or additional features available.
For more detailed examples, you can refer to the official GroupDocs repository on GitHub, which includes various usage scenarios for redaction.
Sources:
[1]: Redact large area of PDF document based on selection
@Professionalize.Discourse PageAreaRedaction only takes in regex, replacementoptions with region replacement options. it is not working with the page area filter like you provided in the sample code.
can you please describe other ways or something i missed
@kashafvidizmo
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): REDACTIONNET-546
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.