Click the hyperlink download PDF file, the content of the PDF file with the JSP page data. The essence is a print bar.
If you print a PDF of this template, first load the template, that is, the contents of the template read out.
Pdfreader reader = new Pdfreader ("Simpleregistrationform.pdf");
Set the size of a page
Rectangle rectpagesize = reader.getpagesizewithrotation (1);
Document doc = new document (Rectpagesize, 40, 40, 40, 40);//The remaining 4 parameters, set the page's 4 margins
Emptying response, not doing so sometimes has an impact on the program, because before this may also use the response, if not reset behind the setContentType () may not be valid.
Response.reset ();
setContentType () set file type as PDF
Response.setcontenttype ("Application/pdf");
Set the name of the download file
Response.setheader ("Content-disposition", "attachment; Filename=test.pdf ");
Bytearrayoutputstream BAOs = new Bytearrayoutputstream (); Set font
Basefont font = Basefont.createfont ("heiseimin-w3", "Unijis-ucs2-hw-h",
basefont.not_embedded);
Font font = Fontfactory.getfont (Fontfactory.helvetica, Font.Bold,
Color.Blue);
PDFWriter pw = pdfwriter.getinstance (doc, BAOs);
Doc.open ();
Pdfcontentbyte PCB = Pw.getdirectcontent ();
Join business logic here
Pcb.begintext ();
Pcb.setfontandsize (font, 10);
String page = string.valueof (1);
pcb.showtextaligned (Pdfcontentbyte.align_left, page, 530, 40, 0);
Pcb.endtext ();
Doc.close ();
Send PDF to Client
Baos.writeto (Response.getoutputstream ());
Baos.close ();
The above is the output of the file with the flow of content, than to generate temporary file output should be simpler and faster.