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.
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.