Re: Advanced printing
From: Ron Allen (rallen_at__nospam_src-us.com)
Date: 01/30/05
- Next message: Ron Allen: "Re: Advanced printing"
- Previous message: Axel Dahmen: "VS8: Custom Controls - HTML IntelliSense without Schema?"
- In reply to: Johan DM: "Re: Advanced printing"
- Next in thread: Johan DM: "Re: Advanced printing"
- Reply: Johan DM: "Re: Advanced printing"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 30 Jan 2005 12:12:12 -0500
Johan,
I don't know of simple samples available on the net and company rule
prevent me from posting code I've developed for internal use. There are the
text-only print samples from MS.
But in general a PrintDocument that I create overrides
OnBeginPrint - I allocate any fonts and Pens that I use here
OnEndPrint - I deallocate any allocations here
OnQueryPageSettings - I check my XML document current page for
Landscape and set the landscape flag appropriately.
OnPrintPage - Does all the work for each page
To draw a graphic such as a jpg use
Image img = Image.FromFile(theImageFileName) or use a stream with
the data in it
e.Graphics.DrawImage(img, new PointF(100.0f, 100.0f)) to draw at 1",
1"
Note that the standard measurement for a page is in 1/100ths of an inch and
then just draw the strings at the appropriate locations. To do your sample
in ad hoc code.
float x = 100.0f;
float y = 50.0f; // top of page
Image img = (get the image from a file or from a stream)
float deltax = ((float)img.Width/img.HorizontalResolution) * 100.0f;
// width of image in 1/100ths
float x2 = 750.0f; // 1 " from left size of an 8.5x11 page;
e.Graphics.DrawImage(img, newPointF(x2 - deltax, y));
float deltay = ((float)img.Height/img.VerticalResolution) * 100.0f;
// height of image
y += deltay; // if you want the text to start below the logo --
otherwise where desired
Font myBold = new Font("Arial", 10.0f, FontStyle.Bold);
Font myFont = new Font("Arial", 10.0f, FontStyle.Normal);
float leading = (myFont.SizeInPoints / 72.0f) * 100.0f; // get the
leading in 1/100ths
string s = "Activity Date: ";
e.Graphics.DrawString(s, myBold, Brushes.Black, x, y,
StringFormat.GenericTypographic);
float len = e.Graphics.MeasureString(s, myBold, new PointF(x, y),
StringFormat.GenericTypographic);
e.Graphics.DrawString(actDate.ToShortDateString(), myFont,
Brushes.Black, x+len, y,
StringFormat.GenericTypographic);
y += leading; // advance to next line. This would be single
spaced
// print out some more things here
When y is below the bottom margin of the page set HasMorePages to true
and exit the routine. Keep track of data locations either in class
variables of the subclass (as I do) or in some external way.
Ron Allen
"Johan DM" <JohanDM@discussions.microsoft.com> wrote in message
news:21482647-DAC5-4F53-ABBF-34BE339A6FF8@microsoft.com...
> Thanks for the reply Ron.
> But i'm kind of a newbie in programming VB.Net, do you happen to know if i
> could find a working sample on the net? Cause i've searched online but
> nothing came up.
>
> Printing the PDF File wouldn't be a problem as i use Adobe Acrobat to
> create
> the files, its rather the drawing of the data at the correct location. But
> if
> this could also be automated so that i wouldn't have to check the settings
> and type the filename that would be really great.
> I suppose these toolkits aren't for free, in that case this will not be a
> possibility here, because i work with a non-profit organisation.
>
> If I could have a working sample it would be outstanding.
>
> PS: i use Visual Studio.Net 2003
>
>
> "Ron Allen" wrote:
>
>> Johan,
>> Printing graphics and formatted text fields isn't a problem. I have
>> several programs that do this. To print a PDF you can either get one of
>> the
>> ..NET toolkits that support PDF generation and make your own or (as we
>> do)
>> get a PDF printer output driver that prints your document to a PDF file.
>> We
>> use activePDF composer to do the PDF output. For the formatted output I
>> just draw the desired item at the location required on the page using a
>> PrintDocument subclass. For transmission between offices all of our
>> output
>> documents are stored in a set of defined XML formats and then printed
>> from
>> that.
>>
>> Ron Allen
>> "Johan DM" <JohanDM@discussions.microsoft.com> wrote in message
>> news:A59C31CC-6296-499D-B8DB-07170658658E@microsoft.com...
>> > I'm aware of the possibility to print plain text.
>> > But I'm wondering if it is possible to print more advanced documents.
>> >
>> > e.g. i want to let the user choose some topics and answer some
>> > questions
>> > that will be stored in variables.
>> > Afterwards these variables have to be printed (as pdf) including a
>> > company
>> > logo and some standard text according a fixed ordening.
>> >
>> > e.g.
>> > company logo
>> > Activity date: 8-11-2005
>> > Activity place: California
>> > etc
>> >
>> > Anyone knows if this is possible?
>>
>>
>>
- Next message: Ron Allen: "Re: Advanced printing"
- Previous message: Axel Dahmen: "VS8: Custom Controls - HTML IntelliSense without Schema?"
- In reply to: Johan DM: "Re: Advanced printing"
- Next in thread: Johan DM: "Re: Advanced printing"
- Reply: Johan DM: "Re: Advanced printing"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|