Hi support,
I'm using pdfbox 2.0.8. I have some pdf files that I would like to merge
together in a single document. Multiple files can be used to compose a
single page, so they don't have the same size.
It works using the LayerUtility class, importing pages as layer and
appending layers to the new page. But doing this I loose link annotations
and hyper links are not clickable in the final document.
So is there a way to append a pdf page to an other document page, keeping
link annotations ? ( I can't use PDFMergerUtility because it only
"concatenates" pages, and i need to append content at specific positions ).
To reproduce this, use the example pdf in attachment and try to append it
as layer to a new Document ( see sample code ).
Thanks in advance
best regards
try( PDDocument exampleDoc = PDDocument.load( new File( "/tmp/exampleDoc.pdf" ) ) ) {
PDPage examplePage = exampleDoc.getPage( 0 );
try( PDDocument newDocument = new PDDocument() ) {
PDPage newPage = new PDPage( PDRectangle.A4 );
LayerUtility layerUtility = new LayerUtility( newDocument );
PDFormXObject form = layerUtility.importPageAsForm( exampleDoc, examplePage );
double translationY = 100.0;
double translationX = 250.0;
layerUtility.appendFormAsLayer(
newPage,
form,
AffineTransform.getTranslateInstance( translationX, translationY ),
UUID.randomUUID().toString()
);
newDocument.addPage( newPage );
File tempDoc = File.createTempFile( "doc-", ".pdf" );
newDocument.save( tempDoc );
System.out.println( tempDoc.getPath() );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]