Jump to content
Changes to the Jaspersoft community edition download ×

pdf file/memory size with jpg and gif files


Recommended Posts

By: Eric Everman - eeverman

pdf file/memory size with jpg and gif files

2002-07-25 10:58

I've noticed that including jpg files causes that resulting pdf file to expand to 8-10x the size of the jpg image, while gif files do not seem to be cause this. My test was done on a relatively empty report with a single scaled image.

 

Also, the memory size required to process a report with a largish jpg is also largish. I tried to run a single page report with a 1M jpg in 64M of memory space. Not enough - it generated an 'out of memory error' and I had to bump the -Xmx memory to 100M.

 

Has anyone else run into this file size / memory issue? Am I doing something wrong?

 

Thanks for your help,

 

Eric Everman

 

 

By: Bernd Proissl - berndproissl

RE: pdf file/memory size with jpg and gif fil

2002-07-25 11:26

Hi,

java printing uses lots of resources, this is common. Search th bugbase for "printing, memory, huge"

 

Bernd

 

 

 

By: Eric Everman - eeverman

RE: pdf file/memory size with jpg and gif fil

2002-07-26 08:38

Thanks for the replies - It sounds like there is not much that can be done as far as memory requirements go.

 

Does anyone have ideas on why pdfs with scaled jpgs turn out to be so much larger then the original jpg?

 

 

Eric Everman

 

 

By: Paulo Soares - psoares33

RE: pdf file/memory size with jpg and gif fil

2002-07-26 08:53

jpeg use a DCT filter to compress the image. This filter is rather eficient to compress continuous tone images such as photographs but is not lossless. When the image is imported into an awt image it's expanded pixel by pixel and then compressed in the pdf with a lossless filter (zip type). After all this the image in the pdf is a lot bigger than the original. Jasper could use the strategy to keep the awt image and the file that originated it together. A configuration option would select if one or the other were to be used in the pdf. This would work for jpg files and most of the png (not with 16 bit and progressive png).

 

 

By: Teodor Danciu - teodord

RE: pdf file/memory size with jpg and gif files

2002-08-05 01:02

 

Hi,

 

I'll dig into this issue.

 

Thank you all,

Teodor

 

 

 

By: Paulo Soares - psoares33

RE: pdf file/memory size with jpg and gif files

2002-07-26 03:25

The problem is not with you but with jasper. jasper reads all the images to a java.awt.Image and then inserts this image into the pdf. When an awt image is read it's expanded in memory twice, the first one when it's read from file and the second one when it's inserted in the pdf. For a brief period of time this two images live together, hence the huge memory resources needed. This is rather unfortunated as jpeg can be inserted directly into the pdf.

 

 

By: Chris Beels - cbeels

RE: pdf file/memory size with jpg and gif files

2002-12-03 10:07

I'm encountering a related phenomenon. I have a 50 page report, with each page running as a subreport. Each page has the same logo GIF. The report is normally 3.6MB, but when I take out this logo, it drops to 1.5MB, all for a an 8k GIF! Is there a way to force the PDF to save the image once, displaying the same image on each page?

 

 

By: Matthew Ashley - mashley

RE: pdf file/memory size with jpg and gif files

2002-12-03 15:17

The iText api allows jpg, png, images to be embeded into pdf without decompresing, so I hacked the jasper source so that the awt.Image is not used, the image file is placed directly in a iText image. I found the time to generate a report reduced about 10 times, and pdf file size was reduced about 5 times. This was a quick hack and I had to disable clipping, but resizing worked fine.

 

Code change was in JRPdfExporter.exportImage

 

com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(printImage.getImageData());

 

 

 

By: Chris Beels - cbeels

RE: pdf file/memory size with jpg and gif files

2002-12-05 09:58

Teodor,

 

Any thoughts of making iText compressed images a standard option? Sounds like a major improvement...

 

Chris

 

 

By: Teodor Danciu - teodord

RE: pdf file/memory size with jpg and gif files

2002-12-05 10:30

 

Hi,

 

I have already made the modification and tested it.

But it looks like not all GIF files are supported by

iText this way.

However, if I load them in java.awt.Image objects and

then insert them into PDF, it works.

 

I have to devise a way to handle this transparently.

Hopefuly for the next version.

 

Any hints appreciated.

Teodor

 

 

 

By: Chris Beels - cbeels

RE: pdf file/memory size with jpg and gif files

2002-12-13 13:15

Teodor,

 

Here's how I did it cheaply:

 

byte[] imageData = printImage.getImageData();

com.lowagie.text.Image image = null;

if (checkForGif(imageData)) {

java.awt.Image awtImage = JRImageLoader.loadImage(imageData);

System.err.println("GIF SUPPORT DEPRECATED - please switch to PNG");

image = com.lowagie.text.Image.getInstance(awtImage, null);

}

else {

image = com.lowagie.text.Image.getInstance(imageData);

}

 

...

 

/** check whether a given image is a GIF or not */

private boolean checkForGif(byte[] imageData) {

return imageData[0] == 'G' &&

imageData[1] == 'I' &&

imageData[2] == 'F';

}

 

 

By: Chris Beels - cbeels

Interlaced PNGs also cause crash

2002-12-17 08:54

One final comment on this, some of our PNGs were generated by GD as "interlaced", and these also cause the iText image class to fail.

 

 

By: Teodor Danciu - teodord

RE: Interlaced PNGs also cause crash

2002-12-17 09:04

 

Hi,

 

I have solved this issue and will be available in the next version.

If the PDF exporter cannot handle the file content directly,

we add the image using java.awt.Image as we do today.

 

Thank you,

Teodor

 

 

 

By: Matthew Ashley - mashley

RE: pdf file/memory size with jpg and gif files

2002-12-05 21:00

Chris,

 

While using a modfied version without awtimage may reduce the file size, I don't think it will fix the main cause of the problem. It sounds like your logo image is being embedded multiple times into the pdf.

 

Is it in the header, or footer. I havn't checked, but that may cause the image to be embedded only once, but used multiple times within the pdf.

 

I checked the iText doco, and it appears that if the image is in a chunk, and the chunk is used multiple times, then the image will be included only once.

 

Not sure if JasperReports does this.....

 

 

 

 

By: Teodor Danciu - teodord

RE: pdf file/memory size with jpg and gif files

2002-12-07 02:00

 

Hi,

 

JasperReports reuses "isUsingChache" images at .jrprint level. When generating PDF, it does not

reuse images.

Maybe in the future.

 

Thank you,

Teodor

 

 

 

By: Chris Beels - cbeels

RE: pdf file/memory size with jpg and gif files

2002-12-10 14:45

Matt,

 

I finally got around to figuring out how to do your change in 3.3 (we can't upgrade due to unfortunate overflow issues).

 

It is rockin' out! Now I have to turn off all the places I was using ImageMagick to convert png->gif...

 

Thanks,

Chris

 

 

By: Chris Beels - cbeels

RE: pdf file/memory size with jpg and gif files

2002-12-10 15:17

Woops, spoke to soon. Now it's really weird. It looks great in Acrobat, but when we print a page with an image generated this way, the page cuts off half way and prints a second page that says

 

ERROR: ioerror

OFFENDING COMMAND: image

STACK:

 

-dictionary-

-savelevel-

 

Something tells me we're better off sticking with the released jasper, slower or not. :(

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...