|
pdfPrint - PRINT PDF function |
Top Previous Next |
|
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.
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.
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.
List:
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 LOWQUALITY*) =1 - buffer all output to monochrome bitmap in screen resolution BUFFERED*) =1 - buffer all output to monochrome bitmap in [BUFFERRES] dpi. BUFFERRES*) =X - resolution for the buffered printing. Default = print resolution / 2 If you use the parameter TRYPNG=1 the tool will try to transfer a compressed PNG bitmap to the printer. (We found no printer which supports PNG images though) TRAY1 =N - printer tray for first page TRAY2 =N - printer tray for all pages STRETCH =1 - print the page inside physical page margins STRETCH =2 - print the page stretched to the page size (don't add margins) 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!) DUPLEX select duplex mode: 0= simplex, 1=horizontal, 2=vertical LISTPRINTER =1 - list all printer names to debug console LISTTRAY =1 - list all paper trays to debug console
DONTWAIT =1 - the function returns quicker
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.
_____ *)New mode in WPViewPDF Version 2
Declaration of the print function in C
stdcall int pdfPrint( char *filename, char *password: char *licname, char *lickey: PChar, unsigned long liccode, char *options);
MSVC++ 6.0 / MFC Example:
HINSTANCE hiDll = LoadLibrary( "wPDFViewDemo02.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 long, char* ); 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 "wPDFView02.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("wPDFViewDemo02.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("wPDFViewDemo02.dll", CharSet:=CharSet.Ansi)> _ Public Shared Function pdfPrint(ByVal filename As String, ByVal password As String, _ ByVal license_name As String, ByVal license_key As String, ByVal license_code As Integer, _ ByVal options As String) As Integer
Private Sub Print_Click(ByVal sender As Object, ByVal e As EventArgs) WinForm.pdfPrint(Me.FileName.Text, "", "", "", 0, "") End Sub
Delphi Example
function pdfPrint(filename: PChar; password: PChar; licname, lickey: PChar; liccode: Cardinal; options: PChar): Integer; stdcall; external 'wPDFViewDemo02.dll' name 'pdfPrint';
Please update the code to use wPDFViewDemo01.dll or wPDFView01.dll.
|