PDFBox
  1. PDFBox
  2. PDFBOX-1306

Transparent PNG file display with black border

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7.0
    • Component/s: None
    • Labels:
      None

      Description

      Hi,

      I have added Transparent PNG file in PDF with PDFBox and it's display black border around image. I have added same PNG file with IText and it's display good in PDF.

      I have used below function to add PNG file. I am using latest PDFBox SVN code to add PNG file.

      public void createPDFFromImage( String inputFile, String image, String outputFile )
      throws IOException, COSVisitorException
      {
      // the document
      PDDocument doc = null;
      try
      {
      doc = PDDocument.load( inputFile );
      //we will add the image to the first page.
      PDPage page = (PDPage)doc.getDocumentCatalog().getAllPages().get( 0 );

      PDXObjectImage ximage = null;

      /*if( image.toLowerCase().endsWith( ".jpg" ) )

      { ximage = new PDJpeg(doc, new FileInputStream( image ) ); }

      else if (image.toLowerCase().endsWith(".tif") || image.toLowerCase().endsWith(".tiff"))

      { ximage = new PDCcitt(doc, new RandomAccessFile(new File(image),"r")); }

      else

      { BufferedImage awtImage = ImageIO.read( new File( image ) ); FileInputStream inputStream = new FileInputStream(image); PDStream stream = new PDStream(doc, inputStream); ximage = new PDPixelMap(stream); //throw new IOException( "Image type not supported:" + image ); }

      */

      System.out.println("Testing");
      BufferedImage stampImage = null;
      try

      { stampImage = ImageIO.read(new File(image)); }

      catch(Exception e)

      { e.printStackTrace(); }

      ximage = new PDJpeg(doc, stampImage );
      //ximage = new PDPixelMap(doc, stampImage);
      COSStream stream = ximage.getCOSStream();
      PDStream pdStream = new PDStream(stream);
      ximage = new PDPixelMap(pdStream);
      //BoxImage imageData = BoxImage.getInstance(image);

      //System.out.println(""+imageData.getImageType());
      PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true, true);
      AffineTransform transform = new AffineTransform(stampImage.getWidth(), 0, 0, stampImage.getHeight(), 20, 200);
      //contentStream.drawImage( ximage, 20, 20 );
      contentStream.drawXObject(ximage, transform);
      contentStream.close();
      doc.save( outputFile );
      }
      finally
      {
      if( doc != null )

      { doc.close(); }

      }
      }

      1. African_Elephant_Transparent.png
        95 kB
        Manoj Patel
      2. GeneratedFileIText.pdf
        125 kB
        Manoj Patel
      3. GeneratedFilePDFBox.pdf
        18 kB
        Manoj Patel
      4. PDFBox_NEW.pdf
        101 kB
        Manoj Patel
      5. iText_NEW.pdf
        80 kB
        Manoj Patel
      6. NEW.png
        3 kB
        Manoj Patel

        Activity

        Andreas Lehmkühler made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Andreas Lehmkühler made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Manoj Patel made changes -
        Comment [ Attachments NEW.png, iText_NEW.pdf and PDFBox_NEW.pdf ]
        Manoj Patel made changes -
        Attachment PDFBox_NEW.pdf [ 12526729 ]
        Attachment iText_NEW.pdf [ 12526730 ]
        Attachment NEW.png [ 12526731 ]
        Manoj Patel made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Andreas Lehmkühler made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Andreas Lehmkühler [ lehmi ]
        Fix Version/s 1.7.0 [ 12316940 ]
        Resolution Fixed [ 1 ]
        Manoj Patel made changes -
        Field Original Value New Value
        Attachment African_Elephant_Transparent.png [ 12526609 ]
        Attachment GeneratedFileIText.pdf [ 12526610 ]
        Attachment GeneratedFilePDFBox.pdf [ 12526611 ]
        Manoj Patel created issue -

          People

          • Assignee:
            Andreas Lehmkühler
            Reporter:
            Manoj Patel
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development