2013-04-21 103 views
0

我正在製作Web基礎結算系統,首先我要獲取用戶填寫的表單,然後需要將其轉換爲PDF ..我正在使用JSP SO我想問的是我不知道如何將JSP表單轉換爲PDF並保存該PDF文件?請告訴我如何將PDF格式轉換成PDF格式並保存到用戶機器中?如何將Jsp頁面轉換爲PDF以及如何將其保存更多

+0

你衝浪這樣的:HTTP://www.coderanch.com/t/528357/open-source/convert-jsp-form-pdf-file – NINCOMPOOP 2013-04-21 13:18:59

+0

我的工作有了它,但我的電話是什麼PDF轉換主要功能。 public static void main(String args []) { PDFConversion pdfConversion = new PDFConversion(); //pdfConversion.createPdf("C:/shunmuga/tajmahal.jpg「,」C:/shunmuga/tajmahal.pdf「,true);對於其他文件 pdfConversion.createPdf(「a.html」,「sample.pdf」,false); } } – Rojar 2013-04-21 13:31:33

+0

您是否看到過整個代碼?這是他定義'main()'方法的類的名字! – NINCOMPOOP 2013-04-21 13:34:46

回答

0
package com.sample.pdfconvertor;  
import com.lowagie.text.Document;  
import com.lowagie.text.Paragraph;  
import com.lowagie.text.pdf.PdfWriter;  
import java.io.File;  
import java.io.FileOutputStream;  
public class PDFConversion  
{  
/** 
    * This method is used to convert the given file to a PDF format 
    * @param inputFile - Name and the path of the file 
    * @param outputFile - Name and the path where the PDF file to be saved 
    * @param isPictureFile 
    */ 

    private void createPdf(String inputFile, String outputFile, boolean isPictureFile)  
    {  
    /** 
    * Set the page size for the image 
    */ 
    Rectangle pageSize = new Rectangle(2780, 2525);  
    Document pdfDocument = new Document(pageSize);  
    String pdfFilePath = outputFile;  

    try  
    {  
     FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);  

     PdfWriter writer = null;  

     writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);  

     writer.open();  

     pdfDocument.open();  

     /** 
     * Proceed if the file given is a picture file 
     */ 

     if (isPictureFile)  
     {  
      pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));  
     }  

     /** 
     * Proceed if the file given is (.txt,.html,.doc etc) 
     */ 

     else  
     {  
      File file = new File(inputFile);  
     pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));  

     }  

     pdfDocument.close();  

     writer.close();  
    }  
    catch (Exception exception)  
    {  
    System.out.println("Document Exception!" + exception);  
    }  

}  


public static void main(String args[])  
{  

    PDFConversion pdfConversion = new PDFConversion();  

    //pdfConversion.createPdf("C:/shunmuga/tajmahal.jpg", "C:/shunmuga/tajmahal.pdf", true);  


    // For other files  

    pdfConversion.createPdf("a.html","sample.pdf", false);  

}  
相關問題