Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in create PDF using iText  RSS feed

 
Cs Jun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all
I got a problem when I using two file to create PDF file for printing.
I used two file. One is used to generate the PDF file, another one has a link pointing to the former jsp file. But I found the PDF file had some errors, which caused the PDF file could not display in the Acrobat Reader 5.
So I post the code here. Could anyone help me ???
<%@
page import=" java.io.*,
java.awt.Color,
com.lowagie.text.*,
com.lowagie.text.pdf.* "
%>
<%

// Create the PDF DOC

response.setContentType( "application/pdf" );
response.setHeader("Content-disposition", "attachment; filename=out.pdf");
String lineSep = java.lang.System.getProperty("line.separator");
System.out.println("Starting printdoc......");
com.lowagie.text.Document document = new Document(PageSize.A4);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
com.lowagie.text.pdf.PdfWriter.getInstance( document, buffer );

document.open();
//table with 2 columns, no need to specify the row number
com.lowagie.text.Table aTable = new Table(2);
aTable.setAutoFillEmptyCells(true);
aTable.setBorderWidth(0.1f);
aTable.setBorderColor(java.awt.Color.white);

com.lowagie.text.Cell emptyCell = new Cell(" ");
emptyCell.setColspan(2);

aTable.addCell(emptyCell);
com.lowagie.text.Cell cell = new Cell("Name of Bank");
cell.setColspan(2);
aTable.addCell(cell);

aTable.addCell("Please debit my account number");
aTable.addCell("number");
aTable.addCell(emptyCell);

aTable.addCell("Branch code/Sort code:");
aTable.addCell("branch");
aTable.addCell(emptyCell);

document.add(aTable);

document.close();

byte[] bytes = buffer.toByteArray();

response.setContentLength(bytes.length);
for( int i = 0; i < bytes.length; i++ )
{ output.writeByte( bytes[i] ); }
System.out.println("End of the printing");
output.close();

%>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!