RasterizePageRange Method

The RasterizePageRange method converts page contents into a color or grey scale image. When archiving documents or performing OCR, it is sometimes preferable for all pages to be stored as images rather than complex text and graphic operations.

 

Syntax

VB:

Sub RasterizePageRange(StartPage As Integer, EndPage As Integer, Resolution As Integer, ColorOption As ACPDFCREACTIVEX.acRasterizeColorOption, ACPDFCREACTIVEX.Compression As acImageCompressionConstants)

C#:

void RasterizePageRange(System.Int32 startPage, System.Int32 EndPage, System.Int32 Resolution, ACPDFCREACTIVEX.acRasterizeColorOption ColorOption, ACPDFCREACTIVEX.acImageCompressionConstants compression)

C++:

HRESULT RasterizePageRange(long StartPage, long EndPage, long Resolution, acRasterizeColorOption ColorOption, acImageCompressionConstants compression)

 

Parameters

StartPage, EndPage

Start and end page numbers to Rasterize. Page numbers start with page 1.

Resolution

Resolution in dots per inch (DPI) at which the documents are to be rasterized.  A DPI of 150 is recommended in most situations.  Higher resolutions will produce very large PDF files

ColorOption

Option

Value

Description

acColorOptionBW

1

Black and White images.

acColorOptionGray

2

256 Grey level images.

acColorOptionRGB

3

RGB color images.

compression

Option

Value

Description

acCompression256Colors

1

256 Color level images.

acCompressionJPegLow

2

Low quality JPeg Compression.

acCompressionJPegMedium

7

Medium quality JPeg Compression.

acCompressionJPegHigh

9

High quality JPeg Compression.

acCompressionCCITTFax

10

CCITT Level 6 Black and White Compression.

acCompressionPNG

11

PNG (Flate) Compression.

acCompressionJPG2000

12

JPeg 2000 Compression.

acCompressionJBIG2

13

JBIG2 Compression.

Color

RGB color used to draw the page numbers.

StartWithPage

Page number where to start adding page numbers. If this value is positive, page numbers will start with 1. If this value is negative, page numbers will start with the actual page number.

Format

This specifies the formatting for the page numbers. Two formatting keywords are currently supported: #page and #pages. All other keywords are output as is.

 

Remarks

This method launches an exception when an error occurs. Exceptions should be handled properly by the calling application.

 

Example

Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF OCR Module Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010093D94E09B8D9E1238F7DF9E1C5978D7D37AF93D9345B1D74DDC2D9DA41BB345E54160991EA7537246947E74D57A4"

 

    ' Initializing PDFCreativeX Object

    Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX = New ACPDFCREACTIVEX.PDFCreactiveX()

 

    ' Set license key

    pdf.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Open an existent PDF filw

    Dim fileName As String = "c:\temp\PDFdocument.pdf"

    Dim password As String = ""

    pdf.Open(fileName, password)

 

    ' Rasterize Pages

    Dim startPage As Integer = 1

    Dim endPage As Integer = pdf.PageCount

    Dim resolution As Integer = 120

    Dim colorOption As ACPDFCREACTIVEX.acRasterizeColorOption = ACPDFCREACTIVEX.acRasterizeColorOption.acColorOptionBW

    Dim compression As ACPDFCREACTIVEX.acImageCompressionConstants = ACPDFCREACTIVEX.acImageCompressionConstants.acCompression256Colors

    pdf.RasterizePageRange(startPage, endPage, resolution, colorOption, compression)

 

    ' Save PDF

    pdf.Save("c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView)

 

    ' destroy objects

    pdf = Nothing

End Sub

static void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF OCR Module Evaluation";

    const string strActivationCode = "07EFCDAB0100010093D94E09B8D9E1238F7DF9E1C5978D7D37AF93D9345B1D74DDC2D9DA41BB345E54160991EA7537246947E74D57A4";

 

    // Initializing PDFCreativeX Object

    ACPDFCREACTIVEX.PDFCreactiveX pdf = new ACPDFCREACTIVEX.PDFCreactiveX();

 

    // Set license key

    pdf.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Open an existent PDF file

    string fileName = @"c:\temp\PDFdocument.pdf";

    string password = "";

    pdf.Open(fileName, password);

 

    // Rasterize Pages

    int startPage = 1;

    int endPage = pdf.PageCount;

    int resolution = 120;

    ACPDFCREACTIVEX.acRasterizeColorOption colorOption = ACPDFCREACTIVEX.acRasterizeColorOption.acColorOptionBW;

    ACPDFCREACTIVEX.acImageCompressionConstants compression = ACPDFCREACTIVEX.acImageCompressionConstants.acCompression256Colors;

    pdf.RasterizePageRange(startPage, endPage, resolution, colorOption, compression);

 

    // Save PDF

    pdf.Save(@"c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView);

 

    // destroy objects

    pdf = null;

}

#include <iostream>

#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace

 

using namespace std;

 

int main()

{

    // Constants for Activation codes

    bstr_t strLicenseTo = "Amyuni PDF OCR Module Evaluation";

    bstr_t strActivationCode = "07EFCDAB0100010093D94E09B8D9E1238F7DF9E1C5978D7D37AF93D9345B1D74DDC2D9DA41BB345E54160991EA7537246947E74D57A4";

 

    // Initialize the COM subsystem

    CoInitialize(0);

 

    // IPDFCreactiveXPtr is a smart pointer type defined in pdfcreactivex.tlh,

    // the type library header file generated by the #import instruction above

    IPDFCreactiveXPtr pdf;

 

    // Create the PDFCreactiveX instance

    pdf.CreateInstance(__uuidof(PDFCreactiveX));

 

    // set license key

    pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));

 

    // Open an existent PDF file

    bstr_t fileName = "c:\\temp\\PDFdocument.pdf";

    bstr_t password = "";

    pdf->Open(fileName, password);

 

    // Rasterize Pages

    int startPage = 1;

    int endPage = pdf->PageCount;

    int resolution = 120;

    acRasterizeColorOption colorOption = acColorOptionBW;

    acImageCompressionConstants compression = acCompression256Colors;

    pdf->RasterizePageRange(startPage, endPage, resolution, colorOption, compression);

 

    // Save PDF

    pdf->Save("c:\\temp\\CreatePDFDocument_resulting.pdf", acFileSaveView);

 

    // destroy objects

    pdf = NULL;

 

    return 0;

}

' acImageCompressionConstants

Const acCompression256Colors = 1

Const acCompression256ColorsWithPredictor = 257

Const acCompressionCCITTFax = 10

Const acCompressionDefault = 0

Const acCompressionJBIG2 = 13

Const acCompressionJBIG2Huffman = 14

Const acCompressionJPegHigh = 9

Const acCompressionJPegLow = 2

Const acCompressionJPegMedium = 7

Const acCompressionJPG2000 = 12

Const acCompressionPNG = 11

 

' acRasterizeColorOption

Const acColorOptionBW = 1

Const acColorOptionGray = 2

Const acColorOptionRGB = 3

 

' FileSaveOptionConstants

Const acFileSaveAll = 0

Const acFileSaveDefault = -1

Const acFileSaveView = 1

Const acFileSaveDesign = 2

Const acFileSavePDFA_7 = 3

Const acFileSavePDFA = 4

Const acFileSavePDF14 = 5

 

' Constants for Activation codes

Const strLicenseTo = "Amyuni PDF OCR Module Evaluation"

Const strActivationCode = "07EFCDAB0100010093D94E09B8D9E1238F7DF9E1C5978D7D37AF93D9345B1D74DDC2D9DA41BB345E54160991EA7537246947E74D57A4"

 

' Initializing PDFCreativeX Object

Dim pdf

Set pdf = CreateObject("PDFCreactiveX.PDFCreactiveX.6.5")

 

' Set license key

pdf.SetLicenseKey strLicenseTo, strActivationCode

 

' Open an existent PDF file

Dim fileName

fileName = "c:\temp\PDFdocument.pdf"

Dim password

password = ""

pdf.Open fileName, password

 

' Rasterize Pages

Dim startPage

startPage = 1

Dim endPage

endPage = pdf.PageCount

Dim resolution

resolution = 120

Dim colorOption

colorOption = acColorOptionBW

Dim compression

compression = acCompression256Colors

pdf.RasterizePageRange startPage, endPage, resolution, colorOption, compression

 

' Save PDF

pdf.Save "c:\temp\CreatePDFDocument_resulting.pdf", acFileSaveView

 

' destroy objects

Set pdf = Nothing

 

Important Note

All the samples that are provided in this documentation assume that the developer is using the ActiveX version (PDFCreactiveX.dll.)

 

When using the .NET version (acPDFCreatorLib.Net.Dll), the functions are very similar although the code slightly different. Rather than duplicating all the documentation and sample code, we have chosen to provide a complete .NET sample at the end of this documentation.