Hi all,
I have a problem using the iText library:
I have a simple Java-iText-Script running in an Java-agent. It works fine, no errors. The pdf-file is generated properly. Here it is:
import lotus.domino.*;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Anchor;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
// we create a pdf writer that listen to the document
PdfWriter pdf = PdfWriter.getInstance(document,
new FileOutputStream(“C:\Temp\HelloWorldPdf.pdf”));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
document.add(new Paragraph(“This is a paragraph”));
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
Now I want to call the same script (implemented in a Java library) from a LotusScript-Agent.
LS-Agent:
(Options)
Option Public
Option Explicit
Uselsx “*javacon”
Use “iText”
Sub Initialize
Dim jSession As JavaSession
Dim jPrintClass As JavaClass
Dim jPrintObject As JavaObject
Dim jError As JavaError
Set jSession = New JavaSession()
Set jPrintClass = jSession.GetClass(“PrintFile”)
Set jPrintObject = jPrintClass.CreateObject()
Call jPrintObject.main()
End Sub
Java library “iText”:
import lotus.domino.*;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Anchor;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class PrintFile {
public void main() {
try {
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
// we create a pdf writer that listens to the document
PdfWriter pdf = PdfWriter.getInstance(document,
new FileOutputStream(“C:\Temp\HelloWorldPdf.pdf”));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
document.add(new Paragraph(“This is a paragraph”));
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
The pdf-file is created but it is an empty file. In the Java Debug Console I get the message:
-
Helvetica not found as resource. (The *.afm files must exist as resources in the package com.lowagie.text.pdf.fonts)
-
ExceptionConverter: java.io.IOException: The document has no pages.
…
The itext-2.1.7.jar file is correctly added to the script library (in the Java-agent it already worked with no problems). The afm-files are in the correct path.
Can anyone help me solving this problem?
original post here: