!!!参考 http://d.hatena.ne.jp/ocs/20110520/1305866658 !!!準備 iTextを準備する。 注意点はバージョンによってライセンスが異なる。 5以降はライセンスが厳しいので、4以前を使うのが無難。 {{ref itext-4.2.1.jar}} !!!サンプル 参考先のソースをほぼそのまま。 {{code Java, import java.io.FileOutputStream; import java.io.IOException; import java.util.*; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.pdf.PdfCopy; import com.lowagie.text.pdf.PdfImportedPage; import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.RandomAccessFileOrArray; public class test { public static void main(String[] args) { String inFiles[] = new String[args.length - 1]; System.arraycopy(args, 1, inFiles, 0, inFiles.length); connectPDF(args[0], inFiles); } public static void connectPDF(String outputPath, String... inputPaths) { Document document = null; PdfCopy copy = null; PdfReader reader = null; try { for (String inputPath : inputPaths) { reader = new PdfReader(new RandomAccessFileOrArray(inputPath), null); reader.consolidateNamedDestinations(); if (document == null) { document = new Document(reader.getPageSizeWithRotation(1)); copy = new PdfCopy(document, new FileOutputStream(outputPath)); document.open(); } PdfImportedPage page; int numberOfPages = reader.getNumberOfPages(); for (int i = 1; i <= numberOfPages; i++) { page = copy.getImportedPage(reader, i); copy.addPage(page); } reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } catch (DocumentException e) { throw new RuntimeException(e); } finally { if (reader != null) { reader.close(); } if (document != null) { document.close(); } if (copy != null) { copy.close(); } } } } }} {{category2 プログラミング言語,Java}}