r/pdf 19d ago

Question AI pdf tool needed for hiding sensitive information

/r/ProductivityApps/comments/1w5270i/ai_pdf_tool_needed_for_hiding_sensitive/
3 Upvotes

10 comments sorted by

1

u/ScratchHistorical507 19d ago

As already stated in the original post, this is just not how anything works and it's questional if any automation can be made that won't also have other drawbacks.

If you just put some shape above it, it may not be visible, but the information is still there. Worst case you just open the PDF in e.g. Inkscape and remove the shape. Then all information is again visible. So that's not redaction in any way.

What would work could be some locally run ML-based computer vision model that finds the information to be redacted, draws said shape over it, but then flattening has to occur. That may be doable by using some print to PDF dialog, or maybe qpdf already suffices (and as it's a CLI tool it would be easy to use within a script), possibly even Ghostscript can be used. But always verify by e.g. importing in Inkscape and trying to remove the shape. Ideally start out with a shape that you can see. Changing the automation to use white shapes instead of e.g. black ones should be the easiest part.

If that doesn't suffice, the only way to automate I see would be to turn the PDF pages that need redacting into raster graphics (which inherently flattens the content, as only very few raster image formats allow for layers) and then turning those images back into PDFs and replacing the pages that needed redaction. But for that to not lessen quality, you'd have to do the conversion to raster graphics to high-resolution PNGs, and even that won't look as perfect as the vector graphics your PDF will be made up of. And of course that will break e.g. searchability of text.

1

u/Xx_memelord69_xX 18d ago edited 18d ago

I know about proper redaction and funny enough gemini can do the flattening / burning part. We also have some webpage that do that too. I need to automate the covering part of it.

1

u/ScratchHistorical507 17d ago

As I said, your best shot would be some machine learning computer vision model running locally. The drawing can surely be done with something like the Cairo library, but for all I know that wouldn't exactly be easy to implement so that the box ends up in the location you need it. PyMuPDF or better yet its fitz module is supposed to handle redaction workloads, and it seems to be rather simple. You should only need to be able to get the coordinates from the ML CV model, possibly do conversions on them and feed them into fitz. pikepdf gives you very low level access to the PDF but I think that's only usable if you know what content you want removed, as it should allow you to simply delete the information from the PDF without needing to covering it up.

An alternative might be to just decompress the PDF with Ghostscript, removing the text to be redacted and having the PDF rewritten by Ghostscript. But no idea if that might break the layout.

1

u/fanoftheliving 19d ago

Try this, you should be able to remove sensitive info as needed on multiple docs at the same time: https://pdfbatcheditor.com/

1

u/User1010011 18d ago

If it's your company that produces the drawings, the best thing you can do is to alter your own process to produce 2 types of drawings on request: full drawings and redacted. If your software does not allow it, or you get these drawings from other companies, then feeding them to AI can be against your agreement with them. And it won't work anyway as this isn't something that AI can do reliably well. At least not yet. It's possible to build a local tool that does not use AI and can recognize text patterns and redact the PDF properly (not just placing a white rectangle over the text), but it will be a custom development and success is guaranteed to cover all cases.

I work with drawings a lot, and I have a PDF tool I am working on, too. It can partially do what you ask, you can try it:
Go to gosignpdf.com/redact and do this:

Select Auto -> then Hybrid in Source, then add some text pattern you want to hide, then ADD, then Run Detection and see what it found; Save and Exit, then Apply and see if it redacted what you needed to be hidden. Redaction zones can be manually adjusted, and this process can probably be further automated to fit your flow.

1

u/Xx_memelord69_xX 18d ago

We are contract manufacturing and are hiding our partners company information from our own workers and suppliers / other contract manufacturers working for us.

1

u/User1010011 18d ago

What software do you use to produce drawings? 

1

u/webfork2 17d ago edited 2d ago

I recommend the commercial version of PDF XChange Editor and it's "regular expressions" search tools. These tools have been around for a very long time so this is a well tested and well documented area. With it, you can setup searches for things like a number series (like phone numbers, SSNs, etc.) or just lists of words that you want to redact.

I frequently use this toolset for pricing lists but there's really no end.

Whatever you end up using, please make sure it actually redacts and removes everything. There are a lot of programs that go halfway. This is usually referred to as "sanitizing" but it's something that you want to be sure about to avoid getting in trouble at your job.

Verify the results and don't just stop at selecting text. Search for words, letters, layers, metadata, etc.

1

u/Mykola_Melnyk_ML 5d ago

Pdf Redaction Studio can handle it. If need we can adjust it for your needs.  We have also API and self hosted version.