如何使用pdfbox(java)将两个pdf页面缝合在一起?

如何使用pdfbox(java)将两个pdf页面缝合在一起?,java,pdf,pdf-generation,pdfbox,Java,Pdf,Pdf Generation,Pdfbox,我找不到这样做的方法。我需要的是一页作为背景,另一页作为前景。我找到了 LayerUtility lu = new LayerUtility( doc ); PDXObjectForm form = lu.importPageAsForm( doc2, 0 ); PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get( 0 ); lu.wrapInSaveRestore( page ); AffineTransform

我找不到这样做的方法。我需要的是一页作为背景,另一页作为前景。

我找到了

LayerUtility lu = new LayerUtility( doc );
PDXObjectForm form = lu.importPageAsForm( doc2, 0 );
PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get( 0 );
lu.wrapInSaveRestore( page );
AffineTransform at = new AffineTransform();
lu.appendFormAsLayer( page, form, at, "new_layer_name" );

定义合并。。。在一个文档中,一个pdf紧跟着另一个?一个页面作为背景,另一个页面作为前景如果你想再看一个例子,请查看我的回答:如果你合并的pdf有不同的页面大小怎么办?它破坏了使用比导入层小的基本PDF测试的输出。我猜需要设置大小或更改mediabox/cropbox值。