Our site written in php receives PDF files from customers. After processing, the next step is code from a vendor. That code requires that each page is 8.5x11" in portrait. The code also requires that the page have data like this (output from pdfinfo):
Page 1 size: 612 x 792 pts (letter)
Page 1 rot: 0
Page 1 MediaBox: 0.00 0.00 612.00 792.00
Page 1 CropBox: 0.00 0.00 612.00 792.00
Page 1 BleedBox: 0.00 0.00 612.00 792.00
Page 1 TrimBox: 0.00 0.00 612.00 792.00
Page 1 ArtBox: 0.00 0.00 612.00 792.00
Sometimes customers give us PDFs with one or more pages in portrait. We have code that uses FPDI to rewrite the file, rotating the pages that need it by 90 degrees:
$pdf->AddPage('L', array(215.9, 279.4), 90);
The problem is that is just sets rot=90 and the resulting file has this (output from pdfinfo):
Page 3 size: 792 x 612 pts (letter)
Page 3 rot: 90
Page 3 MediaBox: 0.00 0.00 792.00 612.00
Page 3 CropBox: 0.00 0.00 792.00 612.00
Page 3 BleedBox: 0.00 0.00 792.00 612.00
Page 3 TrimBox: 0.00 0.00 792.00 612.00
Page 3 ArtBox: 0.00 0.00 792.00 612.00
Our next step code does not recognize the rot=90 and sees this as a landscape page.
What can I use to change the page characteristics to be like the first set of data (the portrait image)? In our environment ghostscript is available. pdftk can be used (with more difficulty).
ADDED I started with Patrick's pdfrw but ultimately shifted to staying with just FPDF. One odd thing that I noticed: I lost the rotation fix for most files rotated to be only letter, portrait using FPDF and pdfrw when I concatenated to something else using ghostscript. Solution: I ran the "fix rotation" code again after concatenating any files with gs.