c++ Usage
All Aloaha APIs are implemented as automation compatible COM Objects. The advantage is that the Aloaha APIs can be used by any language which does support COM Objects.
Most variables have to be passed by reference (as pointers). Some programming language handle this automatically, in some others you need to define that in the code.
For programmers which have problems to pass variables by reference we introdced in Build 3.0.171 a new function which expects the variables by value.
The function is called Sign_PDF_EML and is identically to the function sign_pdf_file explained
here. The only difference is that is supports by value instead of by reference. The EML in the function name furhtermore shows that this function is also able to handle emails as explained
here.
If you use as function name sign_file instead then you can also pass as infile a NON PDF document. Aloaha will create as outfile an enveloped PKCS7 file. It is suggested to give the outfile the extension p7m.
Please note that this function requires a valid license key! Please contact
aloaha@wrocklage.de for an evaluation key.
c++ code sample
main.cpp (1,32 KB)
#include "windows.h"
#include <atlbase.h>
#import "C:\Program Files\Common Files\aloaha\aloahapdf.dll" auto_rename, auto_search
BOOL DigSignPDFFile(LPCWSTR lpszsrcpdf, LPCWSTR lpszdstpdf,
LPCWSTR lpszsignreason, LPCWSTR lpszsignlocation)
{
try
{
// Create COM object smart pointer class.
CComPtr<aloahapdf::_edit> editpdf;
// Create an instance of the "aloahapdf.edit" COM object.
if (FAILED(editpdf.CoCreateInstance(L"aloahapdf.edit", NULL, CLSCTX_INPROC_SERVER)))
return FALSE;
// Please set empty for an invisible signature
// If you use as content a path to a 24Bit JPG Image it will be used as signature image
// See also http://www.aloaha.com/software-development/signature-types.php
editpdf->signaturecontent = _bstr_t(L"");
// Call the sign PDF function.
// _bstr_t(L"0") stands for first card reader
// it can be set also to UniqueContainerName of SerialNumber of Certificate
if (editpdf->Sign_PDF_EML(_bstr_t(lpszsrcpdf), _bstr_t(lpszdstpdf),
0, 0, 11, 8, 21, 2, _bstr_t(lpszsignreason), _bstr_t(lpszsignlocation),
_bstr_t(L"0"), _bstr_t(L"")) == VARIANT_FALSE) return FALSE;
}
catch(_com_error)
{
// Catch any COM exceptions.
return FALSE;
}
// Success.
return TRUE;
}
void main(void)
{
::CoInitialize(NULL);
DigSignPDFFile(L"C:\\test.pdf", L"C:\\test_sign.pdf", L"Reason", L"Location");
::CoUninitialize();
}
main.cpp (1,32 KB)
Options/Variables of function Sign_PDF_EML:
InputPDF: This first parameter defines the Input File. In case the function Sign_PDF_EML this file has to be of type PDF or EML. Should you use the alternatve function Sign_File this inputfile can be of any filetype.
OutputPDF: The second paramter defines the outputfile. For function Sign_PDF_EML it has to be of type PDF or EML. In case you use the function Sign_File the extension can be also .P7M.
The following 8 options are only relevant when signing PDF Documents. For other document types they will be ignored and can be set to 0.
PaperX: PDF Page Size X. If set to 0 Aloaha will autodetect the size.
PaperY: PDF Page Size Y. If set to 0 Aloaha will autodetect the size.
percentx1: Upper left corner of signature Box (X) in percent.
percenty1: Upper left corner of signature Box (Y)in percent
percentx2: Lower right corner of signature Box (X) in percent
percenty2: Lower right corner of signature Box (X) in percent
SignReason: This value will be entered into the SignReason field of the PDF Signature
SignLocation: This value will be entered into the SignLocation field of the PDF Signature
Cert_Uniquename: Certificate to be used. When using Aloahas native interface please use 0-9 for Cardreader 1-10. If a UniqueContainerName, Fingerprint or Serialnumber is used Aloaha will access the certificate via the Windows Store.
HexFlags: Reserved for special use!
When using the suggested API Sign_File there are some special cases to note. If SignReason or SignLocation is set to "sha1" or "sha256" Aloaha will use sha1 or sha256 as hashing Algorythm.
PDF Signatures created by Sign_File will be always of type adbe.pkcs7.detached.
Should have any questions or should you require other APIs by value instead of by ref please do not hesitate to contact us via the form below.
Please ask...
Although we really tried hard, there are always questions left open.
Please send us your question.
We would be glad to answer it.
Home / Knowledge Base / PDF SDK / PDF Signature API / c++ Usage