PDFsharp & MigraDoc Foundation http://forum.pdfsharp.de/ |
|
Use existing code, which assumes pixels, to draw a PDF? http://forum.pdfsharp.de/viewtopic.php?f=2&t=1511 |
Page 1 of 1 |
Author: | ddobrev [ Mon Jan 17, 2011 11:52 am ] |
Post subject: | Use existing code, which assumes pixels, to draw a PDF? |
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 |
Author: | jeffhare [ Thu Jan 20, 2011 3:52 pm ] |
Post subject: | Re: Use existing code, which assumes pixels, to draw a PDF? |
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 [ 12.05 KiB | Viewed 3904 times ] -Jeff |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |