Silent Print PDF from Browser WAR fileThis 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
No.
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.
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.
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
Back to Top1. 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
PROTOCOL://HOST:PORT/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
If your server not JSP enabled may try ASP or PHP
PROTOCOL://HOST:PORT/silent_print_pdf_from_browser/silent_print_pdf.asp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
Or PHP
PROTOCOL://HOST:PORT/silent_print_pdf_from_browser/silent_print_pdf.php?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]Example (Print PDF):
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
Or (ASP)
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.asp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
Or (PHP)
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.php?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]View PDF
PROTOCOL://HOST:PORT/silent_print_pdf_from_browser/view_pdf.jsp?DOCUMENT=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
Or (ASP)
PROTOCOL://HOST:PORT/silent_print_pdf_from_browser/view_pdf.asp?DOCUMENT=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
Or (PHP)
PROTOCOL://HOST:PORT/silent_print_pdf_from_browser/view_pdf.php?DOCUMENT=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]Example (View PDF):
http://www.activetree.com/silent_print_pdf_from_browser/view_pdf.jsp?DOCUMENT=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.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)
PROTOCOL://HOST:PORT/silent_print_pdf_from_browser/Tutorial
Start page also has a link to the tutorial to learn more about the application.
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:
file:///c:/pdf/sample.pdf or file:/c:/pdf/sample.pdf
file:Macintosh HD/pdf/sample.pdf
file:///tmp/sample.pdf
Examples of typing remote URL:
http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf
https://www.paypal.com/en_US/pdf/PP_Sandbox_UserGuide.pdf
ftp://ftp.eia.doe.gov/pub/oiaf/1605/cdrom/pdf/ggrpt/057306.pdf
Back to Top
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.
http://www.activetree.com/silent_print_report_from_browser/PdfJSPDemo2.jsp
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
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.
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://host:port/silent_print_pdf_from_browser/view_pdf.jsp
Here is an example: http://www.activetree.com/silent_print_pdf_from_browser/view_pdf.jsp?DOCUMENT=[PdfURL]
Pass one or more of these parameters to the view_pdf.jsp.
| Parameter name | Possible values | Details |
| DOCUMENT | String | A string pointing to an existing PDF or an URL that can dynamically generate a PDF document for viewing.
Example: [http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
or a server program produce a PDF dunamically.
If the PDF is generated dynamically from a server program may require parameters. This is how one can add the parameters and values using the standard URL systax.
This is how a PDF viewer URL for such parameterized PDF generator program may be constructed.
|
| PASSWORD | String | Only applicable for those password protected documents. You may or may not pass a value for this parameter. If the document is NOT a password protected a value passed for it will be ignored. |
These examples are pointing to an existing deployment.
| Details | URL |
| Existing PDF | http://www.activetree.com/silent_print_pdf_from_browser/view_pdf.jsp?DOCUMENT=http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf |
| URL that generates a PDF dynamically | http://www.activetree.com/silent_print_pdf_from_browser/view_pdf.jsp?DOCUMENT=http://www.activetree.com/silent_print_report_from_browser/PdfJSPDemo2.jsp |
| Password protected PDF | http://www.activetree.com/silent_print_pdf_from_browser/view_pdf.jsp?DOCUMENT=http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf&PASSWORD=myDocPassword |
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
You call silent_print_pdf.jsp script from this web application with one or more parameters to it.
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).
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[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
http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf from a remote web site.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]
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:
http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf
and
http://www.activetree.com/silent_print_report_from_browser/PdfJSPDemo2.jsp
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf][http://www.activetree.com/silent_print_report_from_browser/PdfJSPDemo2.jsp]
Job name is controlled using JOB_NAME name parameter.
This example is using "PDFPrintJob" is the job name for this parameter.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob
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.
Default value is set to FIT_TO_PRINTABLE_AREA.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&AUTO_ROTATE_AND_CENTER=true
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=NONE&AUTO_ROTATE_AND_CENTER=false
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&AUTO_ROTATE_AND_CENTER=true&PAPER=(612,792)
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&AUTO_ROTATE_AND_CENTER=true&PAPER=(612,792)&AUTO_MATCH_PAPER=true
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&AUTO_ROTATE_AND_CENTER=true&PAPER=(612,792)&AUTO_MATCH_PAPER=true&PASSWORD=myDocPassword
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.
URL_AUTH_PASSWORD - user password for the protected URL.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&AUTO_ROTATE_AND_CENTER=true&PAPER=(612,792)&AUTO_MATCH_PAPER=true&PASSWORD=myDocPassword&URL_AUTH_ID=urlAuthId&URL_AUTH_PASSWORD=urlAuthPassword
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.
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&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
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&PASSWORD=myDocPassword&PRINT_QUALITY=High
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&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
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&JOB_NAME=PDFPrintJob&PAGE_SCALING=FIT_TO_PRINTABLE_AREA&PAPER=(612,792)&AUTO_MATCH_PAPER=true&IS_USE_PRINTER_MARGINS=true
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&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 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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&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
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf][http://www.activetree.com/silent_print_report_from_browser/PdfJSPDemo2.jsp]&SINGLE_PRINT_JOB=true
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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&PASSWORD=myDocPassword&SHOW_PRINT_DIALOG=true
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).
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&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 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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&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 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.
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample1.pdf]&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
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:
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 programSERVER_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.
Examples:
SERVER_CALL_BACK_URL=http://www.activetree.com/silent_print_pdf_from_browser/demo/server.jsp
Complete example:
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample2.pdf]&SERVER_CALL_BACK_URL=http://www.activetree.com/silent_print_pdf_from_browser/demo/server.jsp
- 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.
Examples:
ON_SUCCESS_SHOW_PAGE=http://www.activetree.com/silent_print_pdf_from_browser/demo/success.jsp&ON_SUCCESS_PAGE_TARGET=_blank
Complete example:
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample2.pdf]&SERVER_CALL_BACK_URL=http://www.activetree.com/silent_print_pdf_from_browser/demo/server.jsp&ON_SUCCESS_SHOW_PAGE=http://www.activetree.com/silent_print_pdf_from_browser/demo/success.jsp&ON_SUCCESS_PAGE_TARGET=_blank
- 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.
Examples:
ON_FAILURE_SHOW_PAGE=http://www.activetree.com/silent_print_pdf_from_browser/demo/failure.jsp&ON_FAILURE_PAGE_TARGET=_blank
Complete example:
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample2.pdf]&SERVER_CALL_BACK_URL=http://www.activetree.com/silent_print_pdf_from_browser/demo/server.jsp&ON_FAILURE_SHOW_PAGE=http://www.activetree.com/silent_print_pdf_from_browser/demo/failure.jsp&ON_FAILURE_PAGE_TARGET=_blank
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.
Examples:
IS_SHOW_PRINT_PREVIEW=true&VIEWER_PAGE=view_pdf.jsp&VIEWER_CONTROLS=SILENT_PRINT_BUTTON, SILENT_PRINT_BUTTON, FIRST_PAGE_BUTTON, NEXT_PAGE_BUTTON, PREVIOUS_PAGE_BUTTON, LAST_PAGE_BUTTON, GO_TO_A_PAGE_FIELD, TOTAL_PAGE_LABEL
Complete example:
http://www.activetree.com/silent_print_pdf_from_browser/silent_print_pdf.jsp?DOC_LIST=[http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample2.pdf]&SERVER_CALL_BACK_URL=http://www.activetree.com/silent_print_pdf_from_browser/demo/server.jsp&ON_SUCCESS_SHOW_PAGE=http://www.activetree.com/silent_print_pdf_from_browser/demo/success.jsp&ON_SUCCESS_PAGE_TARGET=_blank&ON_FAILURE_SHOW_PAGE=http://www.activetree.com/silent_print_pdf_from_browser/demo/failure.jsp&ON_FAILURE_PAGE_TARGET=_blank&IS_SHOW_PRINT_PREVIEW=true&VIEWER_PAGE=view_pdf.jsp&VIEWER_CONTROLS=SILENT_PRINT_BUTTON, SILENT_PRINT_BUTTON, FIRST_PAGE_BUTTON, NEXT_PAGE_BUTTON, PREVIOUS_PAGE_BUTTON, LAST_PAGE_BUTTON, GO_TO_A_PAGE_FIELD, TOTAL_PAGE_LABEL
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.
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:
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.
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.
.../silent_print_pdf.jsp?...&ON_MESSAGE_JS_NAME=myJavaScriptMethod&...
Format of the input message
Input message is formatted with minimum of three parameters which one has to parse and extract the content.
Here are some messages received while running demo samples and they are simply displayed in a pane; where JOB_ID=6d12a9 and START, DOC_LIST, DOC_COUNT, PAGE_COUNT, PRINTER_NAME, JOB_STATUS, DURATION, END are commands. Third argument next to the command is the value for the command. All time related values are in milliseconds.
[6d12a9] START [] [6d12a9] DOC_LIST [http://www.activetree.com/silent_print_pdf_from_browser/demo/sample_pdf/sample2.pdf] [6d12a9] DOC_COUNT [1] [6d12a9] PAGE_COUNT [4] [6d12a9] PRINTER_NAME [PDF995] [6d12a9] JOB_STATUS [SUCCESS] [6d12a9] DURATION [1375] [6d12a9] END []JOB_STATUS: Typically the job status will be one of these; PROGRESS, SUCCESS, FAILED, CANCELED.
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.
.../silent_print_pdf.jsp?...&SERVER_CALL_BACK_URL=/demo/server.jsp&...
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
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.
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).
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).
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
Copyright © 2008 Activetree, Inc. All rights reserved.
Web: http://www.activetree.com
Email: sales@activetree.com
Tel: +1 408 716 8414 Fax: +1 408 716 8450