Skip to content

Instantly share code, notes, and snippets.

@gyfis
Created May 9, 2017 14:48
Show Gist options
  • Save gyfis/cbced399bc072d937c92b89d3b9cffa0 to your computer and use it in GitHub Desktop.
Save gyfis/cbced399bc072d937c92b89d3b9cffa0 to your computer and use it in GitHub Desktop.
Last frontier destroyed, submitting thesis.pdf
from pdfrw import PdfReader, PdfWriter, PdfObject
def main():
thesis = PdfReader('thesis.pdf')
for i, _ in enumerate(thesis.pages):
try:
im_keys = thesis.pages[i].Resources.XObject.keys()
for key in im_keys:
thesis.pages[i].Resources.XObject[key].Interpolate = PdfObject('false')
thesis.pages[i].Resources.XObject[key].SMask.Interpolate = PdfObject('false')
except:
print('This page does not have images: {}'.format(i))
PdfWriter().write('thesis_out.pdf', thesis)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment