Briefly
Setting the button in the document gives us a quick way to manipulate the document, which is simple and easy to use in programs that effectively improve customer satisfaction. In the previous article, you described how to set the Jump button for a page in a PDF document, including jumping to a specific page, including the first, next, previous, and last pages, as well as customizing the jump page. This article describes how to add a Print button to a PDF document page.
Using tools
- Spire.pdf for. NET version 4.0
Note: After installing the class library, be aware of adding reference Spire.Pdf.dll to the project program. DLL files can be obtained in the Bin folder under the installation path.
Code sample (for reference)
Step 1: Add a using directive
using Spire.Pdf;using Spire.Pdf.Fields;using Spire.Pdf.Graphics;using System.Drawing;
Step 2: Load the document to get the specified page
//加载PDF文档PdfDocument doc = new PdfDocument("test.pdf");doc.AllowCreateForm = true;//获取第一页PdfPageBase page = doc.Pages[0];
Step 3: Set the Print button and its properties
//在第一页创建一个PdfButtonField实例,并为按钮设置属性PdfButtonField button = new PdfButtonField(page, "Print");button.Bounds = new RectangleF(450, 600, 50, 20);button.BorderColor = new PdfRGBColor(Color.White);button.BorderStyle = PdfBorderStyle.Solid;button.ForeColor = new PdfRGBColor(Color.White);button.BackColor = new PdfRGBColor(Color.LightGray);button.ToolTip = "Print";button.Text = "Print";button.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
Step 4: Apply the button to the page
//添加打印功能到按钮button.AddPrintAction();//添加按钮到页面doc.Form.Fields.Add(button);
Step 5: Save the document
Doc. SaveToFile ("Output.pdf");
System.Diagnostics.Process.Start ("Output.pdf");
After the code is finished, debug the Run program and generate the document (as shown). The generated document, the mouse click the Print button, you can pop up the Print dialog box, in the dialog box to set the printing needs, click Print to complete the printing.
(End of this article)
If you want to reprint, please specify the source
C # Add a Print button to a PDF page