The Print and DocPrint methods can be used to print a PDF document to a hardware printer. It is also used to print multiple pages on a single sheet of paper.
System.Boolean Print(System.String PrinterName, System.Int32 StartPage, System.Int32 EndPage, System.Int32 Copies)
int DocPrint(EXTDOCHANDLE edhDocument, LPCSTR szPrinterName, long lStartPage, long lEndPage, long lCopies)
PrinterName, szPrinterName
Name of printer as it shows in the printers control panel. If this parameter is left empty, the document will print to the default printer.
StartPage, lStartPage
Page number from which to start printing. The index of the first page is 1.
EndPage, lEndPage
Page number at which to stop printing.
Copies, lCopies
Number of copies to print the document.
The Copies parameter is split into 2 parts:
Example 1:
To print 2x2 pages per sheet in 3 copies, we would use:
long copies =((2 << 8)+ 2)<< 16 + 3document.Print("", 1, document.PageCount, copies)
Example 2:
To print 1 page per sheet in 2 copies, we would use:
long copies = 2;document.Print("", 1, document.PageCount, copies)
edhDocument
Handle Returned by DocOpen.
The return value is True if the Print method succeed. Otherwise, False If the Print method fails.
The return value is zero if the DocPrint method succeed. If the DocPrint method fails, a negative value will returned, ex:
E_ACCESSDENIED Document security doesn't allow printing
E_FAIL Invalid destination printer
The security setting on a PDF file might disable printing, in this case the file should be opened with the owner password in order to print it.
The evaluation license will print only one page of the document.
Member of CDIntfEx.Document.
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