SAP Community
Products and Technology
Additional Blogs by Members
Create a PDF file using JAVA
Additional Blogs by Members
All community
This category
Blog
Knowledge base
Users
Managed tags
cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Search instead for
Did you mean:
Create a PDF file using JAVA
Former Member
Options
Subscribe to RSS Feed
Mark as New
Mark as Read
Bookmark
Subscribe
Printer Friendly Page
Report Inappropriate Content
04-05-2005
10:17 AM
0
Kudos
Introduction
This weblog presents Java code to create a PDF file to be displayed in EP6 portal using AbstractPortalComponent.
I currently use this solution to convert all my reporting
htmlb
table display to PDFs.
I am going to use
iText's
open source api to create a PDF file.
These apis can also be used to read PDF file. For more information about api check out the site.
www.lowagie.com/iText/.
There is plenty of documentation and example code at this site.
Required Jars:
You can download the following iText jar from
http://www.lowagie.com/iText/download.html
.
servlet.jar, itext-1.2.jar
Steps to create PAR component
Step 1:
Create an
AbstractPortalComponent
using
Eclipse or Netweaver Studio
. Add the above jar (itext-1.2.jar) to PORTAL-INF->lib folder.
Step 2:
Add the following lines to
doContent
method.
public void doContent( IPortalComponentRequest request, IPortalComponentResponse response) { try { //create a document with certain page size Document document = new Document(PageSize.A4); HttpServletResponse res = request.getServletResponse(true); //set the mimetype res.setContentType("application/pdf"); PdfWriter.getInstance(document, res.getOutputStream()); //open the document for adding stuff document.open(); //create a table with 3 columns PdfPTable table = new PdfPTable(3); PdfPCell cell; //add the first row as header cell = new PdfPCell(new Paragraph("Rank")); cell.setBackgroundColor(new Color(34, 90, 141)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Name")); cell.setBackgroundColor(new Color(34, 90, 141)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Points")); cell.setBackgroundColor(new Color(34, 90, 141)); table.addCell(cell); //add the data rows. int flag = 0; Color bg; for (int i = 0; i <= 10; i++) { //alternate colors if (flag == 0) { flag = 1; bg = new Color(204, 204, 255); } else { flag = 0; bg = new Color(255, 255, 255); } cell = new PdfPCell(new Paragraph("1")); cell.setBackgroundColor(bg); table.addCell(cell); cell = new PdfPCell(new Paragraph("Prakash Singh: " + i)); cell.setBackgroundColor(bg); table.addCell(cell); cell = new PdfPCell(new Paragraph("" + (50000 - i * 10) + "")); cell.setBackgroundColor(bg); table.addCell(cell); } document.add(table); document.close(); } catch (Exception e) { } }
Step 3:
Deploy it in portal and run it. You should get the following output.
prakash singh4
Retagging Required
6 Comments
Related Content
How to make futur termination date visible before termination date ?
in
Human Capital Management Q&A
3 hours ago
Demystifying Transformers and Embeddings: Some GenAI Concepts
in
Technology Blogs by SAP
yesterday
NF-e Nota Técnica 2019.001 v1.62 novos campos adicionados à nota fiscal
in
Enterprise Resource Planning Blogs by SAP
yesterday
NF-e Technical Note 2019.001 v1.62: New Fields Added to Nota Fiscal
in
Enterprise Resource Planning Blogs by SAP
yesterday
Default tax code missing when creating a purchase order
in
Supply Chain Management Q&A
yesterday
Popular Blog Posts
Are you there, SAP? It's me, Jelena
Integration Point of MM-FI-SD in SAP ERP
SAP Project System - A ready Reference ( Part 1 )
Top kudoed authors
User
Count
brenton_ocallag
han
1
henrique_pinto
1
View all