Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
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
*/
System.out.println("Testing");
BufferedImage stampImage = null;
try
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 )
}
}