About us | News | Contact
iText ® Licenses Support   
You are here: Home > Forums > iText and iTextSharp Support > Getting started > Installing iTextSharp
User login
  • Request new password

Can I use iTextSharp in a VBA application?

Submitted by Anonymous Newbie on Fri, 02/11/2011 - 15:58

Since iTextSharp is a .NET library, I registered iTextSharp.dll with: RegAsm iTextSharp.dll /tlb:iTextSharp.tlb /codebase. The Regasm I used is from .NET Framework 4(4.0.30319.1), and my OS is Win7/64 on AMD. I got approx a dozen warnings for generic types. Then I opened Access 2007 and set the reference to iTextSharp.tlb.

Then just in order to see everything was ok, i tried:

Private Sub PDFButton_Click()
  Dim pdfTemplate As String
  pdfTemplate = "C:TmpD0001.PDF"
  Dim TestClass As pdfReader
  Set TestClass = pdfReader(pdfTemplate)

The rest was not developed because the execution always stops at the last row with the error: Function or Sub not defined. I realized, by opening the Object window in VB, that any class included by iTextSharp has no member at all.

Therefore my question is:

  1. Was I wrong by choosing the initial procedure (to make iTextSharp usable by VBA/Access)?
  2. If I was not wrong, is it that the assembly registration was essentially not successful? If true, why?

I am wondering if this could be due to the generic types signalled by regasm. In this case the reason would be inside the code, as far as I can see. Is there a way to let iTextSharp correctly expose its classes to COM environment?

‹ iTextSharp support for .NET 1.0 / 1.1? How do I install iTextSharp? ›
  • Login to post comments

iTextSharp wasn't written for VBA

Submitted by Bruno Lowagie on Fri, 02/11/2011 - 16:02.

iTextSharp is not COM ready and never will. You can write a .NET COM wrapper that could call iTextSharp but that's quite a task for limited functionality, it may work for your purpose, though.

If you only need limited functionality, why would you want COM? For simple tasks, why not use iTextSharp.dll and Visual Studio C# or VB to write a simple command line EXE. Then use VBAs Shell or extended calling interface with ShellExecute. Just pass the PDF, text and position as arguments. You may have to play some tricks like writing the text to a file to get the arguments correct. Or better ... just write everything to a little XML document like:

<stamp x="###" y="###" width="###" height="###">
  <in href="background.pdf"/>
  <text>Stamp this text in the box that is defined by x, y, width, height</text>
  <out href="result.pdf"/>
</stamp>

And then write the EXE to take only the XML as an argument and do the work.

  • Login to post comments
Content © 2010 1T3XT BVBA