SmartJPrint - Silent Print and View PDF from Browser

100% pure Java API for PDF Printing, Viewing, Convertion of your existing PDF documents. Convert PDF to documents such as TIFF, Post Script and images such as PNG, BMP, GIF, JPEG/JPG and more.

  NOTE: You DO NOT need any other software to Print, View and Convert your PDF documents from browser. 

  • About
  • Does it require any other third-party software?
  • Download Silent Print PDF from Browser WAR file
  • INSTALL WAR (Estimated time: 30 minutes)
  • Typing the URL of your existing PDF document
  • My PDF is generated dynamically from calling an URL
  • Password protected PDF document
  • View PDF in browser window
  • Silent print PDF from browser window
  • Secure silent printing
  • Job tracking
  • DEMO Samples in this archive

  • About

    This edition of PDF Technology API and this tutorial is aimed for "silent printing and viewing of PDF from browser" (web based PDF printing and viewing). Visit out website for other editions for Server/J2EE and desktop applications. This is a web application archive ready for deployment in a web container. This archive is aimed at silent printing and viewing of PDF 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 PDF From Browser WAR (Web Application Archive) File

    Visit our web site and download "silent print PDF from browser" 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" file.

    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_pdf_from_browser.war]

    Here are some examples of how to deploy Silent Print PDF 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 PDF from browser application

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

    2. TEST: if your installation is OK.
    To test if your installation is ok try to print a sample PDF 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 PDF
    If your server not JSP enabled may try ASP or PHP
    Or PHP

    Example (Print PDF):[]
    Or (ASP)[]
    Or (PHP)[]

    View PDF
    Or (ASP)
    Or (PHP)

    Example (View PDF):[]

    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
    Typing the URL of your existing PDF 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:/pdf/sample.pdf or file:/c:/pdf/sample.pdf
  • Mac OS: file:Macintosh HD/pdf/sample.pdf
  • Unix/Linux: file:///tmp/sample.pdf

    Examples of typing remote URL:

  • HTTP:
  • HTTPS:
  • FTP:

    Back to Top
    My PDF 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 PDF. The output form this URL is therefore a PDF document and can be viewed or silent printed like any other URL pointing to an existing PDF.

    Back to Top
    Password protected PDF document

    It lets you specify a password for those password protected documents. See parameter table next to know more about how to provide password for the PDF URL.

    Back to Top
    View PDF in browser window

    Calling the PDF viewer URL with a PDF 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.

    PDF viewer URL to call

    Downloaded archive silent_print_pdf_from_browser.war has few JSP and PHP scripts to call. For viewing a PDF call are going to use view_pdf.jsp. It requires a minimum of one parameter is the PDF document.

    Here is how the PDF viewer URL looks like: http://myHost:port/myPath/view_pdf.jsp

    Here is a simple example with just the document as argument to the viewer script view_pdf.jsp[PdfURL]

    Back to Top
    Parameters to the PDF viewer URL

    For a PDF viewer the minimum requirement is to pass a DOCUMENT argument whose value is a PDF URL. PASSWORD is yet another parameter if not provided in the URL will be asked by the viewer to enter when it is loaded.

    Back to Top
    PDF viewing examples

    These examples are pointing to an existing deployment.
    Existing PDF
    URL that generates a PDF dynamically
    Password protected PDF

    Back to Top
    (New) Scripting PDF viewer to create custom viewer dynamically

    Learn more in here about how you can create customized PDF viewer of your choice in this viewer tutorial.

    Back to Top
    Silent print PDF from browser window

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

    Back to Top
    Silent print URL to call

    You call silent_print_pdf.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_pdf.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 for silent printing is a PDF document (static or dynamically generated from an URL).

    Here is what it looks like when typing the URL for silent printing.[PDF]

    See the examples next. Back to Top
    Silent print single PDF

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

    Back to Top
    Silent print multiple PDF files

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

    Back to Top
    Job name

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

    Back to Top
    Page Scaling

    This is controlled by PAGE_SCALING parameter. PDF page area may be different than the media printable area. Therefore it is important to set this flag in order to get the desired output. Following are the accepted values:
    - NONE if applied page content is not scaled to fit to the media size and orientation.
    - FIT_TO_PRINTABLE_AREA is used for page content to always get scaled to fit to the media printable area. If the printable area is smaller than the page content it will shrink the page content to fit to the printable area. On the other hand if the media printable area is larger than the page content it will expand the content to fit to the printable area.
    - SHRINK_TO_PRINTABLE_AREA is same as FIT_TO_PRINTABLE_AREA except that if the media printable area is larger than the page content it will not expand the page content to fit to the printable area. Otherwise it will shrink the page content to fit to the media printable area.


    Back to Top
    Auto Rotate and Center

    This is a boolean "true" or "false" flag used to indicate whether or not to automatically rotate and center the document page content to the media printable area. A media printable area may not be of exact match with the document page size. Even if the size of the media is same but the orientation may be different. This flag therefore ensures you to automatically re-orient and center the content to the media printable area if this flag is set to "true". This flag works with the PAGE_SCALING parameter. Value "false" for this flag only effective if the value of PAGE_SCALING parameter is NONE. All other value of page scaling will have no effect on this flag and a value "true" will be used (even if you have set it to "false").

    Default value is set to true.[]&JOB_NAME=PDFPrintJob&PAGE_SCALING=NONE&AUTO_ROTATE_AND_CENTER=false

    Back to Top
    Paper selection

    PAPER - parameter is used with a paper size value for which should look like "(widthInPixel, heightInPixel)". For an NA_LETTER paper it will be PAPER=(612,792) where paper width is 612 pixels and height is 792 pixels.[]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&AUTO_ROTATE_AND_CENTER=true&PAPER=(612,792)

    Back to Top
    Automatic paper matching (Choose paper size by PDF page size)

    AUTO_MATCH_PAPER can be set to true or false. If set to true it will take each PDF page size and find a matched paper size looking into ISO paper size list. If found it will use that paper size, otherwise, it will use the paper size you specify with the PAPER flag. If PDF page size is not matched for auto-paper size match and you have not specified a PAPER size it will use a default paper size. We suggest you provide a default paper size using the PAPER parameter.[]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&AUTO_ROTATE_AND_CENTER=true&PAPER=(612,792)&AUTO_MATCH_PAPER=true

    Back to Top
    Password protected PDF

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

    Back to Top
    Password protected URL

    The document URL (or the URL dynamically producing the document) might be password protected in the web server. Web server therefore requires a access USER NAME and PASSWORD (Note: this is different from document PASSWORD).

    Following parameters are used for accessing the password protected URL:
    URL_AUTH_ID - user name (or ID) for the protected URL.

    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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&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.


    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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&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. PDF 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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&IS_USE_PRINTER_MARGINS=true&COPIES=2&COLLATE_COPIES=true

    Back to Top
    Single print job (applicable when printing multiple PDF 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 PDF documents. One print job will cause the API to put together pages from all of the PDF documents and print them together as one document. If this flag it set to false it will print each PDF 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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&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 PDFs 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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&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=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&IS_USE_PRINTER_MARGINS=true&SHOW_PRINT_ERROR_DIALOG=false&STATUS_UPDATE_ENABLED=false&DEBUG=false

    Back to Top
    Debug Level (Limit output messages)

    DEBUG_LEVEL parameter is responsible for limiting the amount of debug messages. Following are the level names. The order of the level matters. Messages for current level and all higher levels are logged.

    Default value is set to INFO.

    Example (for browser based URL parameter usage):
    This indicated starting from warning to any wrost messages are logged.

    Back to Top
    Detecting and customizing silent print status using DOC_LISTENER

    For monitoring of document loading, viewing, printing and conversion one can add a document listener (com.activetree.common.doc.DocListener). Typically, there is a default implementation of this interface com.activetree.common.doc.DefaultDocListener belong to common library jar smartjcommon. For details look at the smartjcommon online javadoc or download it from website.

    Following methods from the com.activetree.common.doc.DefaultDocListener invoked if you add one. You simply add one more parameter as part of the URL query string; i.e. an instance of DefaultDocListener such as DOC_LISTENER=demo.activetree.pdfprint.PdfDocListener for PDF processing. During procssing of the document various methods available in the DefaultDocListener is called by the runtime.

      //Typically DO NOT override this method.
      public void activityPerformed(DocEvent evt);
      //Methods that you can override.
      //Called when a page of a document is rendered in a document viewer.
      //Applicable for document viewer only.
      protected void pageRenderedForViewer(DocEvent evt, int pageIndex) {}
      //Called when a document page is rendered for creating a thumbnail view.
      //Applicable for document viewer only.
      protected void pageRenderedForThumbnailView(DocEvent evt, int thumbnailIndex) {}
      //Called each time a page of a document is loaded for processing.
      protected void pageLoaded(DocEvent evt, int pageIndex) {}
      //Called to post page count during document processing.
      protected void pageCount(DocEvent evt, int pageCount) {}
      //Called when a page of a document is finished coversion.
      //Applicable for conversion only.
      protected void pageConverted(DocEvent evt, int pageCount) {}
      //Called just before printing of a document is starting passing you the document name it
      //is attempting to print. One can keep track of which document is currently being processed.
      protected void printStarting(DocEvent evt, Object source, String printerName) {}
      //Called when a printable; i.e. a Page is called for rendering to a printer.
      protected void printableCalled(DocEvent evt, int pageIndex) {}
      //Called after each page is printed to a printer so one can keep track of
      //pages printed and which are the pages got printed.
      protected void pagePrinted(DocEvent evt, int pageCount) {}
      //Called when one of the document in the list of document is finished processing.
      protected void printFinished(DocEvent evt, Object source, String printerName) {}
      //Called whenever a particular document have problem in processing. One can keep track of
      //the list of documents may have failed during printing of a multiple document print job.
      protected void docError(DocEvent evt, Object failedDoc, int value, Object details) {}
      //Called when the job is started.
      protected void jobStarted(DocEvent evt, Object docList) {}
      //Called before a Pageable doc is sent to the printer. User can filter out those pages
      //keeping only those needs to be processed.
      protected void filterPageable(DocEvent evt, Object docList) {}
      //Called when job is cancelled by the user.
      protected void jobCancelled(DocEvent evt, Object docList) {}
      //Called when job is finished
      protected void jobFinished(DocEvent evt) {}
    A further custom implementation on this default implementation is the PdfDocListener is available in the downloaded archive under examples.

    When using with browser edition one has to use the DOC_LISTENER=yourCustomDocListener. Following is an example of how to use the DEMO made available in any of the SmartJPrint downloaded archive. You can customize this demo class and add to the DOC_LISTENER=yourCustomDocListener as part of URL. Incase you choose to use your own custom implementation of the DefaultDocListener, remember to edit the "silent_print_pdf.XXX" script to add your custom jar in the "cache_archive" keeping the other jar names.


    Back to Top
    Secure silent print from browser

    Processing a web document may involve crossing many different security parameters before any success to print, view or other processing may take place. While maintaining security of the data is essential, processing them is a requirement. This product has established a framework that enables one not to disclose the access security parameters in advance. They may be provided when the document is attempted to access at run time using a callback server program of your choice.

    If the user is accessing a secured document the callback server program may set them and reply back to the browser client. Security information such as document security password, URL protection ID and password are some of the document authorization parameters may be set through the callback server program.

    In addition to providing document access parameters one may not disclose the actual document location and its identity in advance. Instead, the real document location URL (file etc) may be kept hidden and a ID may be set as the document. Callback server program of choice may set the actual document URL or the byte[] content of the document in the browser client reply map.

    Once a document is silent printed (and/or done viewing) a success page may be shown to the end user. Similarly, a failure page may be shown in case of a failure has happened.

    In summary, one can have complete control over internet document processing by way of:

  • not disclosing the real document in advance,
  • ability to provide the document access information at runtime through the callback server program of choice, and
  • tracking the user access on a document and allowing or denying access to it.
  • How it works?

    Everything start on user hitting a URL on a browser page resulting a call to the callback server program along with all the URL parameters and values submitted to the server. Callback server program has to read the required parameters including the DOCUMENT or DOCL_LIST parameter that identifies the document.

    Next steps are things like:
    - in the server program check if the user is allowed for such access
    - set the document access parameter values such as PASSWORD, URL_AUTH_ID, URL_AUTH_PASSWORD etc.
    - set the DOCUMENT or DOC_LIST parameter value if an ID was used in the browser URL. Content may be set as byte[] after reading it from a source such as database, URL, or other source
    - send the reply back to client for processing it

    You may cancel the job from the server program by simply setting JOB_STATUS to "CANCELED" or "FAILED". Client will read the reply status and process it accordingly.

    A page may be displayed depending on success or failure and if URLs for such action is specified in the URL parameter.

    If one choose to hide the documents real location or its content from the user, may choose to use an ID as the document (e.g. DOC_LIST=[docid-123456]) and set the real content byte[] or document URL during a callback to the server program.

    Demo - there is a demo in the downloaded WAR archive or may run the online silent secure print demo.

    Specifying a callback server program

    SERVER_CALL_BACK_URL - A HREF value (i.e. URL) may be provided for this parameter that will be called at run time. All parameters is going to be made available to the server URL for knowing the document and allow access to it by way of providing all security and other information it might need for its opening. Callback program may simply deny access to this program by not providing the access information or simply setting an empty DOCUMENT or DOC_LIST content to the attribute map it replies back for client.


    Complete example:[]&SERVER_CALL_BACK_URL=

    NOTE: If the custom server callback page takes parameters as part of query string then the entire URL must be enclosed with '[' and ']' characters.


    Showing success page

    - ON_SUCCESS_SHOW_PAGE - parameter may be set to an URL for opening it on successful completion of the task.
    - ON_SUCCESS_PAGE_TARGET - parameter is for setting target; e.g. in a new blank window "_blank", in a new titled window (e.g. a title "Job success window") etc.


    Complete example:[]&ON_SUCCESS_SHOW_PAGE=

    NOTE: If the custom success page takes parameters as part of query string then the entire URL must be enclosed with '[' and ']' characters.


    Showing a failure/error page

    - ON_FAILURE_SHOW_PAGE - parameter may be set to an URL for opening it on failure in processing document.
    - ON_FAILURE_PAGE_TARGET - parameter is for setting target window where the failure page will be opened.


    Complete example:[]&SERVER_CALL_BACK_URL=

    NOTE: If the custom failure page takes parameters as part of query string then the entire URL must be enclosed with '[' and ']' characters.


    End user preview before printing

    You may provide a preview option for user to read and review the document before accepting it for processing. Following parameters used for a preview before processing:
    - IS_SHOW_PRINT_PREVIEW - value is true or false.
    - VIEWER_PAGE - view page; e.g. view_pdf.jsp - name of the viewer page relative to the location of "silent_print_pdf.jsp" page.
    - VIEWER_CONTROLS - The controls one wants the viewer to show during the preview operation. For example, user may want to browse the pages, want to see number of pages and do a silent print it.




    Hiding actual document from an user

    DOCUMENT or DOC_LIST parameter values may be IDs generated at run time from server during constructing these browser URLs. User may not be able to download document by typing the document URL in the browser location field just because the ID is not a physical document exists any where but access to it established by using this framework.

    For example, DOC_LIST=[docid-123456] may be used as part of the URL where the document "docid-123456" is not a real document. On user click to this URL server callback program may access this DOC_LIST and establish the real identify of the actual document and set it. Therefore, real document URL is revealed by replacing the DOCUMENT or DOC_LIST param values this way before returning the reply. If the actual content belong to a database and not from a file or URL, read such content as byte[] and set against the DOCUMENT or DOC_LIST params value.

    Tracking document access

    Typical example may be that a web site has established where it works based on pay per print basis. Provider therefore need to track number of copies printed so far by the user and may reject or deny further printing request based on account balance. For denying a job callback server program can set the JOB_STATUS to CANCELED. On the other hand server program may increase the copies printed counter to number of copies printed this time and this may be done in the on success callback page when called.

    Once can control things such as:

  • number of times the document was opened for reading or printing,
  • copies printed,
  • printer printed to, paper size, orientation, and more.

    Back to Top
    Job/Process tracking

    Several jobs may be processed concurrently from a browser page and each job may include multiple documents (or data source) associated with it. For example, using a java script one may fire a series of call to the "silent print pdf" script. Each URL may have DOC_LIST consists of multiple data source. Each call to the silent print script will launch the job with a unique JOB_ID aimed at monitoring or logging the status.

    Ways to track running jobs

    While the process continues it updates the job status by calling the context message handler posting the message as parameter. Typically a java script in browser page and the server callback URL (if any) is used for tracking. If a server URL is set, it will call it before and after each job. Java script method is also called for posting a message. One may or may not have defined java script to call and also may not specify a server call back URL. One or both of these two may be used to properly control all aspects of the job processing.

    Java Script (client) based job tracking

    In the browser page following java script may be declared to receive messages posted by the on going process. Process will call this default java script method with message as the argument.

         function showMessage(msg) {
           //todo - process the message here; e.g. may show in a pane or track to persist in a server once done.
    One can specify another method name instead of default showMessage(msg) method using ON_MESSAGE_JS_NAME parameter. For example, if you may want to use a java script method name myJavaScriptMethod using following as part of the job URL.


    Format of the input message
    Each posted message is formatted with minimum of three segments and maximum of four. In case of JOB_STATUS and error message if any is posted as the fourth message segment.

  • segment-1: JOB ID - enclosed by '[' and ']'; example: "[6d12a9]".
  • segment-2: STATUS COMMAND - separated by one or more white spaces; e.g. START.
  • segment-3: VALUE - for the STATUS COMMAND; e.g. JOB_STATUS [SUCCESS] - where JOB_STATUS is a command and the value is enclosed next to it using '[' and ']'.
  • segment-4: optionally posted for commands such as JOB_STATUS error message if fails with an exception.
  • Here are some messages received while running demo samples and they are simply displayed in a pane; where JOB_ID is displayed as the very first message segment in [] and START, DOC_LIST, PRINTER_NAME, SINGLE_PRINT_JOB, DOC_COUNT, PAGE_COUNT, JOB_STATUS, DURATION, END are the commands next to the JOB_ID. Third argument next to the command is the value for the command. All time related values are in milliseconds.

    JOB_STATUS: Typically the job status will be one of these; PROGRESS, SUCCESS, FAILED, CANCELED.

    Following are some of the scenarios and the corresponding message posting to showMessage JS (or custom JS method).

    Java Script Messages Posted - when documents successfully processed.

  • Single document in DOC_LIST (with SINGLE_PRINT_JOB=true)

  • Example:[c:/test/pdfs/sample1.pdf]&SINGLE_PRINT_JOB=true
    [ee6681] START []
    [ee6681] DOC_LIST [c:/test/pdfs/sample1.pdf]
    [ee6681] PRINTER_NAME [PDF995]
    [ee6681] SINGLE_PRINT_JOB [true]
    [ee6681] DOC_COUNT [1]
    [ee6681] PAGE_COUNT [4]
    [ee6681] JOB_STATUS [SUCCESS]
    [ee6681] DURATION [2782]
    [ee6681] END []

  • Single document in DOC_LIST (with SINGLE_PRINT_JOB=false)

  • Example:[c:/test/pdfs/sample1.pdf]&SINGLE_PRINT_JOB=false
          [141b571] START []
          [141b571] DOC_LIST [c:/test/pdfs/sample1.pdf]
          [141b571] PRINTER_NAME [PDF995]
          [141b571] SINGLE_PRINT_JOB [false]
          [141b571] DOC_COUNT [1]
          [141b571] CURRENT_DOC [c:/test/pdfs/sample1.pdf]
          [141b571] PAGE_COUNT [4]
          [141b571] JOB_STATUS [SUCCESS]
          [141b571] DURATION [2125]
          [141b571] END []

    Note: the difference between the above two cases (SINGLE_PRINT_JOB value if different). Processing all document pages in a single print job ccompared to processing one document at a time as one print job. When SINGLE_PRINT_JOB=false, CURRENT_DOC, PAGE_COUNT and JOB_STATUS is posted for each document. For SINGLE_PRINT_JOB=true, CURRENT_DOC is not applicable and PAGE_COUNT, JOB_STATUS messages are posted and applicable for all documents in the DOC_LIST.

  • Multiple documents in DOC_LIST (with SINGLE_PRINT_JOB=true)

  • Example:[c:/test/pdfs/sample1.pdf][c:/test/pdfs/sample2.pdf]&SINGLE_PRINT_JOB=true
          [2f0df1] START []
          [2f0df1] DOC_LIST [c:/test/pdfs/sample1.pdf][c:/test/pdfs/sample2.pdf]
          [2f0df1] PRINTER_NAME [PDF995]
          [2f0df1] SINGLE_PRINT_JOB [true]
          [2f0df1] DOC_COUNT [2]
          [2f0df1] PAGE_COUNT [8]
          [2f0df1] JOB_STATUS [SUCCESS]
          [2f0df1] DURATION [3031]
          [2f0df1] END []

    NOTE: an overall PAGE_COUNT and JOB_STATUS message is posted when all documents processed as one print job.
  • Multiple documents in DOC_LIST (with SINGLE_PRINT_JOB=false)

  • Example:[c:/test/pdfs/sample1.pdf][c:/test/pdfs/sample2.pdf]&SINGLE_PRINT_JOB=false
          [18e18a3] START []
          [18e18a3] DOC_LIST [c:/test/pdfs/sample1.pdf][c:/test/pdfs/sample2.pdf]
          [18e18a3] PRINTER_NAME [PDF995]
          [18e18a3] SINGLE_PRINT_JOB [false]
          [18e18a3] DOC_COUNT [2]
          [18e18a3] CURRENT_DOC [c:/test/pdfs/sample1.pdf]
          [18e18a3] PAGE_COUNT [4]
          [18e18a3] JOB_STATUS [SUCCESS]
          [18e18a3] CURRENT_DOC [c:/test/pdfs/sample2.pdf]
          [18e18a3] PAGE_COUNT [4]
          [18e18a3] JOB_STATUS [SUCCESS]
          [18e18a3] DURATION [2954]
          [18e18a3] END []

    NOTE: for SINGLE_PRINT_JOB=false; each document status is shown separately with the CURRENT_DOC followed by its PAGE_COUNT and JOB_STATUS.

    Java Script Messages Posted in error cases - when documents may not exists or other runtime errors caused FAILURE.

  • One non-existing document in DOC_LIST (SINGLE_PRINT_JOB=true)
  • Example:[c:/test/pdfs/sample1.pdfx][c:/test/pdfs/sample2.pdfx]&SINGLE_PRINT_JOB=false
          [ef137d] START []
          [ef137d] DOC_LIST [c:/test/pdfs/sample1.pdfx]
          [ef137d] PRINTER_NAME [PDF995]
          [ef137d] SINGLE_PRINT_JOB [true]
          [ef137d] DOC_COUNT [1]
          [ef137d] PAGE_COUNT [0]
          [ef137d] JOB_STATUS [FAILED] [[c:/test/pdfs/sample1.pdfx] [NOT_FOUND]]
          [ef137d] DURATION [312]
          [ef137d] END []

    NOTE: the forth message segment in the JOB_STATUS; i.e. "[c:/test/pdfs/sample1.pdfx] [NOT_FOUND]" is about what caused the JOB_STATUS to FAILED state.

  • One non existing document in DOC_LIST (SINGLE_PRINT_JOB=false)

  • Example:[c:/test/pdfs/sample1.pdfx]&SINGLE_PRINT_JOB=false
          [ef137d] START []
          [ef137d] DOC_LIST [c:/test/pdfs/sample1.pdfx]
          [ef137d] PRINTER_NAME [PDF995]
          [ef137d] SINGLE_PRINT_JOB [false]
          [ef137d] DOC_COUNT [1]
          [ef137d] CURRENT_DOC [c:/test/pdfs/sample1.pdfx]
          [ef137d] PAGE_COUNT [0]
          [ef137d] JOB_STATUS [FAILED] [[c:/test/pdfs/sample1.pdfx] [NOT_FOUND]]
          [ef137d] DURATION [250]
          [ef137d] END []

  • Two non-existing documents in DOC_LIST (SINGLE_PRINT_JOB=false)
  • Example:[c:/test/pdfs/sample1.pdfx][c:/test/pdfs/sample2.pdfx]&SINGLE_PRINT_JOB=false
      [b533b8] START []
      [b533b8] DOC_LIST [c:/test/pdfs/sample1.pdfx][c:/test/pdfs/sample2.pdfx]
      [b533b8] PRINTER_NAME [PDF995]
      [b533b8] SINGLE_PRINT_JOB [false]
      [b533b8] DOC_COUNT [2]
      [b533b8] CURRENT_DOC [c:/test/pdfs/sample1.pdfx]
      [b533b8] PAGE_COUNT [0]
      [b533b8] JOB_STATUS [FAILED] [[c:/test/pdfs/sample1.pdfx] [NOT_FOUND]]
      [b533b8] CURRENT_DOC [c:/test/pdfs/sample2.pdfx]
      [b533b8] PAGE_COUNT [0]
      [b533b8] JOB_STATUS [FAILED] [[c:/test/pdfs/sample2.pdfx] [NOT_FOUND]]
      [b533b8] DURATION [421]
      [b533b8] END []

    Example: Tracking silent print job finish status

    Following JavaScript code if added to the tracking page (page where showMessage (or your custom java script method) is located) you can easily detect the silent print job finishing status. In most cases this is a requirement in order to be able to close a window if a new window is used, tracking if printing was a success or a failure (if failed reason for failure), copies printed, printer name, documents printed and so on.

    You may accumulate all messages in the showMessage itself or in checkJobCompletionStatus in a variable and use that when the printing is done; for example to log the status in a server.

    //This code segments are tipically be added in the page header section just like the way existing
    //showMessage is added in existing demo and silent print script pages.
    function showMessage(msg) {
      //....existing implementation....
      //you may keep existing impl here depending on your needs
      //then do some custom message handling for job status, printer printed,
      //copies, document print etc.
      //add custom code here
    //Following JavaScript code is looking for "JOB_STATUS" string in the received messages
    //passed from the "silent print".
    //Java script codes similar to this one here may be used for similar detection from
    //your own custom JavaScript methods called from here.
    var str_to_find='JOB_STATUS';
    var success_msg='SUCCESS';
    var failure_msg='FAILED';
    function checkJobCompletionStatus(msg) {
       if(msg != '') {
    //     alert(msg);
         var idx=msg.indexOf(str_to_find);
         if (idx >= 0) {
           var str_len=str_to_find.length;
    //       alert('idx=' + idx);
           var rem_msg = msg.substring(idx+str_len);
    //       alert('rem_msg='+rem_msg);
           var idx2 = rem_msg.indexOf(success_msg);
           if (idx2 >= 0) {
             var job_status=rem_msg.substring(idx2);
    //         alert('job_status='+ job_status);
           }else {
             var idx3=rem_msg.indexOf(failure_msg);
             var fail_msg='';
             if (idx3 >= 0) {
             }else {
    function silent_print_successful() {
      //uncomment next alert line to see the success detection
      //alert('silent print - successful!');
      //TODO -- close window/log message and/or some other custom actions
    function silent_print_failed(fail_msg) {
      //uncomment next alert line to see the failure detection; failure can be
      //easily produce typing a non-existing document in the DOC_LIST
      //alert('silent print failed - ' + fail_msg);
      //TODO - close window/log message and/or some other actions

    Server based job tracking

    If there is a SERVER_CALL_BACK_URL is specified in the job URL (shown next) it will call the server page before job starts and after each job ends. Status may be captured at the end of the job.


    There is an example in the downloaded archive demo/server.jsp may be used as a demo server call back URL. Parameters passed to the server URL as a query string consists of key=value pairs separated by & character just like the way an URL is formed. Server will parse these parameters using the query string.

    Back to Top
    DEMO Samples in this archive

    This WAR archive contains few demo samples built using the view_pdf.jsp and silent_print_pdf.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 (Parameter values embedded with the URL)

    This demo is located under demo directory. Calling demo1.jsp from this directory location will show content of this demo. Alternatively, you can open the demo_main.jsp in the demo directory which has a link pointing to this demo1.jsp.

    You'll see:
    - A clickable link pointing to an existing PDF. Click on the Silent Print to print the PDF silently. Click on the View link to open the PDF in a new browser window.
    - A user enterable field that lets you enter a PDF URL of your choice for print or view.

    In this sample (demo1.jsp) all parameters are embedded as part of the "silent print" (silent_print_pdf.jsp) or "view" (view_rtf.jsp) URL explained earlier. With the help of javascript in this page parameters are accessed and an URL is constructed and submitted to silent_print_pdf.jsp or view_pdf.jsp.

    When you "silent print" a PDF 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 (User select parameter values)

    This demo is located under demo directory. Calling demo2.jsp from this directory location will show content of this demo. Alternatively, you can open the demo_main.jsp in the demo directory that has a link pointing to demo2.jsp.

    You'll see:
    - A user enterable field for you to enter a PDF URL of your choice.
    - A multiple selection list box with some PDF URL links. Select one or more PDF from here.
    - "Printing Options" pane contains many of the printing parameters mentioned earlier in this tutorial. Select, enter or change one or more of these parameters to change the printing behavior.
    - Hit the "Print Selected PDF Documents" button for printing.

    Specialty with this sample is that user can select the printing parameters instead you embed (hard code) them in the "silent print" (silent_print.jsp) or "view" (view_pdf.jsp) URL.

    When you "silent print" a PDF 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-3 (Silent print or View PDF byte[] content)

    This demo shows how to silent print and view dynamically generated PDF from browser - e.g. InputStream, Database or PDF byte[] content from other source which can not be referred as an URL directly from the browser. Instead they can be accessed through a server program (i.e. an URL) in order to access those kind of PDFs.

    This requires you to write a server program to dynamically generated the PDF content and write it back to the browser. This still is no different than above two examples just because it is indeed an URL and an URL is all that the API needs.

    Examples: Typical example may be that you have a FORM requires data to be feed to it and then generate a PDF. Document content may be stored in a database which you can refer as an existing PDF but you need a server program like this one to retrieve the content and write back to browser. The same is true for every other case when your document is NOT an already existing one.

    Back to Top
    Contact Us

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