Skip to content

Commit

Permalink
switch from PyPDF2 to PyPDF3
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Jan 18, 2022
1 parent db282db commit a8ca16d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -35,7 +35,7 @@ As with all open-source software, its use in production depends on many factors,
About
=====

xhtml2pdf is a HTML to PDF converter using Python, the ReportLab Toolkit, html5lib and PyPDF2. It supports HTML5 and CSS 2.1 (and some of CSS 3). It is completely written in pure Python, so it is platform independent.
xhtml2pdf is a HTML to PDF converter using Python, the ReportLab Toolkit, html5lib and PyPDF3. It supports HTML5 and CSS 2.1 (and some of CSS 3). It is completely written in pure Python, so it is platform independent.

The main benefit of this tool is that a user with web skills like HTML and CSS is able to generate PDF templates very quickly without learning new technologies.

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -2,7 +2,7 @@ arabic-reshaper>=2.1.0
coverage>=5.3
html5lib>=1.1
Pillow>=8.1.1
pyPdf2>=1.26.0
PyPDF3>=1.0.5
python-bidi>=0.4.2
reportlab>=3.5.53
six>=1.15.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -39,7 +39,7 @@
maintainer_email="luisza14@gmail.com",
url="http://github.com/xhtml2pdf/xhtml2pdf",
keywords="PDF, HTML, XHTML, XML, CSS",
install_requires=["html5lib>=1.0.1", "pyPdf2", "Pillow", "reportlab>=3.3.0", "six",
install_requires=["html5lib>=1.0.1", "PyPDF3", "Pillow", "reportlab>=3.3.0", "six",
"python-bidi>=0.4.2", "arabic-reshaper>=2.1.0"],
include_package_data=True,
packages=find_packages(exclude=["tests", "tests.*"]),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asian_font_support.py
Expand Up @@ -2,7 +2,7 @@
import io
from unittest import TestCase

from PyPDF2 import PdfFileReader
from PyPDF3 import PdfFileReader
from reportlab.pdfbase import _cidfontdata

from xhtml2pdf.document import pisaDocument
Expand Down
2 changes: 1 addition & 1 deletion tests/test_document.py
Expand Up @@ -5,7 +5,7 @@
import tempfile
from unittest import TestCase, skipIf

from PyPDF2 import PdfFileReader
from PyPDF3 import PdfFileReader

from xhtml2pdf.document import pisaDocument

Expand Down
12 changes: 6 additions & 6 deletions xhtml2pdf/document.py
Expand Up @@ -24,7 +24,7 @@
from xhtml2pdf.context import pisaContext
from xhtml2pdf.default import DEFAULT_CSS
from xhtml2pdf.parser import pisaParser
from xhtml2pdf.util import PyPDF2, getBox, pisaTempFile
from xhtml2pdf.util import PyPDF3, getBox, pisaTempFile
from xhtml2pdf.xhtml2pdf_reportlab import PmlBaseDoc, PmlPageTemplate

if not six.PY2:
Expand Down Expand Up @@ -145,15 +145,15 @@ def pisaDocument(src, dest=None, path=None, link_callback=None, debug=0,
doc.build(context.story)

# Add watermarks
if PyPDF2:
if PyPDF3:
file_handler = None
for bgouter in context.pisaBackgroundList:
# If we have at least one background, then lets do it
if bgouter:
istream = out

output = PyPDF2.PdfFileWriter()
input1 = PyPDF2.PdfFileReader(istream)
output = PyPDF3.PdfFileWriter()
input1 = PyPDF3.PdfFileReader(istream)
ctr = 0
# TODO: Why do we loop over the same list again?
# see bgouter at line 137
Expand All @@ -164,7 +164,7 @@ def pisaDocument(src, dest=None, path=None, link_callback=None, debug=0,
(bg.mimetype == "application/pdf")
):
file_handler = open(bg.uri, 'rb')
bginput = PyPDF2.PdfFileReader(file_handler)
bginput = PyPDF3.PdfFileReader(file_handler)
pagebg = bginput.getPage(0)
pagebg.mergePage(page)
page = pagebg
Expand Down Expand Up @@ -195,7 +195,7 @@ def pisaDocument(src, dest=None, path=None, link_callback=None, debug=0,
# Found a background? So leave loop after first occurence
break
else:
log.warning(context.warning("PyPDF2 not installed!"))
log.warning(context.warning("PyPDF3 not installed!"))

# Get the resulting PDF and write it to the file object
# passed from the caller
Expand Down
6 changes: 3 additions & 3 deletions xhtml2pdf/pdf.py
Expand Up @@ -18,7 +18,7 @@

import six

from xhtml2pdf.util import PyPDF2, getFile, pisaTempFile
from xhtml2pdf.util import PyPDF3, getFile, pisaTempFile

log = logging.getLogger("xhtml2pdf")

Expand Down Expand Up @@ -49,9 +49,9 @@ def addDocument(self, doc):
self.files.append(doc.dest)

def join(self, file=None):
output = PyPDF2.PdfFileWriter()
output = PyPDF3.PdfFileWriter()
for pdffile in self.files:
pdf = PyPDF2.PdfFileReader(pdffile)
pdf = PyPDF3.PdfFileReader(pdffile)
for pageNumber in six.moves.range(pdf.getNumPages()):
output.addPage(pdf.getPage(pageNumber))

Expand Down
4 changes: 2 additions & 2 deletions xhtml2pdf/util.py
Expand Up @@ -69,9 +69,9 @@
log = logging.getLogger("xhtml2pdf")

try:
import PyPDF2
import PyPDF3
except ImportError:
PyPDF2 = None
PyPDF3 = None

try:
from reportlab.graphics import renderPM
Expand Down

0 comments on commit a8ca16d

Please sign in to comment.