问题
I have been assigned the task to develop a software for generating bills. I have created the database, i have created the front end in VB.NET, but, the main problem is printing the data displayed on the form. The form contains some labels, the VAT, the sub total and the total billed amount. It also displays the list of items in a DataGridView. How can I generate a pdf and print the form as a bill for the customer(without including the buttons)?
I am attaching an image to give you an idea about how the form looks like:
回答1:
Use the PrintForm component.
To print a form to the default printer
- In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
- The PrintForm component is added to the component tray.
- In the Properties window, set the PrintAction property to PrintToPrinter.
- Add the following code in the appropriate event handler (for example, in the Click event handler for a Print Button).
From http://msdn.microsoft.com/en-us/library/bb629268.aspx
If you want to remove the buttons first :
myButton.Visible = False
Then proceed to print the form.
回答2:
The task you describe, is usually done through a reporting framework like CrystalReports, DevExpress Reporting Components or List&Label. These are very powerful commercial products and quite expensive, but they give you great flexibility and save you much work. If you don't want to spend money you should search the internet for a free reporting framework for .Net. One of the advantages of reporting frameworks is that you can change the output without recompiling your application. Furthermore they support many different output formats.
来源:https://stackoverflow.com/questions/24700088/how-do-i-generate-a-pdf-document-from-vb-net-ready-for-printing