Discussion:
[iText-questions] iText/VBA issue
m***@infinito.it
2011-01-31 15:32:03 UTC
Permalink
Hi all,
I need to setup a simple routine in VBA/Access (2003 or 2007), which opens
an already existing PDF, writes a text extra line with some simple
formatting at a specificed position (in Word I would use a text box) with
data taken from an underlying Access query, and then opens Adobe Reader for
further actions by the user.
I thought to use iTextSharp to modify PDF, but I had problems at the very
beginning.
Since it is a .NET library, I registered iTextSharp.dll with: RegAsm
iTextSharp.dll /tlb:iTextSharp.tlb /codebase. 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
warning 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?

Thanks for any help, which will be greatly appreciated.
Marco B.
Paulo Soares
2011-01-31 15:48:23 UTC
Permalink
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.

Paulo

-----Original Message-----
From: ***@infinito.it [mailto:***@infinito.it]
Sent: Monday, January 31, 2011 3:32 PM
To: itext-***@lists.sourceforge.net
Subject: [iText-questions] iText/VBA issue

Hi all,
I need to setup a simple routine in VBA/Access (2003 or 2007), which opens
an already existing PDF, writes a text extra line with some simple
formatting at a specificed position (in Word I would use a text box) with
data taken from an underlying Access query, and then opens Adobe Reader for
further actions by the user.
I thought to use iTextSharp to modify PDF, but I had problems at the very
beginning.
Since it is a .NET library, I registered iTextSharp.dll with: RegAsm
iTextSharp.dll /tlb:iTextSharp.tlb /codebase. 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
warning 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?

Thanks for any help, which will be greatly appreciated.
Marco B.



------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php


Aviso Legal:
Esta mensagem � destinada exclusivamente ao destinat�rio. Pode conter informa��o confidencial ou legalmente protegida. A incorrecta transmiss�o desta mensagem n�o significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. � proibido a qualquer pessoa que n�o o destinat�rio de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.
Kevin Brown
2011-01-31 21:15:44 UTC
Permalink
Why would you want COM? For something so simple, 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.

Kevin Brown

-----Original Message-----
From: ***@infinito.it [mailto:***@infinito.it]
Sent: Monday, January 31, 2011 3:32 PM
To: itext-***@lists.sourceforge.net
Subject: [iText-questions] iText/VBA issue

Hi all,
I need to setup a simple routine in VBA/Access (2003 or 2007), which opens
an already existing PDF, writes a text extra line with some simple
formatting at a specificed position (in Word I would use a text box) with
data taken from an underlying Access query, and then opens Adobe Reader for

<snipped/>
***********************************************

Loading...