MyersA
asked on
Printing a paper form (in BMP) from windows application. The Windows application plugs in values...
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 from what I understand, that'll only print the document. I still need to insert some values at run-time before printing it.
Any suggestions are appreciated.
Thanks.
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 from what I understand, that'll only print the document. I still need to insert some values at run-time before printing it.
Any suggestions are appreciated.
Thanks.
ASKER
Thanks for the info.
It didn't work quite as expected. First, it prints out the Windows taskbar. Also, Form class limits the size of the form so it's not larger than the screen size, so I won't be ablt to create a form that's as big as the bmp I'll be importing. And I don't think I can plug in the values during runtime.
It didn't work quite as expected. First, it prints out the Windows taskbar. Also, Form class limits the size of the form so it's not larger than the screen size, so I won't be ablt to create a form that's as big as the bmp I'll be importing. And I don't think I can plug in the values during runtime.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hope it Helps.
Good Luck
Example
[System.Runtime.InteropSer
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryI
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(
}
private void printDocument1_PrintPage(S
{
e.Graphics.DrawImage(memor
}
private void printButton_Click(System.O
{
CaptureScreen();
printDocument1.Print();
}
Compiling the Code
This example requires:
A PrintDocument component named printDocument1 with a PrintPage event handler.
A Button named printButton with a Click event handler.
The example code replaces the existing event handlers. The form is printed when printButton is clicked.
Robust Programming
The following conditions may cause an exception:
You do not have permission to access the printer.
You do not have permission to use unmanaged code.
There is no printer installed.
Security
In order to run this example, you must have permission to execute unmanaged code and to access the printer.