pdfPrint / pdfPrintW - PRINT PDF function

<< Click to Display Table of Contents >>

Navigation:  Direct Calls to DLL >

pdfPrint / pdfPrintW - PRINT PDF function

 

pdfPrint(

 char *filename, 

 char *password:

 char *licname, 

 char *lickey,

 unsigned long liccode,

 char *options);

 

 

If you need to print from any application you can use some simple code which imports the pdfPrint function directly. You do not need to create any control or any form for it. Simply import this function from the DLL. This works in VB, in Delphi, in .NET. (Please see the declarations at bottom of this page)

 

Important: Please make sure that pdfPrint is not called before the previous call to pdfPrint has been completed. For example disable the menu item which was used to start the printing process before the call and enable it again after the method has been returned.  

 

pdfPrint will return the number of pages, the value -1 if an error happened (more information is available using DebugView). The value -2 is returned when the method was called while a previous job within the same thread was not completed. When used from multiple threads internally the calls are automatically serialized using critical sections.

 

Please note: pdfPrint expects char * parameters which are ANSI characters. If the filename can contain special characters/umlauts it is better to use pdfPrintW and pass 2 byte unicodes. In both cases the strings have to be terminated by \0.

 

pdfPrintW has two additional parameters data and datalen. If not 0, a buffer with PDF data is expected which is loaded or, if a file was also specified, appended  prior to printing.

 

function pdfPrintW(

 filename: PWideChar; 

 password: PWideChar;

          licname, lickey: PWideChar; 

 liccode: Cardinal; 

 options: PWideChar;

          data: Pointer; datalen: Integer): Integer; stdcall;

 

 

Options:

 

Several parameters can be passed inside the option string.

 

The string "options" can contain several parameters. They need to be placed in quotes (") and separated by comma characters, example:

 

options = "\"FROM=1\",\"TO=2\"" to print pages 1 to 2.

 

This options are supported:

 

Standard print options:

 

PRINTER        =xxx - select printer name

COPIES        =N - select count of copies

FROM        =N - the first page (1..)

TO        =N - the last page

COLLATE        =1 - enable collate mode

REVERSE        =1 - print in reversed order

 

ADDPRINTER   = xxx. The mentioned printer (probably a network printer) will be added to the list of printers and also selected unless a different name has been specified with PRINTER=xxx

 

Show the print dialog

 

DIALOG            = 1

 

Print as bitmap:

 

LOWQUALITY*)        =1 - buffer all output to monochrome bitmap in screen resolution

USEBITMAP       =1 ... 10. A colored bitmap will be sent to the printer. The resolution is the printer resolution defined by the value.

                       Suggested values is 2. Using this settings embedded fonts can be reproduced more thoroughly.

BUFFERED*)        =1 - buffer all output to monochrome bitmap in [BUFFERRES] dpi.

BUFFERRES*)        =X - resolution for the buffered printing. Default = print resolution / 2

 

Print from memory

 

The filename can be used to transfer PDF data as a memory block.. To do so pass its size as option:

MEMORYSIZE    = x

 

 

Select paper tray:

 

TRAY1        =N - printer tray for first page

TRAY2        =N - printer tray for all pages

 

Select media type

 

MEDIATYPE      = N - this must be a valid media type identifier

 

Select duplex mode:

 

DUPLEX        select duplex mode:

 0= simplex,

 1=horizontal,

 2=vertical

 

Stretch the pages:

 

STRETCH        = N

 0 : Print page on paper ignoring the physical margins (default)

 1 : Reduce the print size to printable area

 2 : Reduce the print size to fit the physical page  

 3 : Scale the print size to fit printable area

 4 : Scale the print size to fit the physical page

 

NO_OFFSET = 1 - with this setting the engine will not subtract the physical offsets

 

 

To print a smaller PDF page in the upper left corner of the current paper use the option string: 

 

   '"STRETCH=2","DONTSETDEVMODE=5"'

or, from c++, 

  "\"STRETCH=2\",\"DONTSETDEVMODE=5\""

 

 

LIMITA3 = 1:  force any pages larger than A3 to be scaled down to A3 using default stretch mode.

Stretchmode is automatically set to 0.

 

 

Troubleshooting:

 

DONTSETDEVMODE=1 will disable any modifications to the printer setup

DONTSETDEVMODE=2 will only allow the change of the page orientation

add 4 to disable the automatic detection of landscape formats

 

you can also activate the creation of a logfile

LOGFILE=c:\temp\pdfview.log

DEBUGMODE=1

 

 

Print watermark metafiles:

 

WATERMARK        =name of a enhanced meta file to print a watermark on all pages (stretched to

page size!)

OVERPAGE        =name of a enhanced meta file to print a drawing over all pages (stretched to page size!)

 

Print header and footer texts or page numbers:

 

HEADERFONT*)        =name, default = Arial

HEADERSIZE*)        =size in pt, default = 11

 The mode can be used to set the font name for the header text.

FOOTERFONT*)        =name

FOOTERSIZE*)        =size in pt

 Use it to set the font name for the footer text.

 

HEADERL*)        - string to print in header on left side (at the top of printable area)

HEADERC*)        - string to print in header centered

HEADERR*)        - string to print in header on right side

FOOTERL*)        - string to print in footer on left side (at the bottom of printable area)

FOOTERC*)        - string to print in footer centered

FOOTERR*)        - string to print in footer on right side

 

In these strings You can use the placeholder [#] to print the current page number and [##] to print the page count.

 

Select Paper width/Height

 

PAPERWIDTH = ...

 

If larger than 0, set the value for the DEVMODE dmPaperWidth member which will be set in the printer structure.

 

PAPERLENGTH  = ...

 

If larger than 0, set the value for the DEVMODE dmPaperLength member which will be set in the printer structure.

 

PAPERSIZE   = ...

 

If larger than 0, set the value for the DEVMODE dmPaperSize member which will be set in the printer structure.  

If -1 is used, the value will be not set and the default paper size defined for the printer will be preserved. (Switch off automatic paper size switching)

 

Use Printer ESCAPE codes:

 

WRITEPRINTER        - string of hex encoded characters to be sent to the printer using the Escape() function [1]

WRITEPRINTERBEFORE - string of hex encoded characters [2]

WRITEPRINTERAFTER - string of hex encoded characters [3]

WRITEPRINTERBEFORESTART - string of hex encoded characters [4]

 

[1] will be sent before each page

[2] will be sent before all pages

[3] will be sent after all pages, before EndDoc()

[4] will be sent before the document is started, before StartDoc()

 

Switch off any modifications to the DEVMODE structure of the printer:

 

DONTSETDEVMODE=1

 

Modify the way fonts are drawn:

 

OUTLINEFONTS=x

    0: Renderer only draws embedded fonts as outlines which are either subsets or not also installed

    1: renders all fonts as outlines, also installed fonts

    2: renders embedded fonts as outlines

 

STDGDI=1

Selects the standard GDI renderer instead of GDIPLUS. This can result in smaller print files and faster output. For difficult PDF files it can cause a decrease in output quality.

 

 

Switch off anti alias printing for images - that can be important for barcodes:

 

DISABLEAA=1

DISABLEANTIALIAS=1

 

 

Initialize JBIG2 EXE plugin

 

This option is obsolte - the JBIG2 decoding DLLs are wpdecodejp.dll for 32 bit, the file wpdecodejp64.dll for 64 bit projects.

JBIG2TOOL={dll}convert.exe {in} -o {out} 

 

 

Debug Options:

 

LISTTRAY        =1 - list all paper trays to debug console

LISTPRINTER        =1 - list all printer names to debug console

 

PROGRESSWND*)  =handle of a window to receive progress messages. Must be passed as integer number.

 

DONTWAIT       =1 - the function returns quicker

 

Declaration of the print function in Delphi

 

  fktpdfPrint = function(filename: PAnsiChar; password: PAnsiChar;

    licname, lickey: PAnsiChar; liccode: Cardinal; options: PAnsiChar)

    : Integer; stdcall;

 

  fktpdfPrintW = function(filename: PWideChar; password: PWideChar;

    licname, lickey: PWideChar; liccode: Cardinal; options: PWideChar;

    data: Pointer; datalen: Integer; pdfPrintW): Integer; stdcall;

 

Note: The unit WPViewPDF initializes the pointer wpview_....

 

Declaration of the print function in C

 

stdcall int pdfPrint(

 char *filename, char *password:

 char *licname, char *lickey,

 unsigned long liccode,

 char *options);

 

MSVC++ 6.0 / MFC Example:

 

      HINSTANCE hiDll = LoadLibrary( "wPDFViewDemo04.dll" );

      // int pdfPrint(string filename, string password, string license_name, string license_key, int license_code, string options);

      typedef int__stdcall * TypePdfPrint) ( char*, char*, char*, char*, unsigned longchar* );

      TypePdfPrint pDllPdfPrint = (TypePdfPrint) GetProcAddress( hiDll, "pdfPrint" ); 

      if(pDllPdfPrint)

      {

         CString csOptions = "HEADERC=" + csFilePath + ",FOOTERC=" + csFilePath;

         CString csLicPwd  = ""// empty

         CString csLicName = "..."// add license data

         CString csLicKey  = "...";

         int     iLicCode  = ...;

 

         int iR = pDllPdfPrint( csFilePath.GetBuffer(0), 

               csLicPwd.GetBuffer(0), 

               csLicName.GetBuffer(0), 

               csLicKey.GetBuffer(0), 

               iLicCode, 

               csOptions.GetBuffer(0) );

         if(iR <= 0) AfxMessageBox( "Cannot print the file " + csFilePath );

      }

 

 

 

Visual Basic 6 Example:

 

   Private Declare Function pdfPrint Lib "wPDFView05.dll" ( _

            ByVal strFilenames As String, _

            ByVal strPassword As String, _

            ByVal strLicName As String, _

            ByVal strLicKey As String, _

            ByVal lngLicCode As Long, _

            ByVal strOptions As String _

        ) As Long

 

 

Private Sub Command1_Click()

   If pdfPrint(Text1.Text, "", "LIC_NAME", "LIC_CODE", 0, "") <= 0 Then

      MsgBox ("Cannot print PDF file")

   End If

End Sub

 

 

.NET C# Example:

 

// .NET C# Code to print directly using the wPDFViewDemo02 Engine DLL

// using System.Runtime.InteropServices;

[DllImport("wPDFViewDemo04.dll", CharSet=CharSet.Ansi)]

 public static extern int pdfPrint(string filename, string password,

 string license_name, string license_key, int license_code,

 string options);

private void Print_Click(object sender, System.EventArgs e)

{

 pdfPrint(FileName.Text,

 "", // Password or ""

 "","",0, // License Information

 "");// Options

}

 

 

.NET VB Example:

 

// .NET VB Code to print directly using the wPDFViewDemo02 Engine DLL

// requires System.Runtime.InteropServices;

<DllImport("wPDFViewDemo04.dll", CharSet:=CharSet.Ansi)> _ 

Public Shared Function pdfPrint(ByVal filename As StringByVal password As String, _

ByVal license_name As StringByVal license_key As StringByVal license_code As Integer, _

ByVal options As StringAs Integer 

 

 

Private Sub Print_Click(ByVal sender As ObjectByVal e As EventArgs)

    WinForm.pdfPrint(Me.FileName.Text, "", "", "", 0, "")

End Sub

 

Delphi Example

 

 

 

function pdfPrint(filename: PChar; password: PAnsiChar;

  licname, lickey: PAnsiChar; liccode: Cardinal;

  options: PAnsiChar): Integer; stdcall;

  external 'wPDFViewDemo04.dll' name 'pdfPrint';

 

 

function pdfPrintW(filename: PWideChar; password: PWideChar;

  licname, lickey: PWideChar; liccode: Cardinal;

  options: PWideChar; 

  data: Pointer; datalen: Integer): Integer; stdcall;

  external 'wPDFViewDemo04.dll' name 'pdfPrintW';

 

 

Note: The unit WPViewPDF initializes the function pointer wpview_.... which can be used directly:

 

 wpview_pdfPrintW: fktpdfPrintW;

 wpview_pdfPrint: fktpdfPrint;

 

are initialized by the function WPViewPDFLoadDLL(DLLName: string; Quiet : Boolean = FALSE): Boolean; which is called automatically when a viewer will be created but can also be called directly.

 

 

Please update the code to use wPDFViewDemo04.dll or wPDFView04.dll.