Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-5389

To set compressed on buffered image while creating a PDF

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.19
    • 2.0.27, 3.0.0 PDFBox
    • Documentation
    • None

    Description

      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

      Attachments

        Activity

          People

            tilman Tilman Hausherr
            komal.walia Komal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: