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

document.close();

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

Related articles about creating PDF files

15 comments :

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?

Thanks!
Kevin
LotusGuru Blog

Unknown said...

I have done much work on creating PDF using the iText Jar file
should you need help
mmarcavage@andersontechs.com

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 said...

but if we want to modify something...

Dmytro said...

here is an example. I put in on OpenNTF...
http://www.openntf.org/projects/pmt.nsf/1af5f59bae92986c85256bae000f898c/c2e87cc33b93e33b862574410058023e!OpenDocument

http://www.openntf.org/projects/pmt.nsf/
1af5f59bae92986c85256bae000f898c/c2e87cc33b93e33b862574410058023e
!OpenDocument

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 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.
http://www.notessidan.se/A55B53/blogg.nsf/plink/TADN-7DKAH9

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-