pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hewson <j...@jahewson.com>
Subject Re: buffered image to pdf in pdfbox2.0
Date Tue, 28 Apr 2015 05:37:57 GMT

> On 27 Apr 2015, at 14:03, Tilman Hausherr <THausherr@t-online.de> wrote:
> 
> Am 27.04.2015 um 20:08 schrieb John Hewson:
>>> On 27 Apr 2015, at 08:52, Tilman Hausherr <THausherr@t-online.de> wrote:
>>> 
>>> 	  PDImageXObject pdImage;
>>>            if (imagePath.toLowerCase().endsWith(".jpg"))
>>>            {
>>>                pdImage = JPEGFactory.createFromStream(doc, new FileInputStream(imagePath));
>>>            }
>>>            else if (imagePath.toLowerCase().endsWith(".tif") ||
>>>                     imagePath.toLowerCase().endsWith(".tiff"))
>>>            {
>>>                pdImage = CCITTFactory.createFromFile(doc, new File(imagePath));
>>>            }
>>>            else if (imagePath.toLowerCase().endsWith(".gif") ||
>>>                     imagePath.toLowerCase().endsWith(".bmp") ||
>>>                     imagePath.toLowerCase().endsWith(".png"))
>>>            {
>>>                BufferedImage bim = ImageIO.read(new File(imagePath));
>>>                pdImage = LosslessFactory.createFromImage(doc, bim);
>>>            }
>>>            else
>>>            {
>>>                throw new IOException("Image type not supported: " + imagePath);
>>>            }
>> Tilman, maybe we could encapsulate this code in a static factory method, e.g. PDImageXObject.load(File)?
> 
> Yes, that's a good idea... the only thing that irritates me is that if we replace the
above code with load(), the example will no longer show how to create an XImage from a BufferedImage.
> 

Maybe we could have both in the example, or PDImageXObject.load(BufferedImage) too?

— John


> Tilman
> 
>> 
>> — John
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org <mailto:users-unsubscribe@pdfbox.apache.org>
> For additional commands, e-mail: users-help@pdfbox.apache.org <mailto:users-help@pdfbox.apache.org>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message