PDF Software

How to rotate PDF pages using Python program language?

VeryUtils PythonPDF Library is a pure Python library to manipulate PDFs from Python. You can use it to rotate some pages in your PDF files. For example, if you scan a few pages from a book to PDF file, turning the book around every other page, so half the pages in the PDF are upside down. Now, you can use PythonPDF library to write a python script to rotate the even numbered pages. The python script counts pages from 0, so it rotates the odd numbered pages from its perspective.

VeryUtils PythonPDF Library can be purchased from this web page,

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

After you buy it, you will get a download URL to its source code right now, please download that source code package and unzip it to a folder, such as,

D:\downloads\python-pdfrw

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 rotate the PDF pages in your PDF file using PythonPDF Library,

python rotate.py testcmd.pdf 270 1-3 5 7-9

usage:   rotate.py my.pdf rotation [page[range] ...]
         eg. rotate.py 270 1-3 5 7-9

        Rotation must be multiple of 90 degrees, clockwise.

Creates rotate.my.pdf with selected pages rotated. Rotates all by default.

Here is the screenshot of rotated PDF file,

image

This is the source code of rotate.py file,
---------------------------------------------------------
import sys
import os

from pdfrw import PdfReader, PdfWriter

inpfn = sys.argv[1]
rotate = sys.argv[2]
ranges = sys.argv[3:]

rotate = int(rotate)
assert rotate % 90 == 0

ranges = [[int(y) for y in x.split('-')] for x in ranges]
outfn = 'rotate.%s' % os.path.basename(inpfn)
trailer = PdfReader(inpfn)
pages = trailer.pages

if not ranges:
    ranges = [[1, len(pages)]]

for onerange in ranges:
    onerange = (onerange + onerange[-1:])[:2]
    for pagenum in range(onerange[0]-1, onerange[1]):
        pages[pagenum].Rotate = (int(pages[pagenum].inheritable.Rotate or
                                     0) + rotate) % 360

outdata = PdfWriter(outfn)
outdata.trailer = trailer
outdata.write()
---------------------------------------------------------
If you have any question for PythonPDF Library, please feel free to let us know, we are glad to assist you asap.

PDF Software

How to merge and combine PDF files using Python language?

In this tutorial I will show you how to merge and combine two or more PDF files into one PDF file using Python 3.

VeryUtils PythonPDF Library is a Python Library for splitting and merging the pages of PDF and PDF/A conform documents with practical additional functions. It can process multiple input and output documents simultaneously. PDF Merge Split is available as shell tool for batch processing with the command line and as API to be integrated with Python, PHP, C#, Visual Basic, Java or C/C++.

PythonPDF Library can be purchased on this web page,

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

after you purchase it, you will get a download URL to the latest version of PythonPDF Library, please download and unzip it to a folder, such as,

D:\downloads\python-pdfrw

before you use it, please set the main path to "PYTHONPATH" first, for example,

set PYTHONPATH=D:\downloads\python-pdfrw

then please go to "examples" folder, run following command line to test the PDF Merging function,

python cat.py testcmd.pdf watermark.pdf

You will get a merged PDF file after a few seconds, in the following screenshot, the pages #1-#32 are come from first PDF file, the pages #33-#43 are come from second PDF file,

image

The following is the Python source code of cat.py file,

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

from pdfrw import PdfReader, PdfWriter, IndirectPdfDict

inputs = sys.argv[1:]
assert inputs
outfn = 'cat.' + os.path.basename(inputs[0])

writer = PdfWriter()
for inpfn in inputs:
    writer.addpages(PdfReader(inpfn).pages)

writer.trailer.Info = IndirectPdfDict(
    Title='your title goes here',
    Author='your name goes here',
    Subject='what is it all about?',
    Creator='some script goes here',
)
writer.write(outfn)
--------------------------------------------------

This cat.py file demonstrates two features:

1) Concatenating multiple input PDFs.
2) Adding metadata to the PDF.

If you have any question for the PythonPDF Library, please feel free to let us know, we are glad to assist you asap,

https://veryutils.com/contact

PDF Software

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

VeryUtils

Partner with VeryUtils

VeryUtils is a Digital Products Trading Platform that sells Digital Products, Digital Downloads and Subscriptions Online.

image

Partner with VeryUtils
Everything's better when you work together. Which is why we're always looking for opportunities to work with new partners.

Resellers
We partner with regional resellers to distribute our products in markets across the globe. Find out why becoming a VeryUtils reseller can work for you.

Affiliates
Becoming an affiliate is an easy way to maximize your website's traffic. By joining our affiliates program you can earn up to 50% commission.

Business partnerships
Make your hardware, software, and technical services stand out by incorporating VeryUtils technology.

Cross marketing
Utilize co-marketing across various channels to increase your sales and brand recognition.

Product partnerships
Offer packaged solutions and bundled offers to add value for your clients.

Technology integration
Deliver seamless integration fast and efficiently by integrating your solutions with our products.

Interested in exploring Business Partnership opportunities with VeryUtils? please feel free to contact us,

The links of VeryUtils Partners,

Business Software, PDF Software, Photo Software, Scripts

How to use PHP Folder Watcher to monitor a folder and print JPG files to a certain tray of the printer?

Hi David,

Quick question about PHP Folder Watcher. Running PHP on Windows via Xampp. All I need is a watcher to see new .jpg files and send them to a local printer. But some files I need to send to a certain tray of the printer (i.e. Legal or Letter size). If your script doesn't already do that, do you think it's something I can modify? I know ONLY PHP. Also the printer is NOT the default printer and is shared on a network. Is that an issue?

Thanks so much!
Customer
---------------------------------------------

image
Hello,

Thanks for your message, PHP Folder Watcher is just a "watcher" to some folders, if you need to print JPG files to a certain tray of the printer, you need to use following product,

https://veryutils.com/pdf-print-command-line

You may login and download the trial version for free.

PHP Folder Watcher can be purchased on this web page,

https://veryutils.com/php-folder-watcher

PDFPrint Command Line is a Windows Command Line application which can be used to print PDF and Image files to a certain tray of the printer (i.e. Legal or Letter size), the network printer is not an issue, you can use PDFPrint Command Line to print PDF and Image files to both local and network printers without any problem.

  -listbins                        : list bins/trays of a printer
  -listjobs                        : list print jobs in printer's queue
  -listall                         : list printers, ports, monitors etc.
  -listpapers                      : list supported papers from a printer.
  -chgbin <int>                    : change bin/tray for printer by number
  -papersource <string>            : change bin/tray for printer by name
  -settraytopclfile <string>       : set tray to PCL file directly, only work when '-papersource' used

for example, you may call following command lines from PHP Folder Watcher to print PDF or JPG files to special tray of the printer,

   pdfprint.exe -listbins -printer "docPrint"
   pdfprint.exe -listpapers -printer "docPrint"
   pdfprint.exe -chgbin 15 -printer "docPrint" C:\input.pdf
   pdfprint.exe -papersource "auto" -printer "docPrint" C:\input.pdf
   pdfprint.exe -papersource "Tray 1" -printer "docPrint" C:\input.pdf
   pdfprint.exe -papersource "Manual Feed" -printer "docPrint" C:\input.pdf
   pdfprint.exe -papersource "Media Tray" -printer "docPrint" C:\input.pdf
   pdfprint.exe -papersource "Tray 3" -settraytopclfile C:\test.pcl
   pdfprint.exe -papersource "auto" -printer "docPrint" C:\input.jpg
   pdfprint.exe -papersource "Tray 1" -printer "docPrint" C:\input.png
   pdfprint.exe -papersource "Tray 2" -printer "docPrint" C:\input.tif
   pdfprint.exe -papersource "Tray 3" -printer "docPrint" C:\input.doc
   pdfprint.exe -papersource "Tray 4" -printer "docPrint" C:\input.docx

In the PHP Folder Watcher script, you can modify RunExternalEXE() function to call the PDFPrint.exe application, for example,

function PrintFile($strInFile)
{
    $strCurrentFolder = dirname(__FILE__);
    $strExeFile =  $strCurrentFolder . '/pdfprint/pdfprint.exe';
    $strCmd  = "\"$strExeFile\" -papersource \"Tray 4\" \"$strInFile\"";
    MyEcho(__FILE__, __LINE__, '', $strCmd);
    $strRawOutput = shell_exec($strCmd);
    MyEcho(__FILE__, __LINE__, '', "<pre>$strRawOutput</pre><br>");
    return $strRawOutput;
}

function RunExternalEXE($strInFile, $strInRootFolder, $strOutFolder, $strBackupFolder)
{
    MyEcho(__FILE__, __LINE__, '', "[RunExternalEXE] $strInFile => $strOutFolder");
    PrintFile($strInFile);   
}

If you encounter any problem, please feel free to let us know, we are glad to assist you asap.

VeryUtils