I would like to do the following. I have a set of PDF files, first I would like to check the origin of the coordinate system. If the origin of the coordinate system for pdf is not in the upper left corner (usually it is the beginning on the left), I would like to create a resulting PDF with coordinates in the upper left corner. I am trying to do this using the PDFBox [code snippet below], however the resulting PDF is getting empty, which I am doing wrong. I am new to PDFBox, so any help in this regard is greatly appreciated.
PDDocument doc = PDDocument.load("C:\\Users\\test\\workspace\\example1.pdf");
List allPages = doc.getDocumentCatalog().getAllPages();
PDPageContentStream contentStream = null;
for( int i=0; i<allPages.size(); i++ )
{
PDPage page = (PDPage)allPages.get( i );
contentStream = new PDPageContentStream(doc, page);
contentStream.concatenate2CTM(1f, 0f, 0f, -1f, 0f, page.findMediaBox().getHeight());
contentStream.saveGraphicsState();
contentStream.close();
}
doc.save("C:\\Users\\test\\workspace\\example2.pdf");
doc.close();
source
share