Print Page | Close Window

Create button to print PDF page

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2587
Printed Date: 17 Jan 26 at 9:14PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Create button to print PDF page
Posted By: tado
Subject: Create button to print PDF page
Date Posted: 02 Apr 13 at 8:40PM
Hi,
I'm using QuickPDF version 8.13 with C# to print PDF file to printer. 
Is there any way to add the Print button to page 3 (for ex), and then when user open the PDF they can print out page 3 by clicking to that button.

Thanks
Tom



Replies:
Posted By: tado
Date Posted: 03 Apr 13 at 5:57PM
I've done, here is the code:

void AddPrintButton(QuickPDFAX0813.PDFLibrary qp, string buttonName, int pageNumber)
        {
            if (pageNumber > 0)
            {
                qp.SetOrigin(1);

                //set the page where the button appear
                qp.SelectPage(pageNumber);

                //get the size of the button
                var buttonWidth = qp.GetTextWidth(buttonName);
                var buttonLocation = (qp.PageWidth()) - (buttonWidth) - 30;

                var fieldIndex = qp.NewFormField(buttonName, 2);                
                qp.SetFormFieldPrintable(fieldIndex, 0);
                qp.SetFormFieldBounds(fieldIndex, buttonLocation, 70, buttonWidth, 20);
                qp.SetFormFieldFont(fieldIndex, qp.GetFormFontCount());
                qp.SetFormFieldTextSize(fieldIndex, 10);
                qp.SetFormFieldBorderColor(fieldIndex, 1, 0, 0);
                qp.SetFormFieldBorderStyle(fieldIndex, 1, 0, 0, 0);
                qp.SetFormFieldColor(fieldIndex, 1, 0, 0);
                qp.SetFormFieldCaption(fieldIndex, buttonName);
                qp.SetFormFieldValue(fieldIndex, "");
                qp.SetFormFieldHighlightMode(fieldIndex, 3);
                qp.FormFieldJavaScriptAction(fieldIndex, "U", "this.print({" +
                                                                            "bUI: false," +
                                                                            "bSilent: true," +
                                                                            "bShrinkToFit: true," +
                                                                            "nStart: " + (pageNumber - 1).ToString() + "," +
                                                                            "nEnd: " + (pageNumber - 1).ToString() + "});");    // have -1 because the Acrobat Javascript PDF start page from 0
            }            
        }


Posted By: Ingo
Date Posted: 03 Apr 13 at 8:41PM
Hi Tom!

Well done. It will help other users, too.
So i've put it in the samples section.
Thanks a lot to your contribution.

Cheers and welcome here,
Ingo




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk