OpenForPrinting, DocOpenForPrinting

The OpenForPrinting and DocOpenForPrinting  methods optimize the processing of the PDF file for printing to a hardware printer. This is useful when printing very large files that would otherwise require too many resources such as system memory and GDI resources. Calling OpenForPrinting or DocOpenForPrinting is not recommended when using CDINTF to append, merge, encrypt or do other operations with PDF documents.

 

Syntax

ActiveX:

System.Boolean OpenForPrinting(System.String FileName, System.String Password, System.Int32 Options)

DLL:

int DocOpenForPrintingA(EXTDOCHANDLE * edhDocument, LPCSTR szFileName, LPBYTE szPassword, long Options)

 

Parameters

FileName

Full path of the PDF file to open.

Password, szPassword

Owner or user password associated with the document.

Options

[in ]Options to open the document.

Options

Description

Value

IMAGEGDIPLUS

Print as image using GDI+. The full page is converted to an image which is recommended when printing pages containing transparent items

1

USEPDFFONTS

By default, OpenForPrinting will use the system fonts to render text. If this flag is set, the fonts that are embedded in the PDF file will be used.

2

USEGDI

Print using GDI as opposed to the default GDI+, recommended when printing scanned documents.

4

USEDIRECTX

Print using DirectX (XPS print path).  

 

8

 

edhDocument

Hold a reference to the document handle when the call is done.

 

Return Value

The return value is True if the OpenForPrinting method succeed. Otherwise, False If the OpenForPrinting method fails.

The return value is zero if the DocOpenForPrinting method succeed. If the DocOpenForPrinting method fails, a negative value will returned.

 

Remarks

This method will fail if the document is encrypted and the password is invalid.

Some operations are restricted when the document is opened using the user password as opposed to the owner password.

 

Generally speaking in Windows we have two ways for applications to print. The GDI path (including GDI+) and the XPS path (DirectX).

With the GDI path, an application sends output to the printer more or less the same way it sends output to the screen when rendering with GDI.
Similarly, with the XPS path, an application sends output to the printer in the form of an XPS document.

A driver can declare that it accepts GDI operations (which Windows in fact converts from application level GDI output to printer level equivalent operations that more or less resemble the GDI operations) or it can accept XPS an input.

Member of CDIntfEx.Document.

Example

Public Enum PRINTOPTIONS As Integer

    IMAGEGDIPLUS = 1

    USEPDFFONTS = 2

    USEGDI = 4

    USEDIRECTX = 8

End Enum

 

Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

    ' Declare a new cdintfex document if it does not exist in the form.

    Dim pdfDoc As New CDIntfEx.Document

 

    ' The SetLicenseKey method should be called after creating an object of type 

    ' CDIntfEx.Document to activate the advanced methods that require the object 

    ' activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Open the document

    Dim password As String = ""

    pdfDoc.OpenForPrinting("c:\temp\test.pdf", password, PRINTOPTIONS.IMAGEGDIPLUS)

 

    ' Number of Pages

    Dim Pages As Integer = pdfDoc.PageCount()

 

    ' Print Document to the default Printer

    Dim copies As Long = 1

    pdfDoc.Print("", 1, Pages, copies)

End Sub

enum PRINTOPTIONS

{

    IMAGEGDIPLUS = 1,

    USEPDFFONTS = 2,

    USEGDI = 4,

    USEDIRECTX = 8,

}

static void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Converter Evaluation";

    const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

 

    // Declare a new cdintfex document if it does not exist in the form.

    CDIntfEx.Document pdfDoc = new CDIntfEx.Document();

 

    // The SetLicenseKey method should be called after creating an object of type 

    // CDIntfEx.Document to activate the advanced methods that require the object 

    // activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Open the document for printing

    string password = "";

    pdfDoc.OpenForPrinting("c:\temp\test.pdf", password, (int)PRINTOPTIONS.IMAGEGDIPLUS);

 

    // Number of Pages

    int Pages = pdfDoc.PageCount();

 

    // Print Document to the default Printer

    Int32 copies = 1;

    pdfDoc.Print("", 1, Pages, copies);

}

// PDF Converter Cpp.cpp : Defines the entry point for the console application.

// 

#include <Windows.h>

#include <string>

#include <iostream>

#include "CdIntf.h"

#pragma comment (lib, "CDIntf.lib")

 

using namespace std;

 

enum PRINTOPTIONS

{

    IMAGEGDIPLUS = 1,

    USEPDFFONTS = 2,

    USEGDI = 4,

    USEDIRECTX = 8,

};

 

int main()

{

    // Constants for Activation codes

#define strLicenseTo  "Amyuni PDF Converter Evaluation"

#define strActivationCode "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

    // Declare a new cdintfex document if it does not exist in the form.

    EXTDOCHANDLE pdfDoc;

 

    // The SetLicenseKey method should be called after creating an object of type 

    // CDIntfEx.Document to activate the advanced methods that require the object 

    // activation code to work properly

    SetLicenseKeyA(strLicenseTo, strActivationCode);

 

    // Open the document

    LPBYTE passWord = nullptr;

    DocOpenForPrintingA(&pdfDoc, "c:\\temp\\test.pdf", passWord, IMAGEGDIPLUS);

 

    // Print Document

    int Pages = 2;

    int copies = 1;

    DocPrintA(pdfDoc, "", 1, Pages, copies);

 

    // Destroy pdfDoc object

    DocClose(pdfDoc);

    pdfDoc = nullptr;

 

    return 0;

}

package Example;

 

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

import com.jacob.com.Variant;

 

public class OpenForPrinting {

    public enum PRINTOPTIONS 

    {

        IMAGEGDIPLUS(0x00000001),

        USEPDFFONTS(0x00000002),

        USEGDI(0x00000004),

        USEDIRECTX(0x00000004);

        private int value;

        private PRINTOPTIONS(int value)

        {

            this.value = value;

        }

        public Object value(){

            return value;

        }

    }

 

    public static void main(String[] args)

    {

        // Constants for Activation codes

        String strLicenseTo  = "Amyuni PDF Converter Evaluation";

        String strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

 

        // Declare a new cdintfex document if it does not exist in the form.

        ActiveXComponent pdfDoc = new ActiveXComponent("CDIntfEx.Document.6.5"); 

 

        // The SetLicenseKey method should be called after creating an object of type 

        // CDIntfEx.Document to activate the advanced methods that require the object 

        // activation code to work properly

        Dispatch.call(pdfDoc, "SetLicenseKey", strLicenseTo, strActivationCode);

 

        // Open the document for printing

        String password = "";       

        Dispatch.call(pdfDoc, "OpenForPrinting", "c:\\temp\\test.pdf", password, PRINTOPTIONS.IMAGEGDIPLUS.value);

 

        // Number of Pages

        Variant Pages = Dispatch.call(pdfDoc, "PageCount");

 

        // Print Message

        int copies = 1;

        Dispatch.call(pdfDoc, "Print", "", 1, Pages, copies);

 

        // Destroy pdfDoc object

        pdfDoc = null;

    }

}

$PRINTOPTIONS = @{

    IMAGEGDIPLUS = 1

    USEPDFFONTS = 2

    USEGDI = 4

    USEDIRECTX = 8

}

 

# Constants for Activation codes

$strLicenseTo  =  "Amyuni PDF Converter Evaluation"

$strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

#Declare a new cdintfex document if it does not exist in the form.

$pdfDoc = New-Object -ComObject CDIntfEx.Document.6.5

 

#The SetLicenseKey method should be called after creating an object of type 

#CDIntfEx.Document to activate the advanced methods that require the object 

#activation code to work properly

[System.__ComObject].InvokeMember('SetLicenseKey', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, @($strLicenseTo, $strActivationCode))

 

#Open the document

$password = ""

[System.__ComObject].InvokeMember('OpenForPrinting', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, 

    @("c:\temp\test.pdf", $password, $PRINTOPTIONS::IMAGEGDIPLUS))

 

#Optimize the document in Paragraph level

$PAGES = [System.__ComObject].InvokeMember('PageCount', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, $null)

 

#Print Document

$COPIES = 1

[System.__ComObject].InvokeMember('Print', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, 

    @("", 1, $PAGES, $COPIES))

 

#Destroy pdfDoc object

$pdfDoc = $null 

Const PRINTOPTIONS_IMAGEGDIPLUS = 1

Const PRINTOPTIONS_USEPDFFONTS = 2

Const PRINTOPTIONS_USEGDI = 4

Const PRINTOPTIONS_USEDIRECTX = 8

 

' Constants for Activation codes

Const strLicenseTo = "Amyuni PDF Converter Evaluation"

Const strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

' Declare a new cdintfex document if it does not exist in the form.

Dim pdfDoc 

Set pdfDoc = CreateObject("CDIntfEx.Document.6.5")

 

' The SetLicenseKey method should be called after creating an object of type 

' CDIntfEx.Document to activate the advanced methods that require the object 

' activation code to work properly

pdfDoc.SetLicenseKey strLicenseTo, strActivationCode

 

' Open the document

Dim password

password = ""

pdfDoc.OpenForPrinting "c:\temp\test.pdf", password, PRINTOPTIONS_IMAGEGDIPLUS

 

' Number of Pages

Dim pages

pages = pdfDoc.PageCount

 

' Print Document to the default printer

Dim copies

copies = 1

pdfDoc.Print "", 1, pages, copies

 

' Destroy pdfDoc object

Set pdfDoc = Nothing