Problema con página vacía cuando se usa Apache PDFBox para agregar imagen a PDF
Estoy usando este código:https: //www.tutorialspoint.com/pdfbox/pdfbox_inserting_image.ht
Para ayudarme a agregar una imagen a un PDF existente. El problema es que el archivo que crea es una página en blanco con solo la imagen.
Aquí está mi código:
public void signPDF(PdfDTO pdfDTO) throws IOException{
//Loading an existing document
File file = new File(getAbsolutePdfPath(pdfDTO));
PDDocument doc = PDDocument.load(file);
//Retrieving the page
PDPage page = doc.getPage(0);
//a test to ensure the doc is loading correctly
PDDocument testDoc = new PDDocument();
testDoc.addPage(page);
testDoc.save("C:" + File.separator + "Users" + File.separator + "kdotson" + File.separator + "Documents" + File.separator + "test.pdf");
testDoc.close(); //this file is good so I know the doc is loading correctly
//Creating PDImageXObject object
PDImageXObject pdImage = PDImageXObject.createFromFile("C://test_images/signature.pdf", doc);
//creating the PDPageContentStream object
PDPageContentStream contents = new PDPageContentStream(doc, page);
//Drawing the image in the PDF document
contents.drawImage(pdImage, 0, 0);
//Closing the PDPageContentStream object
contents.close();
//Saving the document
doc.save(new File(getSignedPdfLocation(pdfDTO))); //the created file has the image on it, so I know the image is loading correctly
//Closing the document
doc.close();
}
Por lo que puedo decir, lo que estoy haciendo debería funcionar, y no recibo ningún error, ¿qué pasa?