17.05.2014 Views

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

eference calls for an int type argument, Visual Basic programmers should translate this<br />

to long (although VB will correctly translate if int values are supplied).<br />

A Visual Basic program can detect when an error happens, and react upon the error.<br />

Catching Exceptions in Visual Basic is achieved with an On Error GoTo clause:<br />

Sub main()<br />

Dim oPDF As <strong>PDFlib</strong>_com.PDF<br />

On Error GoTo ErrExit<br />

...some <strong>PDFlib</strong> instructions...<br />

End<br />

ErrExit:<br />

MsgBox Hex(Err.Number) & ": " & Err.Description<br />

End Sub<br />

Using the <strong>PDFlib</strong> <strong>COM</strong> edition with .<strong>NET</strong>. As an alternative to the <strong>PDFlib</strong>.<strong>NET</strong> edition<br />

(see Section 2.7, ».<strong>NET</strong> Binding«, page 44) the <strong>COM</strong> edition of <strong>PDFlib</strong> can also be used<br />

with .<strong>NET</strong>. First, you must create a .<strong>NET</strong> assembly from the <strong>PDFlib</strong> <strong>COM</strong> edition using the<br />

tlbimp.exe utility:<br />

tlbimp pdflib_com.dll /namespace:pdflib_com /out:Interop.pdflib_com.dll<br />

You can use this assembly within your .<strong>NET</strong> application. If you add a reference to pdflib_<br />

com.dll from within Visual Studio .<strong>NET</strong> an assembly will be created automatically.<br />

The following code fragment shows how to use the <strong>PDFlib</strong> <strong>COM</strong> edition with VB.<strong>NET</strong>:<br />

Imports <strong>PDFlib</strong>_com<br />

...<br />

Dim p As <strong>PDFlib</strong>_com.IPDF<br />

...<br />

p = New PDF()<br />

...<br />

buf = p.get_buffer()<br />

The following code fragment shows how to use the <strong>PDFlib</strong> <strong>COM</strong> edition with C#:<br />

using <strong>PDFlib</strong>_com;<br />

...<br />

static <strong>PDFlib</strong>_com.IPDF p;<br />

...<br />

p = New PDF();<br />

...<br />

buf = (byte[])p.get_buffer();<br />

The rest of your code works as with the .<strong>NET</strong> version of <strong>PDFlib</strong>. Note that in C# you have<br />

to cast the result of get_buffer( ) since there is no automatic conversion from the VARI-<br />

ANT data type returned by the <strong>COM</strong> object here (similar casts are necessary for create_<br />

pfv( )).<br />

2.3 <strong>COM</strong> Binding 33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!