logo

Complete control when printing HTML from an agent

Agents that are run via the web can use the "Print" statement in order to dynamically write HTML back to the browser.

For example, in a Web Query Save agent you could return a message to the user to let them know everything went ok:

Print "<h2>Your document has been saved</h2><br />"
Print "Use this link to return to that page - <a href=""JavaScript: history.go(-2)"">Go Back 2 Pages</a>"


In the above example domino will start things off for you by creating the first few lines of necessary code. This usually starts off with the <html>, <head> and <body> tags.

If you want to have complete control over the HTML, say to set the title or the include some JavaScript in the HEAD, then the first line you print needs to be like below, which tell domino not to start the tags itself.

Print "Content-Type:text/html"


You can then carry on creating the HTML yourself.

Print "<html>"
Print "<head>"
Print "<title>"
Print "This is made ""dynamically"", by domino"
Print "</title>"

etc

Notice that in the above it is getting a bit tiresome having to use the Print statement as double quotes so often. To get around this use the curly braket delimters for you print string. This lets you use multiple line and no need to use double quotes when you want to include a single quote.

For example, the above example would be:

Print {
<html>
<head>
<title>
This is made "dynamically", by domino
</title>
.....
</body>
</html>
}


Notes:
You can also use the vertical bar | symbol.

You can do this is Java as well. First thing to do is import the "java.io" package. Then define a PrintWriter object and print lines to it:

import java.io.*;

PrintWriter pw = getAgentOutput();
pw.println("Content-Type:text/plain")
pw.println("Content-Type:text/html");


Feedback

  1. Not limited to HTML, also Excel, GIF, XML, etc.

    You can also use this technique to create other kinds or responses besides HTML. The important thing to remember is that you need to change the Content-Type also known as MIME type. For example, this line:

    Print "Content-Type:text/html"

    would change to this for Excel:

    Print "Content-Type:application/vnd.ms-excel"

    Then instead of writing out HTML, you can write out comma seperated text and Excel will launch and convert it. It's a really slick way to exporting to Excel from the web; One that I stole from my credit card company. They're not using Notes, but the principle is the same.

    If you want to get really complicated, you could have your agent write out a binary transfer to the browser. This is how you would use an agent to create a picture. You could use this to search and return scanned documents from another system (although there would probably be an easier way). I've only done this in Java and can't find the code anymore. But, you just read in a binary file (in my case from our imaging system) and print it out to the browser in binary form. Of course, the Content-Type is still set with text, as follows:

    Print "Content-Type:image/gif"

    Most web servers have a configuration file called mime.types or mime.properties or mime.cfg or mime.ini or something like that. If you look at that file you can tell what your options are. Most are obvious and have the program name in the description.

    1. anyone done PDFs? Re: Not limited to HTML, also...

      How hard would it be to generate a PDF this way? This would be *incredibly* useful, in my opinion. Even if the PDF was very simple. Has anyone done this?

      I've tried opening PDFs in BBEdit (a Mac text editor) and most PDFs look like they have a lot of binary data, which presumably would be very hard to generate, but if that part is images, then they'd be static most of the time, so you could just paste that into an agent and forget it. But my experiments suggest that there's some sort of checksum: I went in and changed some metainfo and a PDF wouldn't open right.

      This does not mean it can't easily be done. It could just mean that all the PDFs I opened were too complex. Could a simple PDF be generated???

      If done with a Java agent, are there Java classes that generate PDFs that could be used. (I'm 80% sure such classes exist, but could they be used in an agent which passes the PDF to the browser?)

      Hide the rest of this thread

      1. Re: anyone done PDFs? Re: Not limited to HTML, also...

        See the problem with PDF's is that they use compression. It's not a case of it being a straight text file with binary data init which are the images. It's a lot more complicated.

        There are products out there though which allow you to create pdf's on the fly. I know there are one or two controls for using with asp, so as long as you are running an MS OS - you should be able to use them also!

      2. Re: anyone done PDFs? Re: Not limited to HTML, also...

        I just found this link on the Apache site:

        http://xml.apache.org/fop/index.html

        It would require a different approach to that discussed here but it sounds interesting anyway..

        Jake -codestore

        • avatar
        • codeDog
        • Tue 26 Mar 2002

        PDFs are possible, but complex

        I would strongly suggest that if you need to produce PDFs from Domino that you use Java and locate one of the PDF packages specifically for that purpose.

        That said, you could still produce simple PDFs from LotusScript, but the processing would be arduous. It's been 3-4 months since I've looked at the PDF format, so my memory is a bit fuzzy, but I do recall that the PDF format involves lots of objects that refer to each other, so what you think of as a simple string of text is really several objects for each of the lines of text with more objects to describe the placement, fonts, size, spacing, margins, etc.

        Also included in the format are tables listing the objects, file properties, and other "metadata" type stuff.

        So, if you are producing a simple PDF of just a few lines of text in LS, YOU are responsible for telling the PDF file how much of that text to place on the "first line" (and what fonts to use and where to display it), followed by how much of the text to place on the "second line" (and what fonts to use and where to display it), and so on and so on. Once you've produced all that, then you need to *correctly* produce the tables of objects so the PDF reader can put it all together.

        Adobe has (IMO) a very good PDF Format document available online that gives good explanation and examples. But to try and programatically produce PDF from LS is definately NOT for the faint-hearted.

        Good luck, but stick with Java if you really want to get it done.

      3. Re: anyone done PDFs? Re: Not limited to HTML, also...

        A domino servlet might do this nicely with the use of the iText package. A Java API for creating PDF's.

        Check it out here.

        http://www.lowagie.com/iText/

        Jon

    2. Re: Not limited to HTML, also Excel, GIF, XML, etc.

      I have use the mime settings to generate a .txt file but it keeps putting these strange blocks with my txt file. Any idear how I can solve that?

    3. Open a Excel file via web..

      I have the excel application lauching via the web with the content-type print statement, but I need to know how to open a specific file. HELP!!!!

  2. Opera???

    Using a Webagent to create a SVG Document... the first printline is of course:

    Print {content-type: image/svg+xml}

    :-) Works fine almost everywhere with the Adobe Pluggin installed... Netscape, IE (except 5.0, there are Plugginissues when you have several parameters behind the "?OpenAgent"), Modzilla... however, the big looser is Opera!

    This browserthing urges for the file-extension, not the mime-type... so the trick does not work...

    Any workaround known?

    Inferno aka Magnus

      • avatar
      • Jake
      • Tue 27 Aug 2002

      Re: Opera???

      Try giving your agent a name that ends in ".svg". Should fool Opera in to submission...

      Jake

      Show the rest of this thread

  3. I am confused with a button

    I write an agent,I want to add a button to the printed page,but how can I do it? I have tried this: Print "<input type='Button' name='b1' onClick='@Command([ToolsRunMacro];'MyAgent''>" It doesn't work! When the page that printed by this agent appear,it have an error like: The compile is closed.How can I do what i just say? Please give me some good ideas!

      • avatar
      • jay
      • Thu 15 May 2003

      Re: I am confused with a button

      even i am stuck with the same sort of problem. i have an agent. the agent generates an html page (also generate a text box in that page). Now i want to catch the value of that textbox in order to do some search. can anyone help in this regard

  4. Extreme Example

    Most of our new website http://www.media1.us uses agents to display webpages with dynamic content. The portfolio section uses one agent that takes parameters and spits out lists of projects to fit the parameters. I'm not sure how this method compares in efficiency to what might be accomplished using categorized views inside of forms, but it was a whole lot easier for me working this way. And it is fun to have this much control over the displayed results.

  5. Problem, how to use field values in this example

    How can you embedd field values in this examle, the + symbol does not work in this case to delimit the field names.

    Rahul

  6. QueryOnEvent

    Hi Jake

    I'm hoping that you or one of the legion of readers out there have discovered the meaning of QueryOnEvent....

    Take a look in the R5 or R6 designer help and perform a search for "Print Statement" At the end of the help text the last sentence reads: "If the request is from the Web, Print will be re-directed to the source. Print can be used to dynamically generate a Web page via QueryOnEvent."

    What is QueryOnEvent? It seems to be an event (I tried using it in an "On Event" statement but received a Type Mismatch")

    Any ideas?

    • avatar
    • shailesh
    • Thu 15 Oct 2009

    File Download Popup Issue...

    used this technic very often but the one problem that i am facing with this is file download popup that appers asking for either Open / Save / Cancel option..Any one know how to avoid this popup ?

    for pdf's , gif's, txt's and jpeg's it works fine ... but not with doc's , xls's.. !

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Agents"

« Previous Article Next Article »
None Found   Debugging LotusScript Agents

About This Article

Author: Jake Howlett
Category: Agents
Hat Tip: Johan Känngård
Keywords: Agent; Print; HTML;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »