Creating a PDF file from a Lotus Notes Document

Posted on 2008-11-20
Last Modified: 2013-12-18
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 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.

Question by:varvoura
    LVL 46

    Accepted Solution

    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();

    Author Closing Comment

    Perfect, exactly what I needed.
    LVL 46

    Expert Comment

    by:Sjef Bosman
    Ah wonderful! You're specializing in Java now? LotusScript is "out"? You're making progress!!  ;-))

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

      In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now