Let me explain the problem, I'm getting stuck in it
If I change the dpi settings from the dialog of Printing Preferences of a virtual printer like PDF Creator or any printer that allows to change this setting, and then set a breakpoint like the code below:
PrintDialog printDialog = new PrintDialog();
System.Printing.PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
...... insert breakpoint here
I can see that the properties printDialog.PrintTicket.PageResolution.X; and printDialog.PrintTicket.PageResolution.Y change values correctly while printDialog.PrintTicket.PageMediaSize.Width and printDialog.PrintTicket.PageMediaSize.Height don't change despite the printer resolution change... an A4 paper in portrait mode will always have PageMediaSize.Height = 1122.5196850393702 and PageMediaSize.Width = 793.70078740157476 no matter which resolution is set before ..... for WPF the unit size of these dimensions is set to 1/96th inch but when is Ok on screen because default screen resolution is 96 dpi on the other side is wrong on the printer because it has a different resolution, in other words confuting that Height and Width of the paper are read only properties if I cannot find the way to tell WPF that the unit size of the printer is not 1/96th inch but for example 1/300th inch (if on the printer I previously set 300 dpi ) there's absolutely no way to print at higher resolution than 96dpi
A last note, in my specific case I cannot use RenderTargetBitmap and then resize all to match printer's paper height and width settings because I'm printing high definition barcode images and it would cause an image rescaling that would make the barcode unreadable on final paper because i create it with the purpose to be printed with a resolution of 300dpi which without a resizing will result out of bounds because WPF is telling me the printer paper dimensions in the wrong unit size (1/96th inch) despite the real dpis prevoiusly set on printer
Hoping to have clarified enough the problem,
thanks in advance, Dave
A hint to reproduce the issue is doing a printing with PrintVisual or PrintDocument methods with different printer resolution set before in the PrintDialog, the output will always be the same
Printing seems a tricky issue and I haven't done it in a while... But at any rate I suspect it is correct. Because WPF doesn't use 'pixels' as unit of measure but.. 'device independent pixels' (or DIP for short), that means WPF will always think there are 96 DIP, whatever the DPI. And the underlying system will scale thing accordingly.
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.
Hi Lloyd, thanks for the comment The problem was resolved drawing directly the lines of the barcode in a Canvas Since WPF thinks, draws (and also prints) vectorial it hasn't any problem handling vectorial shapes (at this point the real limit is only given by the printer's physical resolution), viceversa it could have problems handling raster images because it's not the way it's used to think and, like you said before it plainly translates bitmap pixels to WPF units without any sort of scale, so at 96DPIs (unless you set a different DPI value from Control Panel --> Display Settings but that's a different story and not a viable option in my case because printers are not monitors and will always have different resolutions).
modified 20-Nov-12 5:07am.
Last Visit: 31-Dec-99 19:00 Last Update: 10-Dec-16 17:55