I am currently developing an application where users can create/move TextBlocks on a canvas dynamically. Once they have positioned the TextBlocks where they want them they can press a print button which will cause a ZPL printer to print what is currently displayed on screen.
The ZPL commands are built by taking the following values from each TextBlock:
- XPosition = Canvas.Left
- YPosition = Canvas.Right
- Text = Text
However I can't find a way of getting the printout to resemble the on screen display. I guess this is because the values of Canvas.Left and Canvas.Right do not match up with the printers DPI.
Here is the conversion I am currently using (because I thought the Canvas.Left = 1 means 1/96th of an inch) (Top left of the canvas is 0,0)
public double GetZplXPosition(UIElement uiElement)
{
int dpiOfPrinter = 300;
double zplXPosition = (Canvas.GetLeft(uiElement) / 96.0) * dpiOfPrinter;
return zplXPosition;
}
Is there I can display controls in "real size". The paper being used will always be A5 (8.3 in x 5.8 in).
I thought about using a viewbox around a Canvas which had its width and height set to 830 x 580 (ratio correct for A5) however this didn't help.
Any suggestions??
Thanks