This method returns a generated PDF document as a byte array.
VARIANT GetBuffer () |
{ 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();
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); }
// 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();
' 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