• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

Creating a PDF file from a Lotus Notes Document

Hi all,

I am trying to create a PDF file from a selected document in a view. The PDF file should contains all the fields on that document which I will specify in the code and then when the PDF is created it should be saved to the C:\drive.

I have written the code below but it won't complie and I get the following error on this next line of code

Document doc = dc.getFirstDocument();


"Explicit cast needed to convert lotus.domino.Document to com.lowagie.text.Document"

Here's the code below

import lotus.domino.*;
import java.io.FileOutputStream;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chapter;
import com.lowagie.text.Font;
import com.lowagie.text.List;
import com.lowagie.text.Table;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;

public class JavaAgent extends AgentBase {
      public void NotesMain() {
            try {
                  Session session = getSession();
                  AgentContext agentContext = session.getAgentContext();
                  //create document's object
                  Document document = new Document();
                  try {
                  //create a document
                        PdfWriter.getInstance(document, new FileOutputStream("c:\\CreatePDFInlotus.pdf"));
                        //open doc for r/w
                        //add text from the select document in the document collection
               DocumentCollection dc =
     Document doc = dc.getFirstDocument();
      while (doc != null) {
                    document.add(new Paragraph (doc.getItemValueString("centre"))));
                            doc = dc.getNextDocument(); }
                        //if error, catch it with the Catch Statement below                        
                        } catch (DocumentException de) {


            } catch(Exception e) {

Your prompt response will be much appreciated.

  • 2
1 Solution
Sjef BosmanGroupware ConsultantCommented:
You're in trouble, a little: both the Notes and the PDF classes contain a Document class. I'm afraid you need to use explicit types, more or less like this (I'm no Java expert, but you'll get my drift):

instead of:
      Document doc = dc.getFirstDocument();
      lotus.domino.Document doc = dc.getFirstDocument();
varvouraAuthor Commented:
Perfect, exactly what I needed.
Sjef BosmanGroupware ConsultantCommented:
Ah wonderful! You're specializing in Java now? LotusScript is "out"? You're making progress!!  ;-))
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now