PrintForm Print to File
- Hello,
I have created a report on a form that looks exactlty like what I want printed in a single page. I am using VB 2005 Power Packs PrintForm and using PrintToPreview. I want to only print the client area. The preview shows the form running off of the right side of the paper. How can I shift the image so that the report is centered on an 8.5 x 11 portait page?
Thank you.
Answers
- Hi Dan,
The PrintForm component is designed to essentially print an image of what you see on screen, so you would need to adjust your form to fit the page size. If you need more control over the print output, you should use the PrintDocument component instead.
Hope this helps,
Steve Hoag Microsoft aka the V-Bee- Marked As Answer byJeff ShanMSFT, ModeratorWednesday, October 28, 2009 1:41 AM
- Hi Dan,
I think you can print your form using PrintDocument, here is a thread about this topic you can refer to
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/9ed0755f-b4ac-4850-8645-06e4a528e8ed/
Hope this helps
Regards
Jeff Shan
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer byJeff ShanMSFT, ModeratorWednesday, October 28, 2009 1:41 AM
All Replies
- Hi Dan,
The PrintForm component is designed to essentially print an image of what you see on screen, so you would need to adjust your form to fit the page size. If you need more control over the print output, you should use the PrintDocument component instead.
Hope this helps,
Steve Hoag Microsoft aka the V-Bee- Marked As Answer byJeff ShanMSFT, ModeratorWednesday, October 28, 2009 1:41 AM
- Hi Steve,
I have modified the form so that all of the information on it it appears in the PrinToPreview window and it prints properly to the system printer. Howevere, I want to use PrintToFile and, when I do that, I get an error message in debug. Can you tell me what code to add to corrrect this?
This is my code:
314 Me.PrintForm1.PrintAction = Printing.PrintAction.PrintToFile
315 Me.PrintForm1.Print(PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)
This is the error at line 315:
ArgumentNullException was unhandled
Path caqnot be null.
Parameter name: path
Note: I am not ignoring your comment about using the PrintDocument component. I just don't know how to do it. This report is that I am printing looks exactly like a form in a building code with blanks to be filled in. My program draws the form using the PowerPacks line component and fills in the blanks. It is very complicated engineering calculations and I need it to looklike the form in the book. Can the PrintDocument component be used to print the Windos Form that I have created using the PowerPacks line component and does MSDN have a video tutorial on it?
Thank you for your assistance,
Dan - Hi Dan,
When printing to a file, you need to specify a PrintFileName property with the path where you want the file to be created - see http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.printing.printform.printfilename.aspx
Is there a reason that you are printing to a file instead of directly to the printer? The PrintToFile method outputs a Postscript (.eps) file - is that what you want?
Hope this helps,
Steve Hoag Microsoft aka the V-Bee - Hi Steve,
When I try PrintToFile in debug, a window appears (Title "Print") the gives the option of selecting the system default printer, Adobe PDF, Fax or MS XPS Document Writer. Doing this would allow the user to print to a selected device at run time. So, printing to the default printer would get a hard copy, while printing to pdf would get a file that could be saved and printed later. This is very desirable. It looks to me that PrintToPreview will only print to the default printer and, if that is the case, the only way to print a pdf would be to change the default printer before running the program.
Is there a way to allow the user to select the printer at run time when using PrintToPreview?
I could send you a screen shot of the above described "Print" window but I don't know how to attach it to this reply. The screen shot would also include my form, which would give you a better sense of why I am trying to do it this way.
Let me know how and I will send the screen shot.
Thank you,
Dan - Hi Steve,
I probably should have asked this question directly. Is it possible to use the PrintDocument component to print my form or would my form have to be completely redrawn somewhere else to then use the PrintDocument component?
Thank you,
Dan - Hi Dan,
I think you can print your form using PrintDocument, here is a thread about this topic you can refer to
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/9ed0755f-b4ac-4850-8645-06e4a528e8ed/
Hope this helps
Regards
Jeff Shan
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer byJeff ShanMSFT, ModeratorWednesday, October 28, 2009 1:41 AM
- Hi Jeff,
I want to try the PrintDocument solution on the thread that you suggested but I have never used PrintDocument before and could use some fairly explicit advice on it.
1. Do I drop a PrintDocument control on the form and change any of its properties?
2. Do I need to drop any other controls on the form to do this (like Print Dialog, PrintPreviewDialog, PrintPreviewControl, etc.) and change any properties for them?
3. Do the Part 2 and Part 3 Private Subs go under the PrintButton Private Sub?
Thank you for the help,
Dan - Hi Dan,
For first and second question, no, you needn't. Just put the code to a blank project, add a button to it, and then, it will work.
As to the third question, yes, part 2 captures current form as an image and part 3 handles PrintPage event. If you click the print icon on the print preview interface, it will call this part to print the captured image.
Additionally, you can look into the following link for more information.http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx
Hope this helps
Regards
Jeff Shan
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


