PDFOne (for Java)
Create, edit, view, print & enhance PDF documents and forms in Java SE/EE
Compatibility
J2SE J2EE Windows Linux Mac (OS X)

Create PDF Documents In A JSP Page

Learn to use PDFOne (for Java) in a Java Server Page web application running on a Apache Tomcat server.
By V. Subhash

I am new to JSP but decided to give this a try anyway. First, I had to install the Apache Tomcat Server.

Install Apache Tomcat Server

  1. Installed Oracle JDK.
  2. Created a system-wide environment variable named JAVA_HOME for the JDK installation folder.
  3. Downloaded Apache Tomcat Server for Windows.
  4. Extracted the main Tomcat folder from inside the ZIP archive to my C:\ drive. Installation over.
  5. Created system-wide environment variable CATALINA_HOME with the path to the Tomcat folder.
  6. Created a "Limited User" Windows account and ran bin\startup.bat file using this account. (I am still on XP and my regular account is a full-blown Admnistrator account.)
  7. Tested the default site at http://localhost:8080.

Next, I had to create a JSP script that used PDFOne to create a new PDF document and send it down to the browser.

Create PDFOne (for Java™) JSP Application

  1. Created a new folder named lib in the C:\apache-tomcat-7.0.14\webapps\ROOT\WEB-INF for the PDFOne JAR files.
  2. Copied the following files to the folder.
    1. bcprov-jdk14.jar
    2. PDFOne.jar
    3. pdfonejfont.dll
  3. Stopped and restarted the Tomcat server.
  4. Created a new JSP script at C:\apache-tomcat-7.0.14\webapps\ROOT\test.jsp with the following content.
    <%@page import="com.gnostice.pdfone.PDFOne" %>
    <%@page import="com.gnostice.pdfone.PdfDocument" %>
    <%@page import="com.gnostice.pdfone.fonts.PdfFont" %>
    <%@page import="java.awt.Color" %>
    <%
      // Activate your license
      PDFOne.activate("your-pdfone-activation-key",
                      "your-pdfone-product-key");
      try {
        // Create a new PDF document
        PdfDocument doc = new PdfDocument();
     
        // Access the default font and modify it
        PdfFont defaultFont = doc.getFont();
        defaultFont.setStyle(PdfFont.STROKE_AND_FILL);
        defaultFont.setSize(60);
        defaultFont.setStrokeColor(Color.RED);
        defaultFont.setStrokeWidth(2);
        defaultFont.setColor(Color.YELLOW);
    
        // Prepare the browser
        response.setContentType("application/pdf");
        response.setBufferSize(2000);
    
        // Set PDF version to 1.4 for backward compatibility
        doc.setVersion(PdfDocument.VERSION_1_4);
    
        // Render text on the first page
        doc.writeText("Hello, World!", 100, 100);
    
        // Save the document to the browser
        doc.save(response.getOutputStream());
    
        // Close the document
        doc.close();
    
        // Close the browser output
        response.flushBuffer();
      } catch (Exception e) {
        out.println("Sorry, an error occurred " + e.getMessage() );
      } 
    %>
  5. Accessed the JSP script in a browser.

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.