Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » PDF file from Report
PDF file from Report [message #56414] Tue, 09 March 2021 13:50 Go to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
Hi all,
using PdfDraw object for export an multiplepages report in PDf file result in a very big file when there are images. For reduce the size of the resulting PDF file, I modified the method PdfDraw::DrwImageOp(...) in this way:
void PdfDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& _img, const Rect& src, Color c)
{
	Image img = _img;
	if(!IsNull(c))
		img = CachedSetColorKeepAlpha(img, c);
	
	Tuple2<int64, Rect> key = MakeTuple(img.GetSerialId(), src);
	int q = images.Find(key);
	if(q < 0)
	{
		//q = images.GetCount();
		//images.Add(key, img);
		
	  Image h = sJPEGDummy();
		q = images.GetCount();
		images.Add(key, h);
		data = JPGEncoder(40).SaveString(img);
		img = h;
	}
	
	if(img.GetSerialId() == sJPEGDummy().GetSerialId())
		jpeg.Add(data);
	
	page << "q "
	     << Pt(cx) << " 0 0 " << Pt(cy) << ' '
	     << Pt(x) << ' ' << Pt(pgsz.cy - y - cy)
	     << " cm /Image" << q + 1 << " Do Q\n";
	     
}



This will convert every images in compressed JPEG, that in fact result in a smaller PDF file. But, I'm not sure that when the same image is repeated multiple times in the report, the PDF file will contain this image only once or multiple times. It seems to me that the Tuple2 key is intended for this scope, but in fact if I export a test report with only the same image for mulitple pages, without other content, the file size increase proportionally with the page numbers.
What I'm missing?

Many thanks!!
Re: PDF file from Report [message #56424 is a reply to message #56414] Wed, 10 March 2021 09:25 Go to previous messageGo to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
I solved it by changing some more code, generating the tuple key by the image hash. In this way the PDF file size decrease a lot, similar to using a PDF printer.

void PdfDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& _img, const Rect& src, Color c)
{
	Image img = _img;
	if(!IsNull(c))
		img = CachedSetColorKeepAlpha(img, c);
	
  //Tuple2<int64, Rect> key = MakeTuple(img.GetSerialId(), src);
	Tuple2<int64, Rect> key = MakeTuple(img.GetHashValue(), src);
	int q = images.Find(key);
	if(q < 0)
	{
		//q = images.GetCount();
		//images.Add(key, img);
		
	  Image h = sJPEGDummy();
		q = images.GetCount();
		images.Add(key, h);
		data = JPGEncoder(40).SaveString(img);
		img = h;
	}
	
	if(img.GetSerialId() == sJPEGDummy().GetSerialId())
		jpeg.Add(data);
	
	page << "q "
	     << Pt(cx) << " 0 0 " << Pt(cy) << ' '
	     << Pt(x) << ' ' << Pt(pgsz.cy - y - cy)
	     << " cm /Image" << q + 1 << " Do Q\n";
	     
}

[Updated on: Wed, 10 March 2021 09:25]

Report message to a moderator

Re: PDF file from Report [message #56425 is a reply to message #56424] Wed, 10 March 2021 18:09 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, the original idea was to use "void DrawJPEG(Draw& w, int x, int y, int cx, int cy, const String& jpeg_data)" if you want JPEG compression...
Re: PDF file from Report [message #56426 is a reply to message #56425] Wed, 10 March 2021 18:46 Go to previous messageGo to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
Maybe DrawJPEG can be used for adding some additional pictures to the PDF, (that is in fact all what can be understood from the available examples), but the U++ library itself don't foreseen nothing to configure PdfDraw to export PDF with JPG images and optimize the PDF size. When generating the PDF from an QTF text, the resulting file will be very, very fat for nothing.

thanks anyway.
Re: PDF file from Report [message #56427 is a reply to message #56426] Wed, 10 March 2021 21:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mubeta wrote on Wed, 10 March 2021 18:46
Maybe DrawJPEG can be used for adding some additional pictures to the PDF, (that is in fact all what can be understood from the available examples), but the U++ library itself don't foreseen nothing to configure PdfDraw to export PDF with JPG images and optimize the PDF size. When generating the PDF from an QTF text, the resulting file will be very, very fat for nothing.

thanks anyway.


Well, the problem with Jpeg is that it is loss compression, so we basically cannot do that. That BTW is the reason why the argument of DrawJPEG is String, because that way you can put original JPEG file there directly.

Anyway, improving QTF -> PDF with respect to JPG is a good idea. Almost all is there already, missing one last step...
Re: PDF file from Report [message #56432 is a reply to message #56427] Thu, 11 March 2021 12:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, optimizing finished. If JPEG is in RichText as raw image (that basically means that the file content is stored, you can achieve that e.g. in the editor by loading image directly from file), it is exported to PDF as JPEG.
Previous Topic: [PATCH READY] New plugin/icons/silk
Next Topic: Maximum images size in QTF
Goto Forum:
  


Current Time: Fri Mar 29 15:20:39 CET 2024

Total time taken to generate the page: 0.01045 seconds