Components for Developers
© 2000-2012, Two Pilots

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF-X Pilot History In the Lab

PDF Creator Pilot documentation

Download CHM version of this manual.
Common
Collapse All

This method returns a generated PDF document as a byte array.

Syntax

VARIANT GetBuffer ()
Return value
Array of bytes representing the PDF document

Remarks

This method returns a generated PDF file as a byte array and can be used within methods for streaming output to a PDF. To use this method in the full version of the library, you must have at least a Web License.

Example

How to Create a PDF Document and Return the Data in a Web Application

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }
font := PDF.AddFont('Arial', false, false, false, false, fcDefault);
PDF.UseFont(font, 10);
PDF.ShowTextAt(10, 10, 'This is the 1st page.');

Response.Clear; 
Response.ContentType := 'application/pdf';
Response.AddHeader('Content-Type', 'application/pdf');
Response.AddHeader('Content-Disposition', 'inline;filename=form.pdf');
Response.AddHeader('Content-Length', PDF.GetBufferSize.ToString());
Response.BinaryWrite(PDF.GetBuffer()); 
Response.End();
C/C++
[copy to clipboard]
void copyToByteArray(VARIANT variant, unsigned char** p_arrayDest, int& iMemSize);

int _tmain(int argc, _TCHAR* argv[])
{
    ::CoInitialize(NULL);
    // declare PDF Creator Pilot object
    IPDFDocument4* PDF = NULL;

    CLSID clsid_PDFCreatorPilot;
    CLSIDFromProgID(OLESTR("PDFCreatorPilot.PDFDocument4"), &clsid_PDFCreatorPilot);
    ::CoCreateInstance(clsid_PDFCreatorPilot, NULL, CLSCTX_ALL, __uuidof(IPDFDocument4), (LPVOID*)&PDF);        
    if(PDF == NULL)
    {
        ::CoUninitialize();
        return 1;
    }

    long font = PDF->AddFont("Arial", false, false, false, false, fcDefault);
    PDF->UseFont(font, 10);
    PDF->ShowTextAt(10, 10, "This is the 1st page.");
    long s = PDF->GetBufferSize();
    
    _variant_t vt = PDF->GetBuffer();

    size_t size = 0;
    unsigned char* buffer = 0;  
    copyToByteArray(vt.GetVARIANT(), &buffer, (int&)size);

    // PDF object is supposed to be created
    long font = PDF->AddFont("Arial", false, false, false, false, fcDefault);
    PDF->UseFont(font, 10)
    PDF->ShowTextAt(10, 10, "This is the 1st page.");

    Response->Clear(); 
    Response->ContentType = "application/pdf";
    Response->AddHeader("Content-Type", "application/pdf");
    Response->AddHeader("Content-Disposition", "inline;filename=form.pdf");
    Response->AddHeader("Content-Length", itoa(PDF->GetBufferSize()));
    Response->BinaryWrite(buffer); 
    Response->End();

    // after all we clear memory
    delete [] buffer;

    ::CoUninitialize();
    return 0;
}

void copyToByteArray(VARIANT variant, unsigned char** p_arrayDest, int& iMemSize)
{
    SAFEARRAY* pSafeArray = variant.parray;

    long lStartBound = 0;
    SafeArrayGetLBound(pSafeArray, 1, &lStartBound);

    long lEndBound = 0;
    SafeArrayGetUBound(pSafeArray, 1, &lEndBound);

    BYTE* arrayAccess = 0;
    SafeArrayAccessData(pSafeArray, (void**)&arrayAccess);

    int i_size = (lEndBound - lStartBound + 1) * sizeof(BYTE);
    *p_arrayDest = new unsigned char [i_size];

    memcpy(*p_arrayDest, (const void *) &(arrayAccess[0]), i_size);
    iMemSize = i_size;

    SafeArrayDestroy(pSafeArray); 
    SafeArrayUnaccessData(pSafeArray);
}
C#
[copy to clipboard]
// PDF object is supposed to be created
long font = PDF.AddFont("Arial", false, false, false, false, FontCharset.fcDefault);
PDF.UseFont(font, 10);
PDF.ShowTextAt(10, 10, "This is the 1st page.");

Response.Clear(); 
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline;filename=form.pdf");
Response.AddHeader("Content-Length", PDF.GetBufferSize.ToString());
Response.BinaryWrite((byte[])PDF.GetBuffer()); 
Response.End();
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
font = PDF.AddFont("Arial", false, false, false, false, 1) 'fcDefault
PDF.UseFont font, 10
PDF.ShowTextAt 10, 10, "This is the 1st page."

Response.Clear
Response.ContentType = "application/pdf"
Response.AddHeader "Content-Type", "application/pdf"
Response.AddHeader "Content-Disposition", "inline;filename=test.pdf"
Response.AddHeader "Content-Length", PDF.GetBufferSize
Response.BinaryWrite PDF.GetBuffer

See Also

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF-X Pilot History In the Lab

 

 

PDF Library | Virtual Printer | Converters to PDF

Support | Blog | Forum | Contacts

© 2000-2012, Two Pilots