Print Page | Close Window

Optional Print Sections

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=1945
Printed Date: 16 Dec 25 at 9:15PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Optional Print Sections
Posted By: jt234
Subject: Optional Print Sections
Date Posted: 06 Sep 11 at 11:23PM
Hi,

I'm trying to add either a line or text (just an indicator, like an asterisk) to a PDF, but I'm trying to make them optionally printable (up to the user, armed only with the PDF file).  In Adobe Reader, when printing, the user has the option to print: Document, Document and Markup, Document and Stamps.  Are there any QuickPDF functions which I can use in the Markup or Stamps category that would fit this criteria?  I tried AddTextMarkupAnnotation, thinking 'Markup' might work, but it didn't work as expected.

Thanks!

-John



Replies:
Posted By: AndrewC
Date Posted: 07 Sep 11 at 1:09PM
You should try Optional Content Groups.  These are like layers and can be made Optional for printing and viewing.  The layers show up in the left hand side panel in Acrobat next to the Outlines/Bookmarks, Thumbnails and Signatures toolbar panel.

  GetOptionalContentGroupPrintable
  SetOptionalContentGroupPrintable
  GetOptionalContentGroupVisible
  SetOptionalContentGroupVisible

You can also make form field printing optional with

  GetFormFieldPrintable
  SetFormFieldPrintable


Here is some 7.26 code that shows creation of a document with Optional Content Groups

private void button7_Click(object sender, EventArgs e)
        {
            // Create three new optional content groups
            int CapturedPageID;
            double PageHeight;
            double PageWidth;
            int fileA, fileB;
            int OCG_Back = 0;
            int layer;

            // True = create a background OCG layer.  False = Create a fixed background.
            bool useBackgroundOCG = true;

            QP.NewDocument();
            QP.SetOrigin(1);

            // Save file to disk with new layers

            PageHeight = QP.PageHeight();
            PageWidth = QP.PageWidth();

            // QP.SaveToFile("layers.pdf");
            fileA = QP.SelectedDocument();

            // You can only use the DrawCapturedPage function if the captured page is in the same
            // document, so first we'll need to merge the two pages that we wish to overlay together
            // into one document.

            //QP.LoadFromFile("debenu final tm.pdf");
            QP.LoadFromFile("JavaScript.pdf");
            fileB = QP.SelectedDocument();

            // After merging FileB is automatically deleted, leaving only FileB which is now a combination of FileA and FileB
            QP.SelectDocument(fileA);
            QP.MergeDocument(fileB);
            QP.SaveToFile("combined.pdf");

            // Capture the second page in the merged document
            CapturedPageID = QP.CapturePage(2);

            QP.SelectDocument(fileA);
            QP.SelectPage(1);
            
            // Create a background OCG if useBackgroundOCG = true

            if (useBackgroundOCG)
                OCG_Back = QP.NewOptionalContentGroup("Background");

            QP.DrawText(100, 100, "Background");

            // Draw the captured page onto the currently selected OCG

            int ret = QP.DrawCapturedPage(CapturedPageID, 0, 0, PageWidth, PageHeight);

            if (useBackgroundOCG)
            {
                QP.SetLayerOptional(OCG_Back);
                QP.SetOptionalContentGroupVisible(OCG_Back, 1);
            }

            // Now add the two OCG's with some text.

            int OCG1 = QP.NewOptionalContentGroup("Layer 1");
            int OCG2 = QP.NewOptionalContentGroup("Layer 2");

            // Select the page that you want the layers to be associated with.

            QP.SelectPage(1);

            // Add OCG 1

            layer = QP.NewLayer();
            QP.SelectLayer(layer);
            QP.DrawText(180, 100, "Layer 1");
            QP.SetLayerOptional(OCG1);
            QP.SetOptionalContentGroupVisible(OCG1, 1);

            // Add OCG 2

            layer = QP.NewLayer();
            QP.SelectLayer(layer);
            QP.DrawText(260, 100, "Layer 2");
            QP.SetLayerOptional(OCG2);
            QP.SetOptionalContentGroupVisible(OCG2, 1);

            // Save the stitched file to disk
            QP.SaveToFile("ocg.pdf");
            System.Diagnostics.Process.Start(@"ocg.pdf");
        }




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