-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from pdfrw import PdfReader, PdfWriter, PdfArray | ||
from pdfrwx.pdffilter import PdfFilter | ||
from pdfrwx.pdfstreamparser import PdfStream | ||
|
||
toArray = lambda obj: obj if isinstance(obj,PdfArray) \ | ||
else PdfArray([obj]) if obj != None else PdfArray() | ||
|
||
pdfIn = PdfReader('example.pdf') | ||
pdfOut = PdfWriter('example-out.pdf') | ||
for page in pdfIn.pages: | ||
contentsArray = toArray(page.Contents) | ||
for contents in contentsArray: | ||
stream = PdfFilter.uncompress(contents).stream | ||
treeIn = PdfStream.stream_to_tree(stream) | ||
treeOut = [] | ||
for leaf in treeIn: | ||
cmd, args = leaf[:2] | ||
if cmd != 'BT': treeOut.append(leaf) | ||
contents.stream = PdfStream.tree_to_stream(treeOut) | ||
contents.Filter = None | ||
pdfOut.addPage(page) | ||
pdfOut.write() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters