0
我使用PDFBOX創建了PDF。整個PDF我使用在使用資源流的PDF生成中不顯示(但加載)圖像
PDImageXObject ptabelle = PDImageXObject.createFromFile("src/main/resources/pdf/ptabelle.png", pdDocument);
而產生完美的,甚至加載的圖片,但該項目將需要去住一段時間,所以我有一個類加載器,以取代靜態路徑。完成PDF生成的所有內容後,將顯示文本,但不顯示圖像。
有趣的是,在PDF內部的圖像應該是「框」,但不是圖像。
這裏是流生成的代碼。
ClassLoader classLoader = getClass().getClassLoader();
PDStream pdStream = new PDStream(pdDocument, classLoader.getResourceAsStream("pdf/ptabelle.png"));
PDResources pdResources = new PDResources();
PDImageXObject ptabelle = new PDImageXObject(pdStream, pdResources);
PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, page4);
這裏是調用代碼中的長度+寬度變量在代碼中定義。
pdPageContentStream.drawImage(ptabelle, TEXT_BEGIN, currentYCoord, 172, 107);
請更改您的代碼,以便使用工廠類,對於png,這將是'LosslessFactory'。即首先用'ImageIO.read()'在BufferedImage中加載圖像,然後調用'LosslessFactory.createFromImage(doc,bufferedImage)'。這是否工作? –
@TilmanHausherr - 非常感謝您的先生,完美的訣竅:) –