Apache PDFBox Java 라이브러리를 사용하여 PDF를 만듭니다. 그러나, 나는 여러 줄의 텍스트 (자동 줄 바꿈)을 렌더링에 문제에 직면하고있다 :Apache PDFBox Java 라이브러리 - 텍스트가 렌더링되지 않습니다.
이//Creating PDF document object
PDDocument doc = new PDDocument();
//Adding the blank page to the document
doc.addPage(new PDPage());
PDPage page = doc.getPage(0);
PDImageXObject pdImage = PDImageXObject.createFromFile("C:\\Users\\abc\\Desktop\\abc.png", doc);
PDPageContentStream contentStream = new PDPageContentStream(doc, page);
contentStream.drawImage(pdImage, 10, 720);
//Begin the Content stream
contentStream.beginText();
contentStream.newLineAtOffset(50, 735);
//Setting the font to the Content stream
contentStream.setFont(PDType1Font.TIMES_ROMAN, 16);
contentStream. showText("ABC Management System");
//Setting the leading
//contentStream.setLeading(14.5f);
//Setting the position for the line
contentStream.newLineAtOffset(25, 600);
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);
//Ending the content stream
contentStream.endText();
System.out.println("Content added");
//Closing the content stream
contentStream.close();
//Saving the document
doc.save("my_doc.pdf");
System.out.println("PDF created");
//Closing the document
doc.close();
내가 faciing하고 문제가 PDF 파일로 렌더링지고 있지 않은 텍스트의 후반 (텍스트 1, 텍스트 2)입니다. pdf에는 이미지와 첫 번째 줄 ABC Management System
만 표시됩니다.
여러 줄 텍스트를 생성하려면 다음을 참조하십시오. PDFBox - Adding Multiple Lines.
setLeading
이 무엇인지 이해하지 못 했으므로 주석을 달아서 다시 시도했지만 텍스트는 여전히 렌더링되지 않았습니다.
@TilmanHausherr 일했습니다. 감사! – HBK
@TilmanHausherr 배경색을 변경할 방법이 있습니까? – HBK
직사각형을 비연 마성 색으로 그려야합니다. –