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

Monday, May 05, 2008

Discovering of memory leaks

You may have discovered memory leaks when your Notes client is running a large job or just running an application on your Domino server. The leaks can occur in various places — and the source of the problems may be almost impossible to identify in your code. Here are some undocumented techniques that can help you find code that might be causing memory leaks.
The trick is to know the name of a function call to some internal registers that will return the amount of memory in use. Here are the types of information returned and the function names:

LotusScript Memory Allocated: Lsi_info(50)
LotusScript Memory Allocated from OS: Lsi_info(51)
LotusScript Blocks Used: Lsi_info(52)

Here's a LotusScript code fragment that shows how to use these functions in a foreground agent:

Sub Initialize
Msgbox(" Total LotusScript Memory Allocated: " & (Lsi_info(50)))
Msgbox(" Total LotusScript Memory Allocated from OS: " & (Lsi_info(51)))
Msgbox(" Total LotusScript Blocks Used: " & (Lsi_info(52)))
End Sub

To determine whether a leak exists, you must run this code BEFORE and AFTER the portion of code you want to investigate. If you want to use the above code in a background agent, you must print the results to the LOG.NSF using code like this:

Sub Initialize
Print "Memory Allocated: " & CStr(Lsi_info(50))
Print "Total LotusScript Memory Allocated from OS: " & CStr(Lsi_info(51))
Print "Total LotusScript Blocks Used: " & CStr(Lsi_info(52))
End Sub

If you write the information to a document in a database (for example, your own log facility), be careful because this procedure also consumes some memory, and thus, the BEFORE and AFTER measurements will NOT be equal. Also, because these techniques are undocumented, use them at your own risk, and make sure you have good backups before implementing them.

ProgressBar example

There is a small progessBar.rar of this kind of dialog. There are only main page and LS library.

Display all private agents in a database

The first step to detemine what agent are running on each server is to issue a:

Tell Amgr Sched server command

This will display all agents running in each database whether they are private or not.


Now the really cool trick - Before one can delete an agent you have to be able to see them, right? And private agent is'nt visible because they're private, stating the obvious... But here's a neat workaround:

To display all private agents in a database, all you have to do is create another private agent! It doesn't have to contain any code just create the agent, save it and exit. All private agents are now visible and you can even remove your agent and they'll stay visible.

I checked it with R5, and R6.5 it works ! but with R7.03 and R8 it did not work

Saturday, May 03, 2008

cross language via URL

I finished one small project, where I had to add possibility to change language. I did not find the best solution/way how to do it in Internet. So, I did it how I wanted :)
In my case I had documents in database (=> HTML pages) with content. So, I added in every document (HTML's page) new fields with different content (for different language). I put content in different fields: content_en, content_it, content_ru... For opening document in every language I used next approach, look at these URL:
http://host/db.nsf/EN/F593D4CBD7E802FFC125742500638A22?opendocument
http://host/db.nsf/RU/F593D4CBD7E802FFC125742500638A22?opendocument
http://host/db.nsf/IT/F593D4CBD7E802FFC125742500638A22?opendocument

Then I added agent on QO event, and checked the name of "view" (EU/RU/IT), then took it and used it when I received content => "content_" & language.