You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Bryan K Cantwell <bc...@firescope.com> on 2011/09/06 22:05:38 UTC
image to pdf help
I am trying to allow for as many image types as possible to be allowed
in my form for addition to a pdf.
Right now I can do jpg and tif, but really also need png and bmp, and
any other you may know.
Here is the code I have so far that works:
PDXObjectImage yimage = null;
if (logo.toLowerCase().endsWith(".jpg")) {
yimage = new PDJpeg(doc, new FileInputStream(logo));
} else if (logo.toLowerCase().endsWith(".tif") ||
logo.toLowerCase().endsWith(".tiff")) {
yimage = new PDCcitt(doc, new RandomAccessFile(new
File(logo), "r"));
} else {
throw new IOException("Image type not supported:" +
logo);
}
Any help adding at least bmp and png to this 'if else'?
Thanks,
Bryancan
How to make a blank PDXObjectImage
Posted by Bryan K Cantwell <bc...@firescope.com>.
I need to make a 'blank' or just an all white placeholder image for when
my user fails to upload an image to go in their pdf.
If they upload one I do this:
PDXObjectImage yimage = null;
if (logo.toLowerCase().endsWith(".jpg")) {
yimage = new PDJpeg(doc, new FileInputStream(logo));
}
How can I just make yimage a blank?
Thanks,
Bryancan
Re: image to pdf help
Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,
Am 06.09.2011 22:05, schrieb Bryan K Cantwell:
> I am trying to allow for as many image types as possible to be allowed in my
> form for addition to a pdf.
> Right now I can do jpg and tif, but really also need png and bmp, and any other
> you may know.
>
> Here is the code I have so far that works:
> PDXObjectImage yimage = null;
> if (logo.toLowerCase().endsWith(".jpg")) {
> yimage = new PDJpeg(doc, new FileInputStream(logo));
> } else if (logo.toLowerCase().endsWith(".tif") ||
> logo.toLowerCase().endsWith(".tiff")) {
> yimage = new PDCcitt(doc, new RandomAccessFile(new File(logo), "r"));
> } else {
> throw new IOException("Image type not supported:" + logo);
> }
>
> Any help adding at least bmp and png to this 'if else'?
You should create a BufferedImage of your image using ImageIO and use that
BufferedImage to create a PDJpeg using the alternative constructor.
> Thanks,
> Bryancan
BR
Andreas Lehmkühler