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
varvouraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.