Smart Java RTF - Silent Print and View RTF from Web Browser


This is a web application archive ready for deployment in a web container. This archive is aimed at silent printing and viewing of RTF documents (existing or dynamically generated from a server program) located anywhere in the world.

Back to Top
Does this software require any other third-party software?

This web application is a self sufficient WAR archive and does not require any other third-party software. Simply deploy it and access the start page.

Back to Top
Download silent_print_rtf_from_browser.war

Visit our web site and download this archive. When you click on the download link your browser might prompt to "Save As..." a ".zip" extension which you must change to ".war". Alternatively, you can save first and later rename to change the extension to ".war".

Back to Top
Installing WAR sample

This WAR archive is a self sufficient web application archive ready to be deployed under any web container.

[NOTE: - Let us say the downloaded WAR file is saved as (renamed to): silent_print_rtf_from_browser.war]

Here are some examples of how to deploy Silent Print RTF From Browser WAR (Web Application Archive) archive:

These are not the only web servers to deploy. You can deploy it to any other web server of your choice. These are just examples.
JBoss: Copy to installation/server/default/deploy directory.
Tomcat: Copy it to the installation/webapps/ directory.
BEA WebLogic/IBM WebSphere: Logon to admin console and choose to deploy an existing WAR file which will let you select this WAR file located in any folder.

When web server deploy it will create a directory (called context path) that is the name of the WAR file (excluding the .war part).

Steps: in installing and running silent printing and viewing RTF from browser application

1. Install the WEB (WAR) application
Download this WAR (web application archive), rename it to "silent_print_rtf_from_browser.war", and deploy it under your J2EE web container. Therefore your web context path to the start page is "silent_print_rtf_from_browser".

2. TEST: if your installation is OK.
To test if your installation is ok try to print a sample RTF by simply typing this URL on the location filed on your browser and pressing ENTER key (NOTE: replace PROTOCOL, HOST, and PORT). Examples next to them might also help you.

Print RTF

Example (Print RTF):[]

View RTF

Example (View RTF):

3. Try DEMO Samples
Run demo samples and view the tutorial from your installation. This web application has few demo samples and the link to each of them is in the start page. Sample scripts (e.g. JSP files) are part of the WAR installation in the "demo" directory. Go to your installation and find the "demo" directory under which you will find JSP sample programs.

Now run the demo start page (NOTE: replace PROTOCOL, HOST and PORT)

Start page also has a link to the tutorial to learn more about the application.

Back to Top
Opening DEMO page

Let us say the war archive name is silent_print_rtf_from_browser.war which you have copied to one of the web server location mentioned above. The context path for the application when deployed is silent_print_rtf_from_browser (name of the war file). Type an URL that looks something like:

http://host:port/silent_print_rtf_from_browser/ or

If your web server port is 80 you do not need to type the port number.

Back to Top
Typing the URL of your existing RTF document

Input an URL and does not matter if the document is located in local file system, in a remote web server or a server program that dynamically generate one. An URL with appropriate URL syntax is all that required for printing or viewing it.

Examples of typing a local file URL:

  • Window: file:///c:/rtf/sample.rtf or file:/c:/rtf/sample.rtf
  • Mac OS: file:Macintosh HD/rtf/sample.rtf
  • Unix/Linux: file:///tmp/sample.rtf

    Examples of typing remote URL (these URL may not exist):

  • HTTP:
  • HTTPS:
  • FTP:

    Back to Top
    My RTF is generated dynamically from calling an URL

    It is just like any other URL. Here is an example of a JSP report generation URL generates a report and converts it to a RTF. The output form this URL is therefore a RTF document and can be viewed or silent printed like ant other URL pointing to an existing RTF. You can find this dynamic RTF generation sample in this WAR archive.

    Back to Top
    View RTF in browser window

    Calling the RTF viewer URL with a RTF as argument will display it in the browser window. There are JSP and PHP script files to call for printing or viewing. In this tutorial we will use the JSP script in our examples.

    Back to Top
    RTF viewer URL to call

    Downloaded archive silent_print_rtf_from_browser.war has few JSP scripts to call. For viewing a RTF call view_rtf.jsp.

    Here is how the RTF viewer URL looks like:

    Here is an example:

    Back to Top
    Parameters to the RTF viewer URL

    Pass one or more of these parameters to the view_rtf.jsp.

    Parameter name Possible values Details
    DOCUMENT URL String A string pointing to an existing RTF or an URL that can dynamically generate a RTF document for viewing.
    REMOTE_SAVE_ENABLED "true" or "false" When viewing from browser you can let the viewer show you an additional menu and toolbar button to do a "remote save as..." option. With this operation you can save the opened RTF back by overwriting the same document or save to a persistent store such as a database.

    Value "true" if used you must also specify an URL that will be used by the viewer to call for the "remote save as..." operation using the "REMOTE_SAVE_ACTION_URL". You can also provide arguments to the REMOTE_SAVE_ACTION_URL using REMOTE_SAVE_ACTION_URL_ARGS parameter to the viewer. Viewer actually read both these two parameters and forward them to your "remote save as..." action URL. Both of these two parameters discussed next.

    REMOTE_SAVE_ACTION_URL URL string If REMOTE_SAVE_ENABLED is "true", you must provide an URL which the RTF viewer can call and post the RTF data as byte[]. From your action URL you should read the byte[] data and save it some where in the server side (e.g. as file, in a database etc.). You might need additional parameters such as file name, database name, user name, time, location to save etc. in your remote save as action URL for psisting the data. Put any parameters and values together as one string and pass to the viewer using the "REMOTE_SAVE_ACTION_URL_ARGS" mentioned next.

    In this archive under demo directory we have provided a sample demo_main.jsp and a "REMOTE_SAVE_ACTION_URL" jsp script "demo_uploader.jsp". Therefore this demo "remote save as..." action url will look like:

    REMOTE_SAVE_ACTION_URL_ARGS key value pairs separated by "|" character If you haved enabled the "remote save as..." operation, using this parameter you can pass some parameters and their values to your "remote save as action url" where you can parse and use them for persisting the byte[] of data action URL receive.

    This WAR archive has a demo "demo_main.jsp" which has used two custom parameters for the demo_uploader.jsp demo "remote save as..." url and saves the document back by overwriting the original file in the server.
    view_rtf.jsp receive "REMOTE_SAVE_ACTION_URL_ARGS" value and pass it to the demo demo_uploader.jsp. This argument has two parameters (i) "SAVE_AS_LOCATION" and (ii) "FILE_NAME" which are parsed and used by the demo_uploader.jsp demo to overwrite the changes made by the user in the RTF editor in the browser.

    DEBUG "true" or "false" Set to "true" for seeing debug messages on Java console.

    Back to Top
    RTF viewing examples

    These examples are pointing to an existing deployment.
    Existing RTF
    URL generates RTF dynamically

    Back to Top
    Silent print RTF from browser window

    This web archive lets you 'silent print' an existing RTF or a RTF dynamically generated from an URL to a printer. Learn more next about the parameters with examples about how you can control "silent print" RTF.

    Back to Top
    Silent print URL to call

    You call silent_print_rtf.jsp script from this web application with one or more parameters to it.

    Back to Top
    Silent print examples

    For understanding this web application we'll use silent_print_rtf.jsp script from a deployment in our website. We'll pass one or more parameters to this URL in order to control silent printing. At least one parameter is required which is a RTF document URL.

    Back to Top
    Silent print single RTF

    DOC_LIST is the parameter to use for specifying the RTFs to print. This parameter is always enclosed with a leading "[" and a trailing "]" character. This example is going to silent print an existing RTF from a remote web site.[]

    Back to Top
    Silent print multiple RTF files

    DOC_LIST is still is the parameter name for printing multiple RTF files. Each RTF file must be separated by "[" and "]" characters. In this example URL we are printing two RTF files: and[][]

    Back to Top
    Job name

    Job name is controlled using JOB_NAME name parameter. This example is using "Smart Java RTF" is the job name for this parameter.[]&JOB_NAME=Smart Java RTF

    Back to Top
    Fit to paper

    This is controlled by FIT_TO_PAPER parameter. RTF page area may be different than the paper it is printer. Therefore it is important to turn this flag on so the RTF page content be fit into the paper area and no part be lost. If the RTF page area is smaller than the paper area turning this flag on will result the smaller content be enlarged to fit to the biger area.This example is a value "true" for this flag and the print out will fit into the paper area by enlarging or shrinking the RTF page content. Default value is set to true.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true

    Back to Top
    Paper selection

    PAPER - parameter is used with a paper size value for which should look like "(topMargin, leftMargin, bottomMargin, rightMargin, paperWidth, paperHeight)" in pixels. The paper width and paper height in this parameter must be the width and height of the papers defined in ISO standard. Margin values can be some thing of your choice depending on kind of margin you want to have for the output.

    Example: For NA_LETTER paper it is PAPER=(72,72,72,72,612,792)
    topMargin = 72 pixels
    leftMargin = 72 pixels
    bottomMargin = 72 pixels
    rightMargin = 72 pixels
    paperWidth = 612 pixels
    paperHeight = 792 pixels
    Therefore, the imageable width of the paper is (paperWidth - (leftMargin + rightMargin)) e.g. (612-(72+72))=486 pixels and imageable height of the paper is (paperHeight - (topMargin + bottomMargin)) e.g. (792-(72+72))=648 pixels.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)

    Back to Top
    Password protected RTF

    PASSWORD parameter is used for setting the password. Only one password is supported even when you are printing multiple RTF files. We therefore suggest, if you are printing multiple RTF files where more than one RTF is password protected print one RTF at a time.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&PASSWORD=myDocPassword

    Back to Top
    Print to default printer

    There are no flag to print to a default printer. However, if you want to print to a named printer look for PRINTER_NAME and PRINTER_NAME_SUBSTRING_MATCH parameters next.

    Back to Top
    Print to a particular printer

    PRINTER_NAME and PRINTER_NAME_SUBSTRING_MATCH parameters are used in combination to print to a particular printer identified by a name. PRINTER_NAME value is either full name of the printer or a substring of it. On the other hand PRINTER_NAME_SUBSTRING_MATCH tells whether or not API should look for a printer that is of exact match (value if false) with the string in PRINTER_NAME or API should try to find a printer taking the PRINTER_NAME value and do a substring match (value if true) with all the available printers. If it do not find a matched printer using these two parameters it will print to default printer.

    In this example PRINTER_NAME=HP LaserJet 4200 PCL&PRINTER_NAME_SUBSTRING_MATCH=false used to indicate that an exact match should be performed for finding a printer named "HP LaserJet 4200 PCL". When PRINTER_NAME_SUBSTRING_MATCH=true the first printer found using a substring match will be used even there are other printer name might match this substring.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&PASSWORD=myDocPassword&PRINT_QUALITY=High&PRINTER_NAME=HP LaserJet 4200 PCL&PRINTER_NAME_SUBSTRING_MATCH=false

    Back to Top
    Print quality

    PRINT_QUALITY parameter is used for setting the printout quality. Possible values are High, Normal and Draft. For laser printers this parameter may not make any difference in output quality. It is important for other kinds of printer such as a thermal printer.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&PASSWORD=myDocPassword&PRINT_QUALITY=High

    Back to Top
    Media side to print (e.g. One Side, Duplex)

    SIDE_TO_PRINT parameter is used for this purpose. Possible values are ONE_SIDED, DUPLEX, TUMBLE, TWO_SIDED_LONG_EDGE, or TWO_SIDED_SHORT_EDGE. Actual outcome for this parameter will depend on whether or not the printer supports it. In this example a value of DUPLEX is used with the expectation that the output be printed on both sides of the pages. Duplex mode saves paper and is recommended if your printer support it.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&PASSWORD=myDocPassword&PRINT_QUALITY=High&SIDE_TO_PRINT=DUPLEX

    Back to Top
    Use printer margins

    IS_USE_PRINTER_MARGINS parameter is used for validating the paper size with the printer. A printer might be configured to keep certain amount of margins around the page. RTF content if printed ignoring this margins it might produce the content near the boundary of the paper is cut off. Set this flag to true if you want to use the printer margins, otherwise, set this flag to false. Default value is true.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&IS_USE_PRINTER_MARGINS=true

    Back to Top

    COPIES parameter takes an integer number as the number of copies to be printed. Default value is 1 copy. This example is using COPIES=2 for printing 2 copies.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&IS_USE_PRINTER_MARGINS=true&COPIES=2

    Back to Top
    Collate copies

    COLLATE_COPIES parameter takes boolean true if you want the copies to be collated false otherwise. This is used when printing multiple copies. Default value for this parameter is true.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&IS_USE_PRINTER_MARGINS=true&COPIES=2&COLLATE_COPIES=true

    Back to Top
    Single print job (applicable when printing multiple RTF documents)

    SINGLE_PRINT_JOB parameter takes boolean true if you want all the DOC_LIST documents be printed as one print job, false otherwise. This is used when printing multiple RTF documents. One print job will cause the API to put together pages from all of the RTF documents and print them together as one document. If this flag it set to false it will print each RTF document as one print job post fixed with a number.[][]&SINGLE_PRINT_JOB=true

    Back to Top
    Show print setup dialog (non silent mode)

    SHOW_PRINT_DIALOG parameter can be set to true if you want to select all of these printing parameters from a dialog window, false otherwise. This flag makes the printing non-silent since it will wait for user input before printing. Moreover it will ignore all the parameter values and will use what user select from this dialog. Only parameter API will use from the URL parameters is the PASSWORD value.[]&PASSWORD=myDocPassword&SHOW_PRINT_DIALOG=true

    Back to Top
    Showing print error message dialog (if error occurs)

    SHOW_PRINT_ERROR_DIALOG parameter if true shows a dialog displaying any kind of printing error if any, false otherwise. Error dialog is shown only if there are printing errors. Default value is true. This example set this flag to false so no dialogs are shown. (See DEBUG parameter later in this tutorial to trace the printing debug messages).[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&IS_USE_PRINTER_MARGINS=true&SHOW_PRINT_ERROR_DIALOG=false

    Back to Top
    Enable print status message

    STATUS_UPDATE_ENABLED parameter if true it shows messages in the browser window while printing is happening. Messages such as RTFs to print, total number of pages, printer it is printing to etc. are displayed when printing is in progress. Default value is true. When you run without this parameter it will display messages in the browser window. Set this to false if do not want to see any messages in the browser window.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&IS_USE_PRINTER_MARGINS=true&SHOW_PRINT_ERROR_DIALOG=false&STATUS_UPDATE_ENABLED=false

    Back to Top
    Debug (Output messages to Java console)

    DEBUG parameter if true it shows API debug messages in the Java console window while printing is in progress. This is helpful for the end user as well as developers when trying to print and report a problem if any. This example is using a value false for not recording any debug messages. Default value is set to true.[]&JOB_NAME=Smart Java RTF&FIT_TO_PAPER=true&PAPER=(72,72,72,72,612,792)&IS_USE_PRINTER_MARGINS=true&SHOW_PRINT_ERROR_DIALOG=false&STATUS_UPDATE_ENABLED=false&DEBUG=false

    Back to Top
    III. DEMO Samples in this archive

    This WAR archive contains two demo samples built using the view_rtf.jsp and silent_print_rtf.jsp explained earlier in this tutorial. These demo script files are located under demo directory. In the demo directory there is this demo_main.jsp works as a common page with links to both the demo samples.

    Back to Top
    DEMO-1 (Edit remote web server RTF files and save them back)

    This demo is located under demo directory. This consists of two scripts demo_main.jsp and demo_uploader.jsp.

    - read list of RTF files available in the demo/sample_rtf/ directory. For each of the RTF found in this directory it provides a link for the browser to edit and save them back.
    - It also provides a link to demo-2 (a dynamic RTF creator sample) in the same page.

    In this sample (demo_main.jsp) all parameters are embedded as part of the "silent print" (using silent_print_rtf.jsp) or "view" (using view_rtf.jsp).

    When you "silent print" a RTF using this demo, it will display some messages to the "Printing Status" pane at the bottom of this page (if the STATUS_UPDATE_ENABLED is enabled in this script file).

    Back to Top
    DEMO-2 (Dynamically generating a RTF)

    This demo dynamic_rtf_generation.jsp is located under demo directory. A link to this dynamic RTF generation script is made available to the demo_main.jsp in this demo directory.

    This server program shows how to use RTF report generation model to add report objects, generate a report and convert the report pages to a RTF document for viewing or silent printing from a browser.

    URL to this dynamic RTF generation script:

    Back to Top
    Contact Us

    Copyright © Activetree, Inc. All rights reserved.
    Tel: +1 408-791-8036 Fax: +1 408-716-8450