From 59fec73079099fe3881f149627b53edcdc38cf37 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sun, 10 Apr 2022 06:53:36 +0200 Subject: [PATCH 1/2] MAINT: Remove Sample_Code Everything in the Sample_Code folder is now in the docs: https://pypdf2.readthedocs.io/en/latest/ --- PDF_Samples/README.md | 2 +- README.md | 3 +-- Sample_Code/README.md | 8 ------ Sample_Code/basic_features.py | 51 ----------------------------------- Sample_Code/basic_merging.py | 25 ----------------- Sample_Code/makesimple.py | 38 -------------------------- Sample_Code/makesimple.sh | 19 ------------- setup.cfg | 2 +- 8 files changed, 3 insertions(+), 145 deletions(-) delete mode 100644 Sample_Code/README.md delete mode 100644 Sample_Code/basic_features.py delete mode 100644 Sample_Code/basic_merging.py delete mode 100755 Sample_Code/makesimple.py delete mode 100755 Sample_Code/makesimple.sh diff --git a/PDF_Samples/README.md b/PDF_Samples/README.md index 2e2f1a3c9..640d11033 100644 --- a/PDF_Samples/README.md +++ b/PDF_Samples/README.md @@ -13,5 +13,5 @@ when changes to PyPDF2 are made, we keep them in mind. (This folder is available through GitHub only) -Feel free to add any type of PDF file or sample code, +Feel free to add any type of PDF file either by including it in a pull request on GitHub diff --git a/README.md b/README.md index bfc93db58..64821dc01 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,7 @@ with open("Resources/crazyones.pdf", "rb") as fp: PyPDF2 can do a lot more, e.g. splitting, merging, reading and creating annotations, decrypting and encrypting, and more. -Please see [the documentation](https://pypdf2.readthedocs.io/en/latest/), -[`Sample_Code`](https://github.com/py-pdf/PyPDF2/tree/master/Sample_Code) +Please see [the documentation](https://pypdf2.readthedocs.io/en/latest/) and [`Scripts`](https://github.com/py-pdf/PyPDF2/tree/master/Scripts) for more usage examples! diff --git a/Sample_Code/README.md b/Sample_Code/README.md deleted file mode 100644 index 3beb43024..000000000 --- a/Sample_Code/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# PyPDF2 Sample Code Folder - -This will contain demonstrations of the many features -PyPDF2 is capable of. Example code should make it easy -for users to know how to use all aspects of PyPDF2. - -Feel free to add any type of PDF file or sample code, -either by including it in a pull request on GitHub diff --git a/Sample_Code/basic_features.py b/Sample_Code/basic_features.py deleted file mode 100644 index 35d980247..000000000 --- a/Sample_Code/basic_features.py +++ /dev/null @@ -1,51 +0,0 @@ -from PyPDF2 import PdfFileWriter, PdfFileReader - -output = PdfFileWriter() -input1 = PdfFileReader(open("document1.pdf", "rb")) - -# print how many pages input1 has: -print("document1.pdf has %d pages." % input1.getNumPages()) - -# print how many pages input1 has in python3: -# print("This chart has {} pages.".format(input1.getNumPages())) - -# add page 1 from input1 to output document, unchanged: -output.addPage(input1.getPage(0)) - -# add page 2 from input1, but rotated clockwise 90 degrees: -output.addPage(input1.getPage(1).rotateClockwise(90)) - -# add page 3 from input1, rotated the other way: -output.addPage(input1.getPage(2).rotateCounterClockwise(90)) -# alt: output.addPage(input1.getPage(2).rotateClockwise(270)) - -# add page 4 from input1, but first add a watermark from another PDF: -page4 = input1.getPage(3) -watermark = PdfFileReader(open("watermark.pdf", "rb")) -page4.mergePage(watermark.getPage(0)) -output.addPage(page4) - - -# add page 5 from input1, but crop it to half size: -page5 = input1.getPage(4) -page5.mediaBox.upperRight = ( - page5.mediaBox.getUpperRight_x() / 2, - page5.mediaBox.getUpperRight_y() / 2 -) -output.addPage(page5) - -# add some Javascript to launch the print window on opening this PDF. -# the password dialog may prevent the print dialog from being shown, -# comment the the encription lines, if that's the case, to try this out: -output.addJS("this.print({bUI:true,bSilent:false,bShrinkToFit:true});") - -# encrypt your new PDF and add a password: -password = "secret" -output.encrypt(password) - -# add a title to your new PDF's metadata: -output.addMetadata({'/Title': 'PDF Metadata Title'}) - -# finally, write "output" to document-output.pdf -with open("PyPDF2-output.pdf", "wb") as outputStream: - output.write(outputStream) diff --git a/Sample_Code/basic_merging.py b/Sample_Code/basic_merging.py deleted file mode 100644 index e867d5417..000000000 --- a/Sample_Code/basic_merging.py +++ /dev/null @@ -1,25 +0,0 @@ -from PyPDF2 import PdfFileMerger - -merger = PdfFileMerger() - -input1 = open("document1.pdf", "rb") -input2 = open("document2.pdf", "rb") -input3 = open("document3.pdf", "rb") - -# add the first 3 pages of input1 document to output -merger.append(fileobj = input1, pages = (0,3)) - -# insert the first page of input2 into the output beginning after the second page -merger.merge(position = 2, fileobj = input2, pages = (0,1)) - -# append entire input3 document to the end of the output document -merger.append(input3) - -# Write to an output PDF document -output = open("document-output.pdf", "wb") -merger.write(output) - -# Close File Descriptors -merger.close() -output.close() - diff --git a/Sample_Code/makesimple.py b/Sample_Code/makesimple.py deleted file mode 100755 index a05ac7c94..000000000 --- a/Sample_Code/makesimple.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python -"Make some simple multipage pdf files." - -from __future__ import print_function -from sys import argv - -from reportlab.pdfgen import canvas - -point = 1 -inch = 72 - -TEXT = """%s page %d of %d - -a wonderful file -created with Sample_Code/makesimple.py""" - - -def make_pdf_file(output_filename, np): - title = output_filename - c = canvas.Canvas(output_filename, pagesize=(8.5 * inch, 11 * inch)) - c.setStrokeColorRGB(0,0,0) - c.setFillColorRGB(0,0,0) - c.setFont("Helvetica", 12 * point) - for pn in range(1, np + 1): - v = 10 * inch - for subtline in (TEXT % (output_filename, pn, np)).split( '\n' ): - c.drawString( 1 * inch, v, subtline ) - v -= 12 * point - c.showPage() - c.save() - -if __name__ == "__main__": - nps = [None, 5, 11, 17] - for i, np in enumerate(nps): - if np: - filename = "simple%d.pdf" % i - make_pdf_file(filename, np) - print ("Wrote", filename) diff --git a/Sample_Code/makesimple.sh b/Sample_Code/makesimple.sh deleted file mode 100755 index 29980e59c..000000000 --- a/Sample_Code/makesimple.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -n=1 -for np in 5 11 17; do - p=1 - f=simple$n.pdf - while expr $p \<= $np > /dev/null; do - if [ $p != 1 ]; then - echo " \c" - fi - echo "$f page $p of $np" - echo "" - echo "an incredible, yet simple example" - echo "Created with Sample_Code/makesimple.sh" - p=$(expr $p + 1) - done | enscript --no-header -o - |ps2pdf - $f - echo $f - n=$(expr $n + 1) - done diff --git a/setup.cfg b/setup.cfg index 97acc6e8b..9682b2d31 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,5 +30,5 @@ classifiers = Topic :: Software Development :: Libraries :: Python Modules [options] -packages = PyPDF2, Scripts, Tests, Sample_Code +packages = PyPDF2, Scripts, Tests python_requires = >=2.7 From ab38ee070c88347032a22d865c44ae96938e1439 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sun, 10 Apr 2022 13:36:26 +0200 Subject: [PATCH 2/2] Remove it from MANIFEST --- MANIFEST.in | 1 - 1 file changed, 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index d5bd0136c..c41e93739 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,5 @@ include CHANGELOG include LICENSE recursive-include Resources * -recursive-include Sample_Code * recursive-include Scripts * recursive-include Tests *