The samples above show that the C++ sample is significantly longer than that of C# or Visual Basic. The reason for this is the dependence on the Variant type.
HRESULT ObjectAttributeLong(BSTR Object, BSTR Attribute,long newVal)
HRESULT ObjectAttributeFloat(BSTR Object,BSTR Attribute,float newVal)
HRESULT ObjectAttributeStr(BSTR Object, BSTR Attribute, BSTR newVal)
// The function of the first two methods are clear, the third needs a little elaboration. // This method was initially made for languages that do not support the use of variants, // like Visual FoxPro. This method can be used to set the attribute value of any data-type, // encoded as a string, for example, the following calls can be made: m_pdf->ObjectAttributeStr(_bstr_t("Text1"),_bstr_t("Text"), _bstr_t("Hello World!") ); m_pdf->ObjectAttributeStr (_bstr_t("Text1"), _bstr_t("Top"), "500");
// Now, here is the same C++ sample from above, rewritten to use the helper methods: // The sample below creates a simple text object on the current page of the document. This is significantly shorter, less complex and easier to read. Adding some pre-processing directives so the developer can write something like _s() instead of _bstr_t() for example, will make the code even shorter. m_pdf->ReportState = acReportStateDesign; m_pdf->CreateObject( acObjectTypeText, _bstr_t("Text1") ); m_pdf->ObjectAttributeStr(_bstr_t("Text1"),_bstr_t("Text"), _bstr_t("Hello World!") ); m_pdf->put_ObjectAttributeLong(_bstr_t("Text1"),_bstr_t("Top"),200); m_pdf->put_ObjectAttributeLong(_bstr_t("Text1"),_bstr_t("Left"),250); m_pdf->put_ObjectAttributeLong(_bstr_t("Text1"),_bstr_t("Right"),600); m_pdf->put_ObjectAttributeLong(_bstr_t("Text1"),_bstr_t("Bottom"),400); m_pdf->Save(_bstr_t("HelloWorld.pdf"), acFileSaveView);