BCL easyPDF SDK
easyPDF SDK Usermanual
PDF Creator Programming API  |  Download Free Trial  |  Contact Us to Purchase

PrintOut3 Method

Prints a document into a PDF file. Both input and output are stored in memory.

Function PrintOut3(InStream As Variant, FileExtension As String) As Variant

byte[] PrintOut3(byte[] InStream, string FileExtension)

byte[] PrintOut3(byte[] InStream, String FileExtension) throws PrinterException

Parameters

Return Values

PDF file in byte array in (VT_ARRAY | VT_UI1) format.

Remarks

An Error is raised if conversion is not successful.  You can obtain detailed information once you catch the error.

Note: If you are printing an HTML stream, then all links that points to external objects (such as images, style sheets) must be specified with absolute path (or using BASE tag), or the document will not be printed correctly.

Example Usage

    On Error GoTo Function_Err

    Set oPrinter = CreateObject("easyPDF.Printer.8")
    Set oPrintJob = oPrinter.PrintJob

    ' create HTML in memory.
    strHTM = "<html><body><center>Hello</center></body></html>"

    ' convert HTML string into byte array using ADO stream object
    Set oADO = CreateObject("ADODB.Stream")
    oADO.Charset = "Windows-1252"
    oADO.Type = 2 ' 2: adTypeText
    oADO.Open
    oADO.WriteText strHTM
    oADO.Position = 0
    oADO.Type = 1 ' 1: adTypeBinary
    arrHTM = oADO.Read
    oADO.Close

    ' Convert to PDF
    arrPDF = oPrintJob.PrintOut3(arrHTM, ".htm")

    ' Save binary data To disk using ADO stream object
    oADO.Type = 1 ' 1: adTypeBinary
    oADO.Open
    oADO.Write arrPDF
    Call oADO.SaveToFile("C:\test\output.pdf", 2) ' 2: adSaveCreateOverwrite
    oADO.Close

    MsgBox "Success!"

Function_End:
    Exit Sub

Function_Err:
    ' Get error message
    MsgBox Err.Description

    ' Look at the error number
    If Err.Number = PRN_R_CONVERSION_FAILED Then
        ' More detailed error message
        MsgBox "Conversion Result: " + oPrintJob.ConversionResultMessage

        ' See if we have error message from printer driver
        nResult = oPrintJob.ConversionResult
        If nResult = PRN_CR_CONVERSION Or _
           nResult = PRN_CR_CONVERSION_INIT Or _
           nResult = PRN_CR_CONVERSION_PRINT Then
            ' Error message from printer driver
            MsgBox "Printer Result: " + oPrintJob.PrinterResultMessage

            ' You can also get the result in integer form
            nPrinterResult = oPrintJob.PrinterResult
        End If
    End If

    Resume Function_End

Java Example - JACOB Bridge

import com.bcl.easypdf.*;
import com.bcl.easypdf.EasyPDFPrinter.*;
import com.bcl.easypdf.EasyPDFPrinter.IPDFSetting;
import java.io.*;

public class PrintOut3
{
        public static void main(String[] args) throws Exception
        {
                EasyPDF.initialize();

                IPrinter printer = new IPrinter();
                IPrintJob pj = printer.getPrintJob();

                File filein = new File("c:\\test\\input.doc");
                FileInputStream fis = new FileInputStream(filein.getCanonicalPath());
                byte[] byteArr = new byte[(int)filein.length()];
                fis.read(byteArr);

                byte[] byteArrOut = pj.PrintOut3(byteArr, ".doc").toSafeArray().toByteArray();

                FileOutputStream fos = new FileOutputStream("c:\\test\\output.pdf");
                fos.write(byteArrOut);

                fis.close();    // closing input stream
                fos.close();    // closing output stream
                EasyPDF.uninitialize();
        }
}