[ 
https://issues.apache.org/jira/browse/PDFBOX-5389?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17508009#comment-17508009
 ] 

Komal commented on PDFBOX-5389:
-------------------------------

Dear Tilman,

 

I have tried the API PDImageXObject.createFromFile(inputFile, document); of 
PDFBOX version 2.0.25

but it is giving same exceptions as in version 2.0.19:

java.io.IOException: First image in tiff is not a single tile/strip
    at 
org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.extractFromTiff(CCITTFactory.java:484)
    at 
org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.createFromRandomAccessImpl(CCITTFactory.java:261)
    at 
org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.createFromFile(CCITTFactory.java:237)
    at 
org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.createFromFile(CCITTFactory.java:214)
    at 
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.createFromFileByExtension(PDImageXObject.java:256)
    at 
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.createFromFile(PDImageXObject.java:208)
    at 
Drivers.convertImageToPDFUsingPDFBOX.main(convertImageToPDFUsingPDFBOX.java:112)
Exception in thread "main" java.lang.NullPointerException
    at 
org.apache.pdfbox.pdmodel.PDPageContentStream.drawImage(PDPageContentStream.java:696)
    at 
Drivers.convertImageToPDFUsingPDFBOX.main(convertImageToPDFUsingPDFBOX.java:121)

 

Because of this exception we are using API

LosslessFactory.createFromImage(); which works on all type of images and Here, 
I need a API to set different compressions like CCITTFAXDecode, Jpeg 
compression and so on

 

.

Kindly suggest.

> To set compressed on buffered image while creating a PDF
> --------------------------------------------------------
>
>                 Key: PDFBOX-5389
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5389
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Documentation
>    Affects Versions: 2.0.19
>            Reporter: Komal
>            Priority: Major
>
> Dear Concerned,
>  
> Dear Concerned,
>  
> We need to convert images into PDF. We have many format of image type like 
> tiff with any compression (G3, G4, LZW or Jpeg compression), JPEG, BMP, PNG. 
> Images can be single strip or multistrip/multitiles.
>  
> We have converted these images into buffered image and add it to pdf page but 
> for all type of image only compression set is /flatdecode. I need to set 
> different compression for different image format.
>  
> Kindly suggest how to set the compression while inserting image in creation 
> mode of PDF
>  
> Code:
> {
> PDDocument document = new PDDocument();
> //generated buffered image BufferedImage bim;
>                 PDPage page = new PDPage(new PDRectangle((int) 
> bim.getWidth(), (int)bim.getHeight()));
>                document.addPage(page);
>                //Creating PDImageXObject object 
>                PDImageXObject imgObj = null;
>          try {
>                                 imgObj = 
> LosslessFactory.createFromImage(document, bim);
>                                 } catch (IOException e) {
>                                                 // TODO Auto-generated catch 
> block
>                                                 e.printStackTrace();
>                                 }
>         //PDPageContentStream contentStream = new 
> PDPageContentStream(document, page, AppendMode.OVERWRITE,true,true);
>          PDPageContentStream contentStream = new 
> PDPageContentStream(document, page);
>                contentStream.drawImage(imgObj, 0, 0);
>                contentStream.close();
>                //fileForInput.close();
>  
>                document.save(outputFile + ".pdf");
>                document.close();
> }
>  
> PDFBox vesion : 2.0.19
>  
> Regards,
> Komal Walia



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to