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 » U++ Library : Other (not classified elsewhere) » PdfDraw, custom DPI request + my fix
icon3.gif  PdfDraw, custom DPI request + my fix [message #58764] Mon, 22 August 2022 10:43 Go to next message
Mountacir is currently offline  Mountacir
Messages: 45
Registered: November 2021
Member
Hi,

I had a use case where i had to convert some .Pngs to .Pdfs so they can be printed.
The problem was that PdfDraw's fixed 600 DPI casues wrong size pdfs, for example, 6x9"/300dpi image will output as 3x4.5" pdf.
To fix this i modifid PdfDraw.h & PdfDraw.cpp to be able to pass the DPI with PdfDraw's constrctor.

Is it possible to add this feature to the U++? my fix or some other way to set the DPI would be great.

Thank you!
  • Attachment: PdfDraw.zip
    (Size: 12.98KB, Downloaded 56 times)
Re: PdfDraw, custom DPI request + my fix [message #58765 is a reply to message #58764] Mon, 22 August 2022 12:57 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Mountacir,

Please create PR with the changes you want to apply to main branch. It allows code review and changes are easily visible. You can find our repository here.

Klugier


U++ - one framework to rule them all.

[Updated on: Mon, 22 August 2022 12:57]

Report message to a moderator

Re: PdfDraw, custom DPI request + my fix [message #58767 is a reply to message #58765] Tue, 23 August 2022 09:03 Go to previous messageGo to next message
Mountacir is currently offline  Mountacir
Messages: 45
Registered: November 2021
Member
Klugier wrote on Mon, 22 August 2022 12:57
Hello Mountacir,

Please create PR with the changes you want to apply to main branch. It allows code review and changes are easily visible. You can find our repository here.

Klugier


Thank you! I just did.
Re: PdfDraw, custom DPI request + my fix [message #58818 is a reply to message #58764] Wed, 14 September 2022 21:12 Go to previous messageGo to next message
Mountacir is currently offline  Mountacir
Messages: 45
Registered: November 2021
Member
This is an example of the issue.
I attached a test example and two images of 6x9 inches at 300dpi and 600dpi that supposed to be book pages.

Trying to convert them to Pdfs using PdfDraw will output different size pdf for 300dpi page while outputing the correct size for 600dpi page.
Both of these pages should maintain thier size in inches.
index.php?t=getfile&id=6657&private=0

What's causing this issue is the baked-in 600dpi in:

double Pt(double dot)               { return 0.12 * dot; }


This fixed the problem for me, as the dpi is no longer fixed:
double Pt(double dot)               { return 72 * dot / dpi ; }

Re: PdfDraw, custom DPI request + my fix [message #58827 is a reply to message #58818] Thu, 15 September 2022 10:59 Go to previous messageGo to next message
mirek is currently online  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, that is misunderstanding and the problem is elsewhere.

Image::GetSize returns "pixel size" without taking account of DPI (or any other physical dimension).

Now there is Image::GetDots, which returns the size of image in "dots", where dot which is basically 600DPI pixel. Everything in U++ Draw related code that deals with physical dimensions is in dots, including all dimensions in PdfDraw.

Long story short, if you use GetDots instead of GetSize here, it will work as you needed.

Just for reference, to be sure I have tested with this code:

GUI_APP_MAIN
{
	for(const char *fn : { "C:/upp/MyApps/6x9_300dpi.png", "C:/upp/MyApps/6x9_600dpi.png" }) {
		Image img = StreamRaster::LoadFileAny(fn);
		Size isz = img.GetDots();
		DDUMP(isz);
	
		PdfDraw draw(isz.cx, isz.cy);
	
		draw.DrawImage(0, 0, isz.cx, isz.cy, img);
	
		SaveFile("D:/xxx/" + GetFileTitle(fn) + ".pdf", draw.Finish());
	}
}
Re: PdfDraw, custom DPI request + my fix [message #58829 is a reply to message #58764] Thu, 15 September 2022 18:55 Go to previous message
Mountacir is currently offline  Mountacir
Messages: 45
Registered: November 2021
Member
All this time and the problem was me using GetSize() instead of GetDots().
At some point i even doubled the image sizes to get to correct output pdf. well, this is embarrassing.

Very sorry for my wrong PR and thank you so much for your help.

Previous Topic: Windows 11 - Menubar issues
Next Topic: bug in the routine involving the time of the zip file
Goto Forum:
  


Current Time: Fri Mar 29 13:46:26 CET 2024

Total time taken to generate the page: 0.01817 seconds