「java创建pdf」java创建pdf上传服务器
本篇文章给大家谈谈java创建pdf,以及java创建pdf上传服务器对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
怎么用java代码生成pdf文档
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
public class PdfTest
{
public static void main(String[] args) throws Exception
{
Document pdfDoc = new Document();
// 将要生成的 pdf 文件的路径输出流
FileOutputStream pdfFile =
new FileOutputStream(new File("F:/study/test/firstPdf.pdf"));
// pdf 文件中的一个文字段落
Paragraph paragraph = new Paragraph("My first PDF file with an image ...");
Image image = Image.getInstance("F:/study/test/洛克 李.jpg");
// 用 Document 对象、File 对象获得 PdfWriter 输出流对象
PdfWriter.getInstance(pdfDoc, pdfFile);
pdfDoc.open(); // 打开 Document 文档
// 添加一个文字段落、一张图片
pdfDoc.add(paragraph);
pdfDoc.add(image);
pdfDoc.close();
}
}
java创建pdf文件写入不进去
可以用生成PDF报表的Java组件--iText。
具体实现方法如下:1、导入itext-2。1。5。jar跟itextasian-1。5。2。jar两个包到项目里,2、建立一个pdf文件。
一般情况下,iText使用在有以下一个要求的项目中:1。内容无法提前利用:取决于用户的输入或实时的数据库信息。2。由于内容,页面过多,PDF文档不能手动生成。3。文档需在无人参与,批处理模式下自动创建。4。内容被定制或个性化。
Java如何使用Java创建一个空的PDF文档
package com.yiibai;import java.io.IOException;import org.apache.pdfbox.pdmodel.PDDocument;import org.apache.pdfbox.pdmodel.PDPage;// 需要下 apache pdfbox包和apache.commons.loggin乌,下载地址: 和 在本示例中下载使用的是:pdfbox-2.0.7.jar // 将下载的pdfbox-2.0.7.jar添加到Eclipse项目依懒库中。// 右键点击:"java_apache_pdf_box"-"Bulid Path"-"Add External Artchives...",然后选笃下载的"pdfbox-2.0.7.jar"和"commons-logging-1.2.jar"文件 public class CreatingEmptyPdf {
public static void main(String args[]) throws IOException {
// Creating PDF document object
PDDocument document = new PDDocument();
// Add an empty page to it
document.addPage(new PDPage());
// Saving the document
document.save("F:/worksp/javaexamples/java_apache_pdf_box/BlankPdf.pdf");
System.out.println("PDF created");
// Closing the document
document.close();
}}
java创建pdf的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java创建pdf上传服务器、java创建pdf的信息别忘了在本站进行查找喔。