Не в состоянии добавить дополнительный контент в существующий PDF с помощью PDFBoxJAVA

Программисты JAVA общаются здесь
Anonymous
Не в состоянии добавить дополнительный контент в существующий PDF с помощью PDFBox

Сообщение Anonymous »

Я использую PDFBox для генерации PDF с существующим PDF, содержащим шаблон, который должен использоваться для каждого PDF, который я хочу генерировать. Показано. < /p>

Пожалуйста, предложите любое решение для него. < /p>

Вот код, который я пытаюсь сделать: < /p>

//Loading an existing document
File file = new File("/home/spaneos/ScoringReports-TM-110617.pdf");
PDDocument document = PDDocument.load(file);

//Retrieving the pages of the document
PDPage page = document.getPage(0);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
//Begin the Content stream
contentStream.beginText();

//Setting the font to the Content stream
contentStream.setFont( PDType1Font.TIMES_ROMAN, 16 );

//Setting the leading
contentStream.setLeading(14.5f);

//Setting the position for the line
contentStream.newLineAtOffset(25, 725);

String text1 = "This is an example of adding text to a page in the pdf document.we can add as many lines";
String text2 = "as we want like this using the ShowText() method of the ContentStream class";

//Adding text in the form of string
contentStream.showText(text1);
contentStream.newLine();
contentStream.showText(text2);

//Creating PDImageXObject object
PDImageXObject pdImage = PDImageXObject.createFromFile("/home/spaneos/Downloads/man-161282_960_720.png",document);

//creating the PDPageContentStream object
PDPageContentStream contents = new PDPageContentStream(document, page);

contentStream.endText();

System.out.println("Content added");

//Closing the PDPageContentStream object
contents.close();

//Closing the content stream
contentStream.close();

//Saving the document
document.save(System.getProperty("user.dir").concat("/PdfBox_Examples/sample.pdf"));

//Closing the document
document.close();


Подробнее здесь: https://stackoverflow.com/questions/451 ... ing-pdfbox

Вернуться в «JAVA»