C # Add a Print button to a PDF page

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.