Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Jsp页面转换为PDF以及如何进一步保存_Jsp_Core - Fatal编程技术网

如何将Jsp页面转换为PDF以及如何进一步保存

如何将Jsp页面转换为PDF以及如何进一步保存,jsp,core,Jsp,Core,我正在制作一个基于Web的计费系统,在这个系统中,首先我要得到一个由用户填写的表单,然后需要将其转换成PDF。。我正在使用JSP,所以我想问的是,我不知道如何将JSP表单转换为Pdf并保存该Pdf文件?请告诉我如何将该表单转换为pdf格式并保存到用户的计算机中。?您是否浏览过此页面:我正在使用它,但请告诉我主功能中的pdf转换是什么。public static void main(字符串args[]){PDFConversion PDFConversion=new PDFConversion()

我正在制作一个基于Web的计费系统,在这个系统中,首先我要得到一个由用户填写的表单,然后需要将其转换成PDF。。我正在使用JSP,所以我想问的是,我不知道如何将JSP表单转换为Pdf并保存该Pdf文件?请告诉我如何将该表单转换为pdf格式并保存到用户的计算机中。?

您是否浏览过此页面:我正在使用它,但请告诉我主功能中的pdf转换是什么。public static void main(字符串args[]){PDFConversion PDFConversion=new PDFConversion();//PDFConversion.createPdf(“C:/shunmuga/tajmahal.jpg”,“C:/shunmuga/tajmahal.pdf”,true);//对于其他文件PDFConversion.createPdf(“a.html”,“sample.pdf”,false);}}你看到全部代码了吗?这是他在其中定义了
main()
方法的类的名称!哎呀。。。!!我没有通知您我对编码非常陌生……)请再告诉我一件事。我正在将它初始化为一个java类,所以应该用什么代码替换这一行。它显示了一个错误。添加(新段落(org.apache.commons.io.FileUtils.readFileToString(文件));编辑你的问题,请张贴你的代码和错误,准确地告诉你哪里出错。
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);    

}