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 » Decrease PDF size. Compress images?
Decrease PDF size. Compress images? [message #49437] Fri, 09 February 2018 15:38 Go to next message
shockjockey is currently offline  shockjockey
Messages: 3
Registered: July 2016
Junior Member
Hello all!

I am working on a converter that will extract and stitch a number of JPG files together into a single PDF file and lay text on top of it. This works fine but my problem is that the PDF file is very big, about 5 to 10 times the size of the JPG files combined. I wondered if I should take a different approach or could add some code to compress the images in the resulting PDF?\

This is a simplified code example of what I am doing so far:

Image img = StreamRaster::LoadStringAny("C:\\path\\to\\jpg.jpg");

Report r;
				
r.SetPageSize(img.GetWidth(), img.GetHeight());
				
r.DrawImage(0, 0, img);

String pdf_contents = Pdf(r);

SaveFile("C:\\path\\to\\pdf.pdf", pdf_contents);


Thanks in advance for any pointers in the right direction that you might be able to give me!

[Updated on: Fri, 09 February 2018 15:49]

Report message to a moderator

Re: Decrease PDF size. Compress images? [message #49438 is a reply to message #49437] Fri, 09 February 2018 17:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
shockjockey wrote on Fri, 09 February 2018 15:38
Hello all!

I am working on a converter that will extract and stitch a number of JPG files together into a single PDF file and lay text on top of it. This works fine but my problem is that the PDF file is very big, about 5 to 10 times the size of the JPG files combined. I wondered if I should take a different approach or could add some code to compress the images in the resulting PDF?\

This is a simplified code example of what I am doing so far:

Image img = StreamRaster::LoadStringAny("C:\\path\\to\\jpg.jpg");

Report r;
				
r.SetPageSize(img.GetWidth(), img.GetHeight());
				
r.DrawImage(0, 0, img);

String pdf_contents = Pdf(r);

SaveFile("C:\\path\\to\\pdf.pdf", pdf_contents);


Thanks in advance for any pointers in the right direction that you might be able to give me!


Well, this is a tiny bit beyond what PdfDraw can do. We will need to add some direct JPG support to PdfDraw to allow this.

Which might not be that hard actually, this can help:

https://blog.idrsolutions.com/2011/07/extract-raw-jpeg-image s-from-a-pdf-file/
Re: Decrease PDF size. Compress images? [message #49439 is a reply to message #49438] Fri, 09 February 2018 20:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
PdfDraw JPEG support committed, example:

#include <CtrlLib/CtrlLib.h>
#include <Report/Report.h>
#include <PdfDraw/PdfDraw.h>

using namespace Upp;

GUI_APP_MAIN
{
	PdfDraw w;

	DrawJPEG(w, 100, 100, 2000, 1333, LoadDataFile("hermes.jpg"));
	
	String pdf = GetHomeDirFile("test.pdf");
	SaveFile(pdf, w.Finish());

	LaunchWebBrowser(pdf);
}


(reference/PdfDrawJPEG)

Note that it is necessary to have plugin/jpg in the project.
Re: Decrease PDF size. Compress images? [message #49442 is a reply to message #49437] Sat, 10 February 2018 15:25 Go to previous message
shockjockey is currently offline  shockjockey
Messages: 3
Registered: July 2016
Junior Member
I am lost for words. It's working flawlessly. Thank you so much!
Previous Topic: Loses qualifiers const in Size Image::GetDPI(void)
Next Topic: What is the best way to handle scaling icons?
Goto Forum:
  


Current Time: Thu Apr 25 15:12:57 CEST 2024

Total time taken to generate the page: 0.04135 seconds