C # PDF Page action--Set Page toggle button

Source: Internet
Author: User
Tags border color

Overview

In the following example, the method of setting the page toggle button on a PDF document page is described. In the example, the addition of the page toggle button is divided into two cases, one is the settings button to jump to the first page, the next page, the previous page or the last, and the other is the set button to jump to the specified page. The two methods adapt to different programming needs, and can choose the appropriate method of adding.

Description

The code example here needs to use the class library spire.pdf for. NET, version 4.0. When using this class library, you can refer to Spire.Pdf.dll in the project program (DLL files are obtained in the bin file under the installation path).
Such as:

Code operation example (for reference) 1. Jump to a specific page (first, Next, Prev, last)

"C #"

Using spire.pdf;using spire.pdf.actions;using spire.pdf.fields;using spire.pdf.graphics;using System.Drawing; Namespace buttontoappointedpage_pdf{class Program {static void Main (string[] args) {//instance            Pdfdocument class, load PDF Test F document Pdfdocument doc = new pdfdocument (); Doc.            LoadFromFile ("Sample.pdf"); Allow Add Form Doc.            Allowcreateform = true; Get the last page of the document Pdfpagebase LastPage = doc. Pages[doc.            PAGES.COUNT-1];            Adds a button of the specified size at the specified location in the page Pdfbuttonfield button = new Pdfbuttonfield (LastPage, "Click to Back"); button.            Bounds = new RectangleF (lastpage.actualsize.width-150, lastpage.actualsize.height-400, 60, 20); Set button border Color button.            BorderStyle = Pdfborderstyle.solid; button.            BorderColor = new Pdfrgbcolor (color.white); Sets the button background color.            BackColor = color.azure; Sets the button prompt. ToolTip = "to the first PAge ";            Set the button text font and color Pdftruetypefont truetypefont = new Pdftruetypefont (New Font ("Avant garde", 9f), true); button.            Font = Truetypefont; button.            ForeColor = Color.Black; Create a Pdfnamedaction instance, select Previous, Next, first, or last page in incoming parameters pdfnamedaction namedaction = new Pdfnamedaction (pdfactiondestinat Ion.            FirstPage); Apply the action button.            Actions.mousedown = namedaction; Add a button to document Doc.            FORM.FIELDS.ADD (button); Save and open the PDF document Doc.            SaveToFile ("Result.pdf", fileformat.pdf);        System.Diagnostics.Process.Start ("Result.pdf"); }    }}

"VB.net"

Imports spire.pdfimports Spire.Pdf.ActionsImports Spire.Pdf.FieldsImports Spire.Pdf.GraphicsImports            System.drawingnamespace buttontoappointedpage_pdf Class program Private Shared Sub Main (ByVal args as String ()) Dim doc as Pdfdocument = New pdfdocument () Doc. LoadFromFile ("Sample.pdf") Doc. Allowcreateform = True Dim lastpage as Pdfpagebase = Doc. Pages (Doc. pages.count-1) Dim button as Pdfbuttonfield = New Pdfbuttonfield (lastpage, "Click to Back") Butto N.bounds = New RectangleF (lastpage.actualsize.width-150, lastpage.actualsize.height-400, max) button. BorderStyle = Pdfborderstyle.solid button. BorderColor = New pdfrgbcolor (color.white) button. BackColor = Color.azure button.  ToolTip = "To the first page" Dim truetypefont as Pdftruetypefont = new Pdftruetypefont (New Font ("Avant Garde", 9F), True) button. Font = Truetypefont button. FoRecolor = Color.Black Dim namedaction as Pdfnamedaction = New pdfnamedaction (pdfactiondestination.firstpage) button. Actions.mousedown = Namedaction Doc. FORM.FIELDS.ADD (Button) doc. SaveToFile ("Result.pdf", Fileformat.pdf) System.Diagnostics.Process.Start ("Result.pdf") End Sub End C Lassend Namespace

PS: Here the Pdfnameaction class supports four kinds of button jump action

Add effect ():

When you click the button in the text, you can jump to the page that the button points to.

2. Jump to the specified page

"C #"

Using spire.pdf;using spire.pdf.actions;using spire.pdf.fields;using spire.pdf.general;using Spire.Pdf.Graphics; Using System.drawing;namespace buttom2{class Program {static void Main (string[] args) {/            /Instantiate Pdfdocument class, load PDF document Pdfdocument doc = new pdfdocument (); Doc.            LoadFromFile ("Sample.pdf"); Allow Add Form Doc.            Allowcreateform = true; Get last page Pdfpagebase LastPage = doc. Pages[doc.            PAGES.COUNT-1];            Add a button to the page at the specified location Pdfbuttonfield buttons = new Pdfbuttonfield (LastPage, "back"); button.            Bounds = new RectangleF (lastpage.actualsize.width-150, lastpage.actualsize.height-700, 50, 20); Set button border Color button.            BorderStyle = Pdfborderstyle.solid; button.            BorderColor = new Pdfrgbcolor (color.transparent); Sets the button background color.            BackColor = Color.whitesmoke; Sets the button prompt. ToolTip = "Click and back to The third page ";            Set the button text font and color Pdftruetypefont truetypefont = new Pdftruetypefont (New Font ("Avant garde", 9f), true); button.            Font = Truetypefont; button.            ForeColor = Color.Black; Instantiates the Pdfdestination object, passing in the specified page number to page 3rd pdfdestination destination = new Pdfdestination (Doc.            PAGES[2]);            Create go to action pdfgotoaction gotoaction = new Pdfgotoaction (destination); Apply the action button.            Actions.mousedown = gotoaction; Add a button to document Doc.            FORM.FIELDS.ADD (button); Save and open the PDF document Doc.            SaveToFile ("Result.pdf", fileformat.pdf);        System.Diagnostics.Process.Start ("Result.pdf"); }    }}

"VB.net"

Imports spire.pdfimports Spire.Pdf.ActionsImports Spire.Pdf.FieldsImports Spire.Pdf.GeneralImports Spire.Pdf.GraphicsImports system.drawingnamespace Buttom2 Class program Private Shared Sub Main (ByVal args as St Ring ()) Dim doc as Pdfdocument = New pdfdocument () Doc. LoadFromFile ("Sample.pdf") Doc. Allowcreateform = True Dim lastpage as Pdfpagebase = Doc. Pages (Doc. pages.count-1) Dim button as Pdfbuttonfield = New Pdfbuttonfield (lastpage, "back") button. Bounds = New RectangleF (lastpage.actualsize.width-150, lastpage.actualsize.height-700,.) button. BorderStyle = Pdfborderstyle.solid button. BorderColor = New pdfrgbcolor (color.transparent) button. BackColor = Color.whitesmoke button. ToolTip = "Click and back to the third page" Dim truetypefont as Pdftruetypefont = new Pdftruetypefont (New Font ("Avant Garde", 9F), True) button. Font = TruetypefoNT button. ForeColor = Color.Black Dim destination as Pdfdestination = New pdfdestination (Doc. Pages (2)) Dim gotoaction as Pdfgotoaction = New pdfgotoaction (destination) button. Actions.mousedown = Gotoaction Doc. FORM.FIELDS.ADD (Button) doc. SaveToFile ("Result.pdf", Fileformat.pdf) System.Diagnostics.Process.Start ("Result.pdf") End Sub End C Lassend Namespace

Add effect ():

Click the button to jump to the 3rd page of the specified document.

On the way to add a PDF page Jump button, this article to the introduction, I hope the code in the text can give you a certain reference value for developers.
If you want to reprint, please indicate the source.
Thanks for reading!

C # PDF Page action--Set Page toggle button

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.