Print Page | Close Window

Exporting / Printing selected layer of pdf file

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=2461
Printed Date: 17 Jun 25 at 10:16AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Exporting / Printing selected layer of pdf file
Posted By: MartinCS
Subject: Exporting / Printing selected layer of pdf file
Date Posted: 27 Nov 12 at 10:07AM
Hi,

is there a possibility to select a certain layer of a pdf file and export / print it with the original page size of the pdf file container programmatically? With other words, I do have a file which contains several layers. I would like to hide all layers except one specific layer and print it using a pdf printer driver.

Thank you for your support!


Cheers,
Martin



Replies:
Posted By: Ingo
Date Posted: 27 Nov 12 at 7:51PM
Hi Martin!

I would first make a copy of the original pdf to have a working file.
On this file i would delete all layers i don't want and then print out
the working file with one remaining layer.
QuickPDF supports this:
http://www.quickpdflibrary.com/help/quickpdf/LayersAndOptionalContentGroups.php
Have a look at DeleteLayer and LayerCount.
Additionally you should read all about contentstreams...

Cheers and welcome here,
Ingo



Posted By: AndrewC
Date Posted: 28 Nov 12 at 3:19AM
Martin,

Layers are called OptionalContentGroup's (OCG's) in technical speak.  Quick PDF library has full support for  OCG's including functions.  Here is some code I just found showing how the functions are used.  (I am not sure what the function does though)

http://www.quickpdflibrary.com/help/quickpdf/OptionalContentGroupCount.php - http://www.quickpdflibrary.com/help/quickpdf/OptionalContentGroupCount.php
http://www.quickpdflibrary.com/help/quickpdf/GetOptionalContentGroupID.php - http://www.quickpdflibrary.com/help/quickpdf/GetOptionalContentGroupID.php
http://www.quickpdflibrary.com/help/quickpdf/SetOptionalContentGroupPrintable.php - http://www.quickpdflibrary.com/help/quickpdf/SetOptionalContentGroupPrintable.php
http://www.quickpdflibrary.com/help/quickpdf/GetOptionalContentGroupName.php - http://www.quickpdflibrary.com/help/quickpdf/GetOptionalContentGroupName.php


            int ret = QP.LoadFromFile("pdf_with_ocgs.pdf", "");

            int numberOfLayer = QP.OptionalContentGroupCount();

            int[] layerID = new int[numberOfLayer];
            string[] layerName = new string[numberOfLayer];

            string layerNameStr;

            for(int iLayer=0; iLayer < numberOfLayer; iLayer++)
            {
                layerID[iLayer] = QP.GetOptionalContentGroupID(1 + iLayer);
                layerName[iLayer] = QP.GetOptionalContentGroupName(layerID[iLayer]);
            }

            for (int iLayer = 0; iLayer < numberOfLayer; iLayer++)
            {
                //activating and deactivating the layers,
                // in order to have only a single one that is activated
                for (int iLayerTemp = 0; iLayerTemp < numberOfLayer; iLayerTemp++)
                {
                    QP.SetOptionalContentGroupVisible(layerID[iLayerTemp], iLayer == iLayerTemp ? 1 : 0);
                    QP.SetOptionalContentGroupPrintable(layerID[iLayerTemp], iLayer == iLayerTemp ? 1 : 0);
                }
                QP.UseUnsafeContentStreams(1);

                ret = QP.RenderPageToFile(100, 1, 7, "out" + iLayer.ToString() + ".tif");
                if (ret != 1)
                    MessageBox.Show("Render failed");
            }




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