Printing a paper form (in BMP) from windows application

V

VMI

I have a BMP image (the form is also in PDF) that contains a scanned copy of
a paper form that we need to fill out. Is it possible to use this image in
my application so that the application can print out the form and the data
that the user entered? For example, the user loads the application and a
normal Windows Form asks for the user's name. When the user enters the name
and clicks on the "Print" button, I'd like to print the form in the jpg
image and include the person's name in that form (in the appropriate
position).
I wanted to use a Windows Form (whose background would be the image), add a
textbox, and then print the Windows Form (with the txtbox that includes the
user's name), but the Windows Form's size is limited to the screen
resolution.
Someone suggested using PrintDocument but I'm not sure if it'll be able to
accomplish this.
Any suggestions are appreciated.
Thanks.
BTW, the PDF that contains the form is editable through Acrobat Reader (I
can type into it and print). Maybe that'll help me.
 
R

Ron Allen

VMI,
You can use PrintDocument and just print the bitmap at the appropriate
location on the form. Make sure to adjust for the printer's dpi settings
though or you will get stretching/shrinking effects on the background. You
can use DpiX and DpiY properties of the Graphics from the PrintPageEventArgs
argument to OnPrintPage to get the resolutions.

Ron Allen
 
V

VMI

The bitmap I'll be printing is an 8.5"X11" form. I don't really need to
display it in the Win Form; I just need to print it with the user
information. So I'm not really sure what you mean by that. Do you know of
any examples on the Web?

Thanks.
 
R

Ron Allen

VMI,
Sorry I meant page where I said form. I don't know of any examples
offhand on the web but I haven't had any problems printing bitmaps on a page
using PrintDocument.
For example the following puts a logo on the page if the logo file
exists on the disk and then sets the x location to just past the right hand
side of the logo.
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Xml;
if (System.IO.File.Exists(logoName)) // either specified or stock.
{
Image img = Image.FromFile(logoName);
e.Graphics.DrawImage(img, new PointF(98.0f, 56.5f));
xloc = 1.0f + (img.Width/img.HorizontalResolution) + 0.05f;
}
This puts it at the top left of the page for this form. In your case I
guess that you would just draw the whole thing at 0,0 but be aware that
things outside the printer's hard margins won't be shown.

Ron Allen
 
V

VMI

Thanks. I works but I don't know how to insert the values into the image.
The values come from the application. Is that possible?
 
R

Ron Allen

VMI,
Just draw them at the appropriate location on the page. I use
XmlDocument items to pass my data around. Just put them into an appropriate
XML structure and when you print the page just grab them out of the
structure with SelectSingleNode. Draw them at the appropriate location
using DrawString and the font desired.
You may want to get a copy of Programming Windows in C#/VB.NET by
Petzold as he discusses basic printing there. Or look at some of the
printing examples at www.gotdotnet.com or www.codeproject.com.

Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top