How to read, write and watermark/stamp PDF files in Python language?

How to read and write PDF files in Python language?

VeryUtils PythonPDF Library is a Python library and utility that reads and writes PDF files. PythonPDF Library is tested and works on Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.8 and later versions.

image

PythonPDF Library has following highlight features:
* Support operations include subsetting, merging, rotating, modifying metadata, etc.
* The fastest pure Python PDF parser library.
* Has been used for years by a printer in pre-press production.
* Can be used with rst2pdf to faithfully reproduce vector images.
* Can be used either standalone, or in conjunction with reportlab to reuse existing PDFs in new ones.
* PythonPDF Library will faithfully reproduce vector formats without rasterization.

PythonPDF Library can also be used in conjunction with reportlab, in order to re-use portions of existing PDFs in new PDFs created with reportlab.

PythonPDF Library can be purchased from this web page,

https://veryutils.com/pythonpdf-library-source-code

You will get a package after you purchase it, please download it and unzip it to a folder, such as, you may unzip it to "D:\downloads\python-pdfrw" folder, you need also set "PYTHONPATH" to the main folder PythonPDF Library, for example,

set PYTHONPATH=D:\downloads\python-pdfrw

after you set the path to "PYTHONPATH", please run following command line to test watermark function using PythonPDF Library,

python watermark.py testcmd.pdf watermark.pdf

Here is the screenshot of watermarked PDF file,

image

watermark.py contains following Python Source Code,

--------------------------------------------------------
import sys
import os

from pdfrw import PdfReader, PdfWriter, PageMerge

argv = sys.argv[1:]
underneath = '-u' in argv
if underneath:
    del argv[argv.index('-u')]
inpfn, wmarkfn = argv
outfn = 'watermark.' + os.path.basename(inpfn)
wmark = PageMerge().add(PdfReader(wmarkfn).pages[0])[0]
trailer = PdfReader(inpfn)
for page in trailer.pages:
    PageMerge(page).add(wmark, prepend=underneath).render()
PdfWriter(outfn, trailer=trailer).write()
--------------------------------------------------------

Other Example programs:
* 4up.py -- Prints pages four-up
* alter.py -- Simple example of making a very slight modification to a PDF.
* booklet.py -- Converts a PDF into a booklet.
* cat.py -- Concatenates multiple PDFs, adds metadata.
* poster.py -- Changes the size of a PDF to create a poster
* print_two.py  -- this is used when printing two cut-down copies on a single sheet of paper (double-sided)  Requires uncompressed PDF.
* rotate.py -- This will rotate selected ranges of pages within a document.
* subset.py -- This will retrieve a subset of pages from a document.
* watermark.py  -- Adds a watermark to a PDF

No votes yet.
Please wait...

Related Posts

Leave a Reply

Your email address will not be published.