PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jul 06, 2024 11:29 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Jan 17, 2011 11:52 am 
Offline

Joined: Mon Jan 17, 2011 11:32 am
Posts: 1
Hi,

I have some code that draws a printing preview of a document. The document is drawn by an abstract class, DrawingProvider. It has a few methods for drawing (DrawString, DrawLine, etc.). I want to create a DrawingProvider, called DrawingProviderPDF. The data for the document, however, uses pixels, while PDF uses points. That's why in DrawingProviderPDF I apply the following code on each numeric value (coordinates or size) before using it (pdfGraphics is the XGraphics object I use to construct DrawingProviderPDF):

(pixels / pdfGraphics.Graphics.DpiX) * 72 - pixels / DPI (dots per inch) gives me the number of inches, and I multiply by 72 to get the number of points.

However, this doesn't work - the document is printed smaller, about two thirds of an A4 page on 120 DPI, and too large on 96 DPI. XGraphics.ScaleTransform(72 / pdfGraphics.Graphics.DpiX) didn't work as well. What am I doing wrong?

Project: PDFsharp
Build: GDI+
Version: 1.31


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 20, 2011 3:52 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
Hmm. Shouldn't that simply be:

points = (pixels * 72) / (dpi of device where your # of pixels originated)

I think there are 72 points per inch. And since your code supplies the proper # of pixels at a given device resolution, you just need to plug in that device resolution to get to points.

I'm not an expert here but
Attachment:
File comment: Earns the developer certification... :)
works-on-my-machine_small.png
works-on-my-machine_small.png [ 12.05 KiB | Viewed 3900 times ]


-Jeff


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 66 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group