Spring PDF Example


  @RequestMapping (value="/pdf" )
  public void pdfCreate(HttpServletResponse response, OutputStream outputStream){

  Document document = new Document();
     
 try {
                  // 파일 출력 -  
   FileOutputStream file = new FileOutputStream(new File("C:/HelloWorld.pdf"));

 // File Write
                  PdfWriter.getInstance(document, file);
         
          // Stream Output
          PdfWriter.getInstance(document, outputStream);
         
          document.open();
          //
          // Create our first paragraph for the pdf document to be
          // created. We also set the alignment and the font of the
          // paragraph.
          //
          String text = "Sample String ";
               
          Paragraph paragraph = new Paragraph(text);
         
          logger.debug("Paragraph Alignment :" + paragraph.getAlignment());
         
          paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
          paragraph.setFont(new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL));
          paragraph.setAlignment(0);

          document.add(paragraph);
         
          float[] tableCount = {10.1f,20.5f};
          // Table
          PdfPTable  table = new PdfPTable(tableCount);
         
          table.setHeaderRows(0);
          UUID id = new UUID(10,10);

          table.setId(id);
          for (int i=0; i <10; i++){
                  table.addCell("Cell " + i);
                  table.addCell(new PdfPCell(new Phrase("Cell 1")));
                  table.addCell(new PdfPCell(new Phrase("Cell 2")));
                  table.addCell(new PdfPCell(new Phrase("Cell 3")));
                  table.addCell(new PdfPCell(new Phrase("Cell 4")));
          }
         
          File readFile = new File("C:/TEMP/Spring3,2.txt");
          document.add(table);
      } catch (DocumentException e) {
          e.printStackTrace();
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } catch (IOException e) {
 e.printStackTrace();
 } finally {
          document.close();
      }
  }

댓글

이 블로그의 인기 게시물

jquery css

Struts2의 작동 원리

JSP/Servlet 한글 깨짐 처리 ?