Hello,
I have faced a peculiar problem while creating a PDF from a jsp page.
While I am accessing that perticual ( pdf generating) jsp page using
http:// it's OK. Appropriate PDF is generated.
But while accessing that jsp using https:// it is not working. When I am
trying to open the generated pdf file I am getting an error that "File is
damaged".
Here I have attached the code.
Can u give a solution?
<[EMAIL PROTECTED]
import="java.util.*,java.io.*,com.lowagie.text.*,com.lowagie.text.pdf.*,java.awt.Color,
com.ual.Constant.Constants,
com.ual.Constant.CArray, com.ual.Constant.CNDayAsgn,
com.ual.utilities.*, com.ual.Constant.CMTDataEntry,
com.ual.utilities.MTDSN,
com.ual.utilities.DSNParser" errorPage="error.jsp"%>
<%
try{
String nome,cognome;
nome = "abcdddddddddddddddddddddddddddd";
cognome = "defgggggggggggggggg";
response.setContentType("application/pdf");
response.setHeader("Content-Disposition","attachment:filename=abc.pdf");
Document document = new Document();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PdfWriter.getInstance( document, buffer );
document.open();
/*
document.add(new Paragraph(cognome+" "+nome));
*/
BaseFont helvetica = BaseFont.createFont("Helvetica",
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font font = new Font(helvetica, 7, Font.NORMAL);
Font BoldFont = new Font(helvetica, 7, Font.BOLD);
Font hdFont = new Font(helvetica, 9, Font.BOLD);
// Heading
Table hdTable = new Table(1);
hdTable.setWidth(50);
hdTable.setPadding(3);
hdTable.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
hdTable.setBorderWidth(0);
hdTable.setDefaultCellBorder(0);
Cell hdCell = new Cell(new Phrase("ABC Inventory
System\n\nUnique ID: MER-ABC-01-00001\n\n\n",hdFont));
hdTable.addCell(hdCell);
Table table = new Table(4);
table.setWidth(100);
table.setPadding(2);
table.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
// Row 1
Cell cell = new Cell(new Phrase("Responsible For
:",BoldFont));
cell.setColspan(4);
table.addCell(cell);
// Row 2
cell = new Cell(new Phrase("Short Description :
",BoldFont));
cell.add(new Phrase("UNABLE TO INPUT ENGINE NUMBERS INTO
THE WARRANTY SYSTEM.",font));
cell.setColspan(4);
table.addCell(cell);
// row 3 //
// Col 1
cell = new Cell(new Phrase("Priority : ",BoldFont));
cell.add(new Phrase("1",font));
table.addCell(cell);
// Col 2
cell = new Cell(new Phrase("Prioritization :
",BoldFont));
cell.add(new Phrase("Routine",font));
table.addCell(cell);
// Col 3
cell = new Cell(new Phrase("Board Approval :
",BoldFont));
cell.add(new Phrase("Yes",font));
cell.setColspan(2);
table.addCell(cell);
// Col 4
//table.addCell("");
// row 4 //
// Col 1
cell = new Cell(new Phrase("Status : ",BoldFont));
cell.add(new Phrase("On-hold\n\n",font));
cell.add(new Phrase("Status Date : ",BoldFont));
cell.add(new Phrase("12/12/2002",font));
table.addCell(cell);
// Col 2
cell = new Cell(new Phrase("Target Completion Date :
",BoldFont));
cell.add(new Phrase("09/30/2002\n\n",font));
cell.add(new Phrase("Actual Closed Date : ",BoldFont));
cell.add(new Phrase("10/30/2002",font));
table.addCell(cell);
// Col 3
cell = new Cell(new Phrase("Function 1 : ",BoldFont));
cell.add(new Phrase("J8545\n",font));
cell.add(new Phrase("Function 2 : ",BoldFont));
cell.add(new Phrase("WAR001,002 ETC\n",font));
cell.add(new Phrase("Function 3 : ",BoldFont));
cell.add(new Phrase("J8545",font));
cell.setColspan(2);
table.addCell(cell);
// Col 4
//table.addCell("");
// row 5
// Col 1
cell = new Cell(new Phrase("Estimated Start Date :
",BoldFont));
cell.add(new Phrase("03/20/2001\n\n",font));
cell.add(new Phrase("Requesting\n",BoldFont));
cell.add(new Phrase("Org : SFOPP\nName : ANN
LILOYA\nPhone : 4-3003\n\n",font));
cell.add(new Phrase("Expected Benefit $: ",BoldFont));
cell.add(new Phrase("1",font));
table.addCell(cell);
// Col 2
cell = new Cell(new Phrase("Actual Start Date :
",BoldFont));
cell.add(new Phrase("03/26/2001\n\n",font));
cell.add(new Phrase("UAL Impact : ",BoldFont));
cell.add(new Phrase("Cost Reduction\n\n",font));
cell.add(new Phrase("Request Date : ",BoldFont));
cell.add(new Phrase("03/26/2001\n\n",font));
cell.add(new Phrase("Need By Date : ",BoldFont));
cell.add(new Phrase("09/30/2001\n\n",font));
cell.add(new Phrase("Sponsor : ",BoldFont));
cell.add(new Phrase("DANIELLE GRIFFITH",font));
table.addCell(cell);
// Col 3
cell = new Cell(new Phrase("Business Analyst :
\n",BoldFont));
cell.add(new Phrase("Name : Bryan Beck\nStatus :
Analysis\n\n",font));
cell.add(new Phrase("Developer/ Programmer\n",BoldFont));
cell.add(new Phrase("Name : Skytech\nStatus :
Development\n\n",font));
cell.add(new Phrase("Testing Person\n",BoldFont));
cell.add(new Phrase("Name : Skytech\nLevel :\nStatus
:\n\n",font));
cell.add(new Phrase("System Support
Analyst\n",BoldFont));
cell.add(new Phrase("Name :\nStatus :\n\n",font));
cell.add(new Phrase("Database Analyst\n",BoldFont));
cell.add(new Phrase("Name :\nStatus :",font));
cell.setRowspan(2);
table.addCell(cell);
// Col 4
cell = new Cell(new Phrase("Estimated : \n",BoldFont));
cell.add(new Phrase("Effort Hours : 800\nTotal Cost of
Effort$ : 1\n\n",font));
cell.add(new Phrase("Actual\n",BoldFont));
cell.add(new Phrase("Effort Hours : 800\nTotal Cost of
Effort$ : 1\n\n",font));
table.addCell(cell);
// row 6
// Col 1
cell = new Cell(new Phrase("Problem
Description\n",BoldFont));
cell.add(new Phrase("UNABLE TO ENTER ENGINE NUMBER IN
INPUT TO WAR TRANSACTION\n\n",font));
cell.add(new Phrase("Objective/Benefit\n",BoldFont));
cell.add(new Phrase("INCREASE ENGINE WARRANTY
DOLLARS\n\n",font));
cell.add(new Phrase("Proposed Fix\n",BoldFont));
cell.add(new Phrase("ALLOW TO ENTER ENGINE NUMBER IN
INPUT TO WAR TRANSACTION\n\n",font));
cell.add(new Phrase("Additional Comments/Action
Taken\n",BoldFont));
cell.add(new Phrase("No Comments",font));
cell.setColspan(2);
table.addCell(cell);
// Col 2
cell = new Cell(new Phrase("Other System(s)
Affected\n",BoldFont));
cell.add(new Phrase("XYZ System\n\n",font));
cell.add(new Phrase("Database Affected\n",BoldFont));
cell.add(new Phrase("SKYORA\n\n",font));
cell.add(new Phrase("Closing Person\n",BoldFont));
cell.add(new Phrase("Name : John Woo",font));
table.addCell(cell);
// Spanned
cell = new Cell(new Phrase("Attachments\n",BoldFont));
cell.add(new Phrase("No Attachments",font));
cell.setColspan(4);
table.addCell(cell);
document.add(hdTable);
document.add(table);
document.close();
DataOutput output = new DataOutputStream( response.getOutputStream() );
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
}
catch(Exception e)
{
throw new ServletException( "Exception");
}
%>
Thanks & Regards
Barun Chowdhury
Skytechsolutions Pvt. Ltd.
Dial - 2357-5441 ( Extn.- 3028)
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions