BSA – Printing – Zooming in WPF

I use a Canvas as background for the diagrams and as I print I just provide a different Canvas using the same functions to draw on screen and paper. To zoom per page I just do the following – an example to zoom to 50%. The second part is to just draw the symbols using 100% position and size – the few lines below takes care of zooming.

Page page = new Page();
ScaleTransform scale = new ScaleTransform();
scale.ScaleX = 0.5;
scale.ScaleY = 0.5;
page.RenderTransform = scale;

It is a bit of manual work to use a XpsDocument and provide a print system and this might not be the only way, but all in all it is not a big job. What remains now is to calculate the size of the diagram versus size of paper and compute a zoom factor. After that I need to support margins and vertical/horizontal print pages as well as correct offsets so diagrams always start in the upper, let corner.

Next is to do the same for PDF and Web pages, but I suspect that I can reuse the XpsDocument for that. I also have yet to add the documents as I currently only print diagrams as is.

Categories: BSA

Leave a Reply