Skip to content

Commit

Permalink
Replace PyPDF2 with pypdf
Browse files Browse the repository at this point in the history
  • Loading branch information
ashenm committed Jan 6, 2024
1 parent 76ba527 commit d59918f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
beautifulsoup4==4.12.0
lxml==4.9.4
PyPDF2==2.12.1
pypdf==3.17.4
PyYAML==6.0.1
reportlab==3.6.13
18 changes: 9 additions & 9 deletions scripts/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from os import P_WAIT, path, remove, spawnlp
from os.path import basename
from PyPDF2 import PdfFileReader, PdfFileWriter
from pypdf import PdfReader, PdfWriter
from tempfile import NamedTemporaryFile
from argparse import ArgumentParser
from reportlab.pdfbase import pdfmetrics
Expand All @@ -27,7 +27,7 @@
args = parser.parse_args()

# denouement
output = PdfFileWriter()
output = PdfWriter()

# intermediate docs
intermediate = NamedTemporaryFile(mode='wb')
Expand All @@ -39,8 +39,8 @@
# construct denouement
with open(intermediate.name, 'rb') as resume, open(forefront.name, 'rb') as forepart:

intermediate.pdf = PdfFileReader(resume)
forefront.pages = intermediate.pdf.getNumPages()
intermediate.pdf = PdfReader(resume)
forefront.pages = len(intermediate.pdf.pages)

forefront.canvas = Canvas(filename=forefront.name, pagesize=A4, initialFontName='Helvetica')

Expand All @@ -62,24 +62,24 @@
forefront.canvas.save()

# read constructed custom headers
forefront.pdf = PdfFileReader(forepart)
forefront.pdf = PdfReader(forepart)

# merge resume and headers
for i in range(0, forefront.pages):
intermediate.pdf.getPage(i).mergePage(forefront.pdf.getPage(i))
output.addPage(intermediate.pdf.getPage(i))
intermediate.pdf.pages[i].merge_page(forefront.pdf.pages[i])
output.add_page(intermediate.pdf.pages[i])

# add metadata
# https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdfmark_reference.pdf
output.addMetadata({
output.add_metadata({
'/Subject': 'Curriculum Vitae',
'/Creator': 'XMLResume (https://github.com/ashenm/xmlresume)',
'/Title': 'Curriculum Vitae - Ashen Gunaratne',
'/Author': 'Ashen Gunaratne'
})

# configure initial view
output.setPageLayout('/SinglePage')
output.page_layout = '/SinglePage'

# write output
with open('resume.pdf', 'wb') as file:
Expand Down

0 comments on commit d59918f

Please sign in to comment.