filmov
tv
Unable to add TIFF images into a PDF using PDFBox
Показать описание
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Unable to add TIFF images into a PDF using PDFBox
I'm running into some issues in trying to create a PDF that consists of several TIF images using PDFBox 3.0.3. :(
I tried several different approaches, but none have worked so far. I get essentially blank pages with a black line on each page. :(
Attempt 1
PDDocument document = new PDDocument();
for (int i=0;i 5;i++)
{
String sTIFFpath = sRootDir+i;
PDPage page = new PDPage();
PDPageContentStream contentStream = new PDPageContentStream(document, page);
}
PDDocument document = new PDDocument();
for (int i=0;i 5;i++)
{
String sTIFFpath = sRootDir+i;
PDPage page = new PDPage();
PDPageContentStream contentStream = new PDPageContentStream(document, page);
}
The line that creates the image generates an exception. However, the image object is generated and retuned. Looking at the generated PDF I see essentially blank pages with a single blank line in them.
Here is the stack trace of the exception
2024-09-29 19:49:26,490 DEBUG PDImageXObject - Reading as TIFF failed, setting fileType to PNG
2024-09-29 19:49:26,490 DEBUG PDImageXObject - Reading as TIFF failed, setting fileType to PNG
To get around the exception, I replaced the line that generates the image with the following 2 lines:
BufferedImage biTiff = ImageIO.read(new File(sTIFFpath));
BufferedImage biTiff = ImageIO.read(new File(sTIFFpath));
That added quite a bit of time to my program execution but got rid of the exception. However the resulting PDF is the same. :(
After lots of searches I found yet another approach. Again I replaced the single line that creates the image with the following code multitude:
ImageInputStSource of the question:
Question and source license information: