[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 715
  • 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();

Error

"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
                  document.open();
                        //add text from the select document in the document collection
                                    
               DocumentCollection dc =
          agentContext.getUnprocessedDocuments();
     Document doc = dc.getFirstDocument();
      while (doc != null) {
       System.out.println(
       
                    document.add(new Paragraph (doc.getItemValueString("centre"))));
                            
                            doc = dc.getNextDocument(); }
                        
                        //if error, catch it with the Catch Statement below                        
                        
                        } catch (DocumentException de) {
                              System.err.println(de.getMessage());
                        }

                        document.close();

            } catch(Exception e) {
                  e.printStackTrace();
            }
      }
}

Your prompt response will be much appreciated.

Thanks,
Varvoura
0
varvoura
Asked:
varvoura
  • 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();
use:
      lotus.domino.Document doc = dc.getFirstDocument();
0
 
varvouraAuthor Commented:
Perfect, exactly what I needed.
0
 
Sjef BosmanGroupware ConsultantCommented:
Ah wonderful! You're specializing in Java now? LotusScript is "out"? You're making progress!!  ;-))
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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