jump to navigation

Export any Notes document and attachments to RTF format July 25, 2008

Posted by svenm in Tools.
Tags:
trackback

A customer of mine is migrating to Exchange and Navision. Yesterday was my last day. The project is finished now. Even though most of what they had in Notes got exported to Navision there are still a number of databases that contain very useful information but that have nothing to do with Navision. They are looking at Sharepoint for these databases but that will be something for a later phase somewhere next year or so.

By then Notes will no longer be running so they needed an alternative to store the information on the network. I was looking for a way to export documents to the file system based on Rich Text Format (RTF).

A quick look on the internet and I found a post from Julian Robichaux that almost did what I wanted. He has a sample database that “contains LotusScript that demonstrates how you can export formatted data from a Notes rich text field out to an RTF file, while maintaining most or all of the formatting. There is a script library that has all the export functions, and an agent that demonstrates how to call those functions.”

The only thing that I didn’t like was the fact that all these files were saved on the root of the c-drive.

I was looking for a tool that:

  • exports the content of the document to rtf
  • exports the attachments
  • saves the documents in a folder structure similar to the catagories in a view.

The example Julian provided was just the perfect thing to start from.

I’ve added a class called Win32Files. This is something that I’ve created a while ago and that performs a number of operations on a windows network:

  • MapAvailableNetworkDrive
  • SwitchUser
  • MakeDirectories
  • FindFolders
  • IsDriveAvailable
  • FindAllFilesInDir
  • Win32DisconnectDrive
  • RevertToSelf
  • Win32GetErrorString

I’ve taken Julian’s ScriptLib and added the Win32Files class. Then I’ve created an agent that loops through selected documents and creates folders for each document based on first and second category.

When you take a notes view, select the documents that you want to export and launch the Export Agent.

The content of the document will be exported to an rtf file and all attachments will be stored in the same directory.

A notes document that looks someting like this (in read mode):

Will turn into this:

The ‘attachment.pdf’ is no longer an attachment but an image. That’s the reason I’ve also exported the actual file.

The ‘Export Selected Docs to RTF Files’ Agent contains the path where everything needs to be exported. In my example this is “c:\” & Db.Title & “\” & Doc.Title(0) & “\” & Doc.SubTitle(0) & “\” & Doc.Subject(0) & “\”

I’ve created a sample database that contains all the code. Keep in mind that both the W32Files class and the ‘ArchiveAllAttachments’ function in the ‘Export Selected Docs to RTF Files’ Agent are stripped from a production environment so there may be some code in there that is overkill and not as clean as it should be. It’s just to give you an idea of what you can do.

You can find the sample database here.

Comments»

1. jack@leadershipbynumbers.com - July 25, 2008

Well, I think this is a cool idea. Thanks ! It’s not just for people that are leaving Notes, but it might be useful for employees that are leaving the company and would like a record of their e-mail.

2. Leo G - September 26, 2008

Nice! Exactly what I needed, thanks :)

3. Leo G - September 29, 2008

svenm,

I can get my directories created with tifs and pdf attachments exported, but am having trouble getting the rtf form created. There is a file there, but it’s unrecognizable and I can’t open. The test I ran produced this file “ATTM6TLW” can you help? Thanks for the great code!!!!

4. svenm - September 29, 2008

Leo,
What version of Notes are you using? I’ve only tested this with an 8 client. Could be a problem with previous versions…

5. Leo G - September 30, 2008

Notes 7.02. Is that why?

6. Leo G - September 30, 2008

svenm, that’s exactly what it was. I created a virtual machine and loaded Notes 8 and it works like a charm. Thanks again! I’ll dig a little deeper and see if I can get it to work with Notes 7. If you have any suggestions, let me know.

7. Darko Aleksic - October 1, 2008

I tried it with Notes 7.02 and it worked just fine.

8. Leo G - October 1, 2008

That’s odd. What operating system do you have? I ran it with 7, doesn’t work, but works like a charm on Notes 8. I did nothing special to the code, just designated my folders.

9. Darko Aleksic - October 2, 2008

Win XP. I did nothing special with the code except designating the folders as you did. I did resave the code and recompiled all LS.
What if you didnt have any pictures or files in the doc. Did it export the formated text to RTF? Or did the exception occur only with embedded tifs and pdfs?

10. Darko Aleksic - October 2, 2008

In Function ExportDocToRTFEx

oldFormName = doc.Form

Should be

oldFormName = doc.Form(0)

In case you use antoher printform

11. Darko Aleksic - October 2, 2008

I have a problem with inline images in the richtext that doesn’t show up in the RTF document. It works fine with BMP or cut&paste pictures in the Richtext but others inline images as JPG or GIF that are imported or created by Create->Picture dont get into the RTF document.

Any help appreciated!

12. svenm - October 2, 2008

Yeah I know. That don’t work. But as far as I understand it, it is not a problem with the code but with rtf-functionality.
Maybe I’m wrong. Personally, I never needed it. Sorry about that. Somebody else knows more about that?

13. Import those Word documents in Notes « SvenM - October 29, 2008

[...] by svenm in Notes/Domino, Tools. Tags: Agent, Tools trackback Ever since I wrote about a way to export data from Notes to rtf, people have asked me to also show them the other way around: import the content of a Word document [...]

14. Jeff - February 9, 2009

Hi, svenm…

I copied and pasted the ‘Export Selected Docs to RTF Files’ Agent to another Notes database (v6.5), but when I run the agent, I get the following message… ‘Illegal circular USE: RtfExportFunctions’. Any hints re: what this problem might be?

15. Sven Meirte - February 10, 2009

You could try recompiling all LotusScript code. Also make sure that you have copied all the design elements that the agent needs (like script libraries)

16. Jeff - February 13, 2009

Svenm… you’ll have to forgive my ignorance… I’m not a Notes developer, I don’t have developer rights on the database on which I’m trying to apply your agent. I was hoping to just pick the agent out of your sample database, and plop it into another database for which I need to perform the kind of export your agent does. Unfortunately, I can’t recompile any LotusScript code, and I don’t even know where to look for ‘all the design elements that the agent needs (like script libraries)’. The agent works fine in your sample export_Docs.nsf database, but when I did a copy and paste of the agent into another database on my computer, I get the message mentioned before. Probably doesn’t help to know what kind of helplessness you’re dealing with, does it?…

17. JerryS - February 20, 2009

Jeff – Designer access is needed as there are Script Libraries to be copied from the demo database to your target one.

Great code, Sven. Thank you so much – it saved me a lot of time.

18. varun - June 29, 2009

Jeff/SvenM – This is what worked for me:

1. Download Notes Domino Designer 8.
2. Open my email NSF in this DD8, copy over the 2 script libraries viz. RtfExportFunctions and W32Operations, and the 1 agent viz. Export Selected Docs etc.
3. Save and click ‘Tools’ -> “Recompile all LotusScript”.
4. Open the View named $All.
5. Click on ‘Design’ -> “Preview in Notes”.
6. Select all my emails and click ‘Actions’ -> “Export Selected Docs etc”.

Optional step – There were some bugs in email Subject handling for my machine, so I also made the following changes before saving and recompiling (YMMV):
1. In the Agent, ArchiveAllAttachment function: line 29 becomes ExtractPath$ = “c:\” & Db.Title & “\” & Doc.UniversalId & “\”
and line 40 becomes InitialFolder$ = “c:\” & Db.Title & “\” & Doc.UniversalId & “\”
2. In the Agent, Initialize function: line 14 becomes Call ExportDocToRTF(InitialFolder$ & Format(doc.Created, “Medium Date”) & “_” & doc.UniversalID & “.rtf”, doc)

Hope this helps.

19. Stefan - July 1, 2009

Hi Svenm,

First thing: really a nice job you did here, even i am not a friend of lotus script, as i am much more familiar with php, your code was written in an easy-to-understand way ^^

But i have one issue with the agent, the fontsettings from -some- mails doesnt seem to be processed, not even the newline.
When i edit the original mail and select the text i can change the font to arial, save it and after this your agent is working fine with the fonts.
So when the body doesnt have a $Fonts tag, even newline and things like this is not processed.

Would there be a way to just “give” the mail a $Font Rich Field? Like just Courier & Font size 10?

I already tried to use an additional agent with @commands:
@Command([OpenDocument];”1″);
@Command([EditGotoField]);”Body”;
@Command([EditSelectAll]);
result := @Command([TextSetFontFace];”Courier”);
@Command([FileSave]);
@Command([FileCloseWindow])

but this always tells me to save the document, so i cant select more than 1 mail to be processed :/

any help would be very great.

svenm - July 1, 2009

Stefan,

What version of Notes client do you use? I haven’t heard of this problem so far. Seems interesting I must say. I’d like to have a look at this problem but in order to do so I would like to perform my tests with the same version of Notes client…

20. Stefan - July 1, 2009

Hi Sven,

you reply really fast ^^
i am using notes 8.5 (german)

i could provide a good and bad rtf export file and a fine collection of good and bad screenshots if you like :> and as i said, it only happens to mails that dont have a $Fonts Field (what you can check by viewing the Properties of the mail and then search for this in the list of the 2nd register there)

svenm - July 1, 2009

Yeah, well I like to keep my visitors happy….
I’ll send you an email tomorrow concerning these two files!

21. Remy - October 26, 2009

Hi Sven,

I ran intoo your agent and tried this in our enviroment. In our databases all documents are in the categorie ‘NOT Categorized’
could this be a reason why noting is exported?
When i test with your testdatabase it works all fine.
When i test with our database, no errors occur, but also the created directory is empty.
When i copy documents from testdatase to our database and run te agent, the documents appear in the folder. (but still not the documenst from NOT Categorized)
Any help appriciated

22. svenm - October 26, 2009

Remy,
What version of Notes are you using? Have you copied all design elements?
Are you able to export document that do have a category? It’s been a while since I’ve worked on these classes so I can’t recall exactly what I did. It could be possible that I performed a check on category…
I will have a look at it for you.
Would it be possible to send me a copy of the database you are using along with a few documents (not all). Don’t forget to disable local encryption and put Anonymous to Manager access… Just send it to my gmail address.

23. Remy - October 26, 2009

wooow really quick answer indeed… :D
We are running domino 7, and tried designer 7, but also designer 8.5.
I’ve copied the agent, and both of the script library’s. (is that what you mean?)
Yes i off course i can send you an email with the database, thanks for any help!

remy

24. Remy - October 27, 2009

Hi Sven, you just received the DB!
Thnx

Remy

25. Christoph - November 5, 2009

I have the exact same Problem: Lotus Notes/Designer 8.5, the Script creates a empty folder, and seems to continue accessing it, as deleting that folder is only possible after exiting Lotus Notes.

Also, if i start the script on your demo-database after i started it on my own, two files called ~tempcd.cd and ~temprtf appear in the folder named after my database… so i guesse it hangs somewhere, but i can’t find the place this could happen… maybe some of this is helpful to your hunting =)

svenm - November 9, 2009

I will have a look at this problem as soon as I can but I did a quick test on a 6.5.3 client and there is no problem with this version. The agent exports the documents and attachments as expected.
When I have the time I will try the same thing on later versions and I will post my findings here.