Tuesday, May 06, 2008

How to create PDF from Lotus Notes

I want to show you one of the way how we can create PDF documents from Lotus Notes. I propose to use this package com.lowagie.text
You can download iText®, a JAVA-PDF library
Read more here Generate PDF files from Java applications dynamically

Here is an example that create PDF document.
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
document.add(new Paragraph ("Create PDF in Lotus "));
//if error
} catch (DocumentException de) {
System.err.println(de.getMessage()); }


} catch(Exception e) {
Download Project: convert_2_pdf example

Related articles about creating PDF files


Kevin Pettitt said...

Dmytro, I would love to add PDF printing capability to SuperNTF but I don't have time to pull all these pieces together to see if your code will do what I need. Do you already have a functioning agent inside an .nsf that you could share?

LotusGuru Blog

Michael said...

I have done much work on creating PDF using the iText Jar file
should you need help

Kevin Pettitt said...

Michael, for reasons I now cannot recall I was unsuccessful in getting the iText stuff working. If you've got working code in a Notes database context please do share.

Anonymous said...

Why not use "Win2Pdf"? It is free, it appears as a printer option, and it creates a Pdf, and gives you the option of printing it at the same time.

Dmytro Pastovenskyi said...

but if we want to modify something...

Dmytro Pastovenskyi said...

here is an example. I put in on OpenNTF...


Kevin Pettitt said...

Dmytro, thanks for posting that. I see what you're doing now and while useful for some applications I'm looking for something that will allow the printing of any Notes document to PDF. As our anonymous friend mentiones, Win2PDF is an option, but as a separate install it falls short of the "just works" goal I am aiming for.

The odd thing is that Symphony Documents has a built-in Export to PDF function, but Notes documents in 8 cannot do the same trick.

Dmytro Pastovenskyi said...

i will think about it.. probably i will find the way.
i will let you know if i find the right approach

Kevin Pettitt said...

Thanks Dmytro, I'll keep my eyes open for it :-)

Thomas Adrian said...

If you want to create PDF's from any notesdocument in the background, here is a way to do it using Acrobat Proffesional.

Anonymous said...

I am using the iText to export documents to PDF, I can't find out how to write the contents of the body field "as is" to the PDF.

Anonymous said...

THank you for this example .. Can youput more details steps and how to bring it to the Lotus Notes DB..

Thanks in advance

jiffygallant said...

How do you programmatically convert all .nsf files in a local directory to .pdf files using Java?

I have the iText jar but not the package "lotus.domino.*"

I also have a PDF printer set up as my default printer (cutePDF).

Any ideas?

Anonymous said...

Alternative option is also present in online market, try Lotus Notes to PDF software which can solve your issues within blink of eyes

Kemlin joseph said...

I have successfully convert NSF to PDF. Users who want to convert NSF to PDF, this information could be helpful. How to convert NSF to PDF-