mlodic / pdfid

MIT License
13 stars 4 forks source link

Added support for disarming files in memory #4

Closed IV1T3 closed 2 years ago

IV1T3 commented 2 years ago

This PR now supports to disarm PDF files from buffer objects and returns the respective disarmed buffer.

options = pdfid.get_fake_options()
options.disarm = True
options.return_disarmed_buffer = True

disarmed_pdf_buffers = pdfid.PDFiDMain(filenames, options, file_buffers)

As an example, disarming a PDF file with these properties:

{   'reports': [   {   '/AA': 1,
                       '/AcroForm': 1,
                       '/Colors > 2^24': 0,
                       '/EmbeddedFile': 0,
                       '/Encrypt': 0,
                       '/JBIG2Decode': 0,
                       '/JS': 26,
                       '/JavaScript': 27,
                       '/Launch': 0,
                       '/ObjStm': 2,
                       '/OpenAction': 0,
                       '/Page': 1,
                       '/RichMedia': 0,
                       '/XFA': 0,
                       'endobj': 156,
                       'endstream': 55,
                       'filename': './test',
                       'header': '%PDF-1.6',
                       'obj': 156,
                       'startxref': 1,
                       'stream': 55,
                       'trailer': 2,
                       'version': '0.2.7',
                       'xref': 2}]}

Would result in a disarmed file as follows:

{   'reports': [   {   '/AA': 0,
                       '/AcroForm': 1,
                       '/Colors > 2^24': 0,
                       '/EmbeddedFile': 0,
                       '/Encrypt': 0,
                       '/JBIG2Decode': 0,
                       '/JS': 0,
                       '/JavaScript': 0,
                       '/Launch': 0,
                       '/ObjStm': 2,
                       '/OpenAction': 0,
                       '/Page': 1,
                       '/RichMedia': 0,
                       '/XFA': 0,
                       'endobj': 156,
                       'endstream': 55,
                       'filename': './test',
                       'header': '%PDF-1.6',
                       'obj': 156,
                       'startxref': 1,
                       'stream': 55,
                       'trailer': 2,
                       'version': '0.2.7',
                       'xref': 2}]}
mlodic commented 2 years ago

If you have finished, I proceed to merge and create a new release

IV1T3 commented 2 years ago

If you have finished, I proceed to merge and create a new release

I am done. Thanks for your quick reply!