PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Offset in DocumentRenderer or MigradocPrintDocument https://forum.pdfsharp.net/viewtopic.php?f=3&t=64 |
Page 1 of 1 |
Author: | drakaan [ Thu Jan 25, 2007 9:44 pm ] |
Post subject: | Offset in DocumentRenderer or MigradocPrintDocument |
I've boiled it down to a fairly simple example case, and I am seeing the following: Printing to an HP Laserjet 4 printer, I get different results depending on whether I print directly or open a saved document that I created with MigraDoc. There is a specific offset difference between the PDFDocumentRenderer.Save document and the directly-printed one. All objects in the directly printed PDF appear to be .25inches to the right and .33 inches down from where they appear in the same PDF saved to a file. I used the same code to build the document in two asp.net pages, saved one to a file (rendered with PDFDocumentRenderer, so I can .Save), and printed the other directly (rendered with DocumentRenderer so I can .Print), and regardless of which relative horizontal setting I use (well, between page page and margin), if they are set the same on each version, I get that particular offset between elements on the two pages. The PDFDocumentRenderer version appears to be correct, as far as placement of objects on the page goes, so I suspect there's a problem in DocumentRenderer. I plan to look into it tomorrow. On what may be a related note, in order to build Migradoc successfully (the latest version), I had to remove several assembly references that pointed to "MigraDocLite.xxx" and replace them with references to "MigraDoc.xxx". I have an older version of MigraDoc/PDFSharp that doesn't have this problem, but it also doesn't have the text layout stuff. Any pointers are appreciated. |
Author: | Thomas Hoevel [ Tue Feb 20, 2007 5:45 pm ] |
Post subject: | |
We can replicate this behaviour but haven't solved it. PDFsharp ignores the non-printable area of the page. The offset is printer and printer driver specific. We'll fix it soon. |
Author: | Stefan Lange [ Thu Mar 08, 2007 10:55 pm ] |
Post subject: | |
It's a bug in MigraDocPrintDocument. Add this to class MigraDocPrintDocument: Code: [DllImport("gdi32.dll")] static extern int GetDeviceCaps(IntPtr hdc, int capability); const int PHYSICALOFFSETX = 112; // Physical Printable Area x margin const int PHYSICALOFFSETY = 113; // Physical Printable Area y margin And this into function OnPrintPage Code: Graphics graphics = e.Graphics;
IntPtr hdc = graphics.GetHdc(); int xOffset = GetDeviceCaps(hdc, PHYSICALOFFSETX); int yOffset = GetDeviceCaps(hdc, PHYSICALOFFSETY); graphics.ReleaseHdc(); graphics.TranslateTransform(-xOffset * 100 / graphics.DpiX, -yOffset * 100 / graphics.DpiY); Setting OriginAtMargins = true is the correct solution by documentation of GDI+, but it does not work. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |