Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EMF playback in OnPrint(e) is different than straight GDI+ command

19 views
Skip to first unread message

brian

unread,
Aug 13, 2009, 7:38:08 PM8/13/09
to
I've have a custom class that for printing my various WinForms.

I pass it any control, and it loops through it measuring all of it's child
controls and extracts all the various text properties and paints out all the
various background images and colors using GDI+ (System.Drawing.Graphics)

So, in my PrintDocument component, as I loop through a stack of documents to
print, (i.e. stack of business objects being sequentially loaded into an
instance of a Form control) I simply grab the e.Graphics object from the
OnPrint event, and pass that over to my custom class (along with the Form
control) and voila.. I get superb output. Especially when my printer is
actually a PDF library. The GDI commands come into the PDF flawlessly and the
text in the PDF is selectable and searchable.

So far, so good. Except, it's a little slow as it interacts with the PDF
library.

My custom printing class will also accept a Graphics object that I conjure
up via the Form control's CreateGraphics() method. It then steps through the
same series of GDI+ commands to return a reference to an in-memory EMF file..
and then in my OnPrint(e) method, (after I've created my stack of EMF files)
I playback each EMF file onto the e.Graphics, expecting the resulting PDF to
be just as slick. But, it seems to somewhat rasterize everything instead of
getting me selectable, searchable, lightweight "texty" PDF.

From what I understood about the Metafile, was that it contained the exact
same GDI+ commands as what I was passing directly into my print library the
first time around. And, although my EMF-generated-PDF looks crisp and
accurate and identical to the first GDI+ generated PDF, I can't understand
why the fonts are getting rasterized.

Anyone have a clue about this? My apologies if this isn't the precise forum
for posting this, please advise where if I've got it wrong.

brian

unread,
Aug 14, 2009, 5:17:01 PM8/14/09
to
For what it's worth, here's a sample of my OnPrintPage function:

Protected Overrides Sub OnPrintPage(ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
MyBase.OnPrintPage(e)

_currentUserCtrl += 1
_nextUserCtrl = _currentUserCtrl + 1

If (_currentUserCtrl < Me.MetafileBuilder1.MetafileStack.Count) Then


e.Graphics.EnumerateMetafile(Me.MetafileBuilder1.MetafileStack(_currentUserCtrl), New Drawing.Point(0, 0), AddressOf DrawRecords)
e.HasMorePages = _nextUserCtrl < Me.MetafileBuilder1.MetafileStack.Count
Else
e.HasMorePages = False
End If
End Sub

One other note to add further to the weirdness.. when I print from my
PrintPreviewDialog, I *do* get the super nice "texty" PDF.. but if I do a
straight print and skip over the PrintPreviewDialog, I get the rasterized
PDF. Very weird.

brian

unread,
Aug 19, 2009, 11:48:01 AM8/19/09
to
I've decided that a more appropriate forum might be,
"microsoft.public.win32.programmer.gdi", so I've decided to post this
question over there instead, under the title, "Why does playback of an EMF in
OnPrintPage give different results?"
0 new messages