Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / January 2005

Tip: Looking for answers? Try searching our database.

Advanced printing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johan DM - 29 Jan 2005 00:43 GMT
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?
Ron Allen - 29 Jan 2005 16:51 GMT
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
> I'm aware of the possibility to print plain text.
> But I'm wondering if it is possible to print more advanced documents.
[quoted text clipped - 11 lines]
>
> Anyone knows if this is possible?
Johan DM - 29 Jan 2005 23:09 GMT
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

> Johan,
>     Printing graphics and formatted text fields isn't a problem.  I have
[quoted text clipped - 23 lines]
> >
> > Anyone knows if this is possible?
Ron Allen - 30 Jan 2005 17:12 GMT
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

> Thanks for the reply Ron.
> But i'm kind of a newbie in programming VB.Net, do you happen to know if i
[quoted text clipped - 48 lines]
>> >
>> > Anyone knows if this is possible?
Johan DM - 30 Jan 2005 19:33 GMT
Thanks for the great information Ron.
This should really get me started.

Sincerely Johan DM

> Johan,
>     I don't know of simple samples available on the net and company rule
[quoted text clipped - 99 lines]
> >> >
> >> > Anyone knows if this is possible?
Ron Allen - 30 Jan 2005 17:17 GMT
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
> Thanks for the reply Ron.
> But i'm kind of a newbie in programming VB.Net, do you happen to know if i
[quoted text clipped - 48 lines]
>> >
>> > Anyone knows if this is possible?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.