all groups > visual studio .net general > january 2005 >
You're in the

visual studio .net general

group:

Advanced printing


Advanced printing Johan DM
1/28/2005 4:43:02 PM
visual studio .net general:
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

Re: Advanced printing Ron Allen
1/29/2005 11:51:14 AM
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
[quoted text, click to view]

Re: Advanced printing Johan DM
1/29/2005 3:09:01 PM
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


[quoted text, click to view]
Re: Advanced printing Johan DM
1/30/2005 11:33:01 AM
Thanks for the great information Ron.
This should really get me started.

Sincerely Johan DM

[quoted text, click to view]
Re: Advanced printing Ron Allen
1/30/2005 12:12:12 PM
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

[quoted text, click to view]

Re: Advanced printing Ron Allen
1/30/2005 12:17:02 PM
Johan,
Also you need to compensate for the physical margins of the printer
used. Search for GetHardMargins in
microsoft.public.dotnet.framework.drawing or microsoft.dotnet.languages.vb
for some code to do this. If you can't find this I can send a C# module
that does this.
Ron Allen
[quoted text, click to view]

AddThis Social Bookmark Button