Hendrik
Hendrik

Reputation: 83

Disable itextsharp error message

I develop an Bentley Microstation Addin using C# .NET 3.5. This Addin uses itextsharp to create a PDF file.

At the first itextsharp command in my case:

PdfReader _reader = new PdfReader("...\ab.pdf");

i get an message form itextsharp: enter image description here

"The itextsharp.LicenseKey could not be loaded! Reason: The Assembly is not vaild or could not be loaded by 'Assembly.LoadForm'"

After i confirmed this message the program is running fine and there is no error with the pdf. The message might be an exeption?!

If i run the PDF creation part as standalone exe there isn't any message.

I'm searching for a solution to disable or catch this error.

edit1: Here is the iText part of my code:

using iTextSharp.text.pdf;
...
PdfReader _reader = new PdfReader("D:\Test\Source.pdf");
PdfStamper _stamper = new PdfStamper(_reader, new FileStream("D:\Test\Destination.pdf", FileMode.Create));

AcroFields _fields = _stamper.AcroFields;
var _fieldKeys = _fields.Fields.Keys;

foreach (string _fieldKey in _fieldKeys)
{
    string _value = "";
    if (_DataMapping.ContainsKey(_fieldKey.Split('.').Last().Replace("[0]", "")))
        _value = _DataMapping[_fieldKey.Split('.').Last().Replace("[0]", "")];
    _fields.SetField(_fieldKey, _value);
}

_stamper.Close();
_reader.Close();

_DataMapping is a Dictionary of which contains the field/value mapping.

Upvotes: 0

Views: 1781

Answers (1)

JZE
JZE

Reputation: 51

You need the licensekey dll, which is available here: http://developers.itextpdf.com/license-key-download

You then need to insert the following call before any other iText method calls:

LicenseKey.LoadLicenseFile(“path/to/itextkey.xml”)

Note that you mention "I try to use the AGPL version." However, the only time this error message would show up is when you use XFA Worker. XFA Worker doesn't exist in an AGPL version. If you want to use XFA Worker, a commercial license is required.

Upvotes: 5

Related Questions