Showing posts with label Printing. Show all posts
Showing posts with label Printing. Show all posts

Tuesday, 18 June 2013

Some lines may be missing printing to OneNote

In one of the applications I work on with my Peach Innovations hat on, we have recently discovered how useful it is to print directly to One Note for generating reports.

However we discovered today that pen’s created like this

HPEN hp = ExtCreatePen(PS_GEOMETRIC|PS_JOIN_BEVEL|PS_ENDCAP_FLAT, thickness, &lbr, 0, NULL);

with a thickness of zero don’t actually show up when sent to one note, although they show up on screen, and on every printer we’ve ever used, as well as printing to XPS.

I can’t find anywhere that documents that this shouldn’t work, but setting the pen to thickness 1 solves the issue.

Wednesday, 25 July 2012

Landscape Printing and Preview in WPF: It’s the overload, stupid!

We’re just finishing up a new release for our weather station software, and thought it might be nice to add printing for our users.

The printouts lend themselves to Landscape orientation, but much as we searched, we couldn’t find a way to get the DocumentViewer control to show us the preview in Landscape mode.

In the end, there are a sequence of things that need to be done.

First, when you create your PrintDialog, make sure you set the PageOrientation property to PageOrientation.Landscape.  That in itself isn’t enough though.

So, now store the size of the paper from the successful print dialog, and construct your DocumentPaginator object.

var ms = printDialog.PrintTicket.PageMediaSize;
Size pageSize = (printDialog.PrintTicket.PageOrientation == PageOrientation.Portrait) ?
new Size(ms.Width.Value, ms.Height.Value) :
new Size(ms.Height.Value, ms.Width.Value);

var Paginator = new SamplePaginator(uc, pageSize);


Where uc some control or Framework Element.


And here’s the important bit.  When you return a DocumentPage, make sure you use the overload that takes the PageSize you calculated above.  If you do, then preview works great. 


I had naively assumed that overriding the PageSize abstract property would do this job, but it did not.