'How can I uncompress a PDF with Python only?

I currently want to manipulate strings in a PDF. As common Python libraries seem not support this, I uncompressed the PDF with pdftk and edited the file directly with Python.

Is there a possibility to uncompress a PDF file with Python directly?



Solution 1:[1]

In the git-hub there was a new pull request for compress/uncompress. But it is not part of release.

You may want to copy --> paste the content of pypdftk.py to your local lib's pypdftk.py file. and just try using the following function.

import pypdftk

def test_compress():
    input_file = "/Out/test1.unc.pdf"
    pypdftk.compress(input_file, "./Out/test1.c.pdf")

def test_uncompress():
    input_file = "./Out/test1.pdf"
    pypdftk.uncompress(input_file, "./Out/test1.unc.pdf")

def main():
    test_num_pages()
    test_uncompress()
    test_compress()

if __name__ == '__main__':
    main()

Just gave a try. Not sure whether you are looking for same kind of solution. :) Hope this would help you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Haranadh