java官方文档中文版pdf(javaapi文档怎么下载)
各位老铁们好,相信很多人对java官方文档中文版pdf都不是特别的了解,因此呢,今天就来为大家分享下关于java官方文档中文版pdf以及javaapi文档怎么下载的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!
java中poi如何将word文档转换成pdf
在Java中使用POI将Word文档转换为PDF需要以下步骤:
添加POI和相关的依赖库,例如:poi-ooxml、poi-ooxml-schemas和itextpdf等。
加载Word文档:
java
InputStream inputStream= new FileInputStream("test.docx");
XWPFDocument document= new XWPFDocument(inputStream);
创建PDF输出流:
java
OutputStream outputStream= new FileOutputStream("test.pdf");
PdfOptions options= PdfOptions.create();
使用POI中提供的方法将Word文档转换为PDF:
scss
PdfConverter.getInstance().convert(document, outputStream, options);
关闭输入输出流:
go
Copy code
inputStream.close();
outputStream.close();
完整代码示例:
java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.converter.pdf.PdfConverter;
public class WordToPDFConverter{
public static void main(String[] args) throws Exception{
InputStream inputStream= new FileInputStream("test.docx");
XWPFDocument document= new XWPFDocument(inputStream);
OutputStream outputStream= new FileOutputStream("test.pdf");
PdfOptions options= PdfOptions.create();
PdfConverter.getInstance().convert(document, outputStream, options);
inputStream.close();
outputStream.close();
}
}
请注意,该方法依赖于操作系统上安装的MS Office软件,因此需要确保系统上安装了MS Office并配置了正确的环境变量。
如何运用Java组件itext生成pdf
首先从iText的官网下载这个开源的小组件。
iText官方网站
Java版iText组件
Java版工具包
C#版iText组件
C#版工具包
这里笔者使用的是Java版itext-5.2.1。
将itext-5.2.1.zip压缩包解压缩后得到7个文件:itextpdf-5.2.1.jar(核心组件)、itextpdf-5.2.1-javadoc.jar(API文档)、itextpdf-5.2.1-sources.jar(源代码)、itext-xtra-5.2.1.jar、itext-xtra-5.2.1-javadoc.jar、itext-xtra-5.2.1-sources.jar
使用5步即可生成一个简单的PDF文档。
复制代码
1// 1.创建 Document对象
2 Document _document= new Document();
3// 2.创建书写器,通过书写器将文档写入磁盘
4 PdfWriter _pdfWriter= PdfWriter.getInstance(_document, new FileOutputStream("生成文件的路径"));
5// 3.打开文档
6 _document.open();
7// 4.向文档中添加内容
8 _document.add(new Paragraph("Hi"));
9// 5.关闭文档
10 _document.close();
复制代码
OK,搞定,不出问题的话就会在你指定的路径中生成一个PDF文档,内容是纯文本的“Hi”。
可是这样并不能完全满足我们的需求,因为通常我们要生成的PDF文件不一定是纯文本格式的,比如我现在要实现打印销售单的功能,那么最起码需要绘制表格才行,怎么办呢?且跟笔者继续向下研究。
在iText中,有专门的表格类,即PdfPTable类。笔者做了一个简单的表格示例,请先看代码:
复制代码
1 OutTradeList _otl= this.getOtlBiz().findOutTradeListById(this.getOtlid());
2 String _fileName= _otl.getOtlId()+".pdf";
3
4// iText处理中文
5 BaseFont _baseFont= BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H", true);
6// 1.创建 Document对象
7 Document _document= new Document(PageSize.A4);
8
9 HttpServletResponse response= ServletActionContext.getResponse();
10 response.setContentType("application/pdf; charset=ISO-8859-1");
11 response.setHeader("Content-Disposition","inline; filename="+ new String(_fileName.getBytes(),"iso8859-1"));
12
13// 2.创建书写器,通过书写器将文档写入磁盘
14 PdfWriter _pdfWriter= null;
15 try{
16 _pdfWriter= PdfWriter.getInstance(_document, response.getOutputStream());
17} catch(Exception e){
18 this.setMessage("单据生成失败,请检查服务器目录权限配置是否正确");
19 e.printStackTrace();
20 System.out.println("2.挂了");
21// return INPUT;
22 return null;
23}
24 if(_pdfWriter== null){
25 this.setMessage("单据生成失败,请检查服务器目录权限配置是否正确");
26 System.out.println("3.挂了");
27// return INPUT;
28 return null;
29}
30
31// 3.打开文档
32 _document.open();
33
34// 4.创建需要填入文档的元素
35 PdfPTable _table= new PdfPTable(4);
36 PdfPCell _cell= null;
37
38 _table.addCell(new Paragraph("单据号", new Font(_baseFont)));
39 _cell= new PdfPCell(new Paragraph(_otl.getOtlId()));
40 _cell.setColspan(3);
41 _table.addCell(_cell);
42
43 _table.addCell(new Paragraph("客户名称", new Font(_baseFont)));
44 _cell= new PdfPCell(new Paragraph(_otl.getClients().getName(), new Font(_baseFont)));
45 _cell.setColspan(3);
46 _table.addCell(_cell);
47
48 _table.addCell(new Paragraph("销售日期", new Font(_baseFont)));
49 _cell= new PdfPCell(new Paragraph(_otl.getOutDate().toString()));
50 _cell.setColspan(3);
51 _table.addCell(_cell);
52
53 _cell= new PdfPCell();
54 _cell.setColspan(4);
55 PdfPTable _tabGoods= new PdfPTable(7);
56//添加标题行
57 _tabGoods.setHeaderRows(1);
58 _tabGoods.addCell(new Paragraph("序号", new Font(_baseFont)));
59 _tabGoods.addCell(new Paragraph("商品名称", new Font(_baseFont)));
60 _tabGoods.addCell(new Paragraph("自定义码", new Font(_baseFont)));
61 _tabGoods.addCell(new Paragraph("规格", new Font(_baseFont)));
62 _tabGoods.addCell(new Paragraph("数量", new Font(_baseFont)));
63 _tabGoods.addCell(new Paragraph("单价", new Font(_baseFont)));
64 _tabGoods.addCell(new Paragraph("小计", new Font(_baseFont)));
65 Object[] _outTrades= _otl.getOutTrades().toArray();
66//将商品销售详细信息加入表格
67 for(int i= 0; i< _outTrades.length;){
68 if((_outTrades[i]!= null)&&(_outTrades[i] instanceof OutTrade)){
69 OutTrade _ot=(OutTrade) _outTrades[i];
70 Goods _goods= _ot.getGoods();
71 _tabGoods.addCell(String.valueOf((++i)));
72 _tabGoods.addCell(new Paragraph(_goods.getName(), new Font(_baseFont)));
73 _tabGoods.addCell(_goods.getUserCode());
74 _tabGoods.addCell(_goods.getEtalon());
75 _tabGoods.addCell(String.valueOf(_ot.getNum()));
76 _tabGoods.addCell(String.valueOf(_ot.getPrice()));
77 _tabGoods.addCell(String.valueOf((_ot.getNum()* _ot.getPrice())));
78}
79}
80 _cell.addElement(_tabGoods);
81 _table.addCell(_cell);
82
83 _table.addCell(new Paragraph("总计", new Font(_baseFont)));
84 _cell= new PdfPCell(new Paragraph(_otl.getAllPrice().toString()));
85 _cell.setColspan(3);
86 _table.addCell(_cell);
87
88 _table.addCell(new Paragraph("操作员", new Font(_baseFont)));
89 _cell= new PdfPCell(new Paragraph(_otl.getProcure()));
90 _cell.setColspan(3);
91 _table.addCell(_cell);
92
93// 5.向文档中添加内容,将表格加入文档中
94 _document.add(_table);
95
96// 6.关闭文档
97 _document.close();
98 System.out.println(_fileName);
99 this.setPdfFilePath(_fileName);
100 System.out.println("3.搞定");
101// return SUCCESS;
102 return null;
复制代码
以上代码是写在 Struts2的 Action中的,当用户发送了请求之后直接将生成的PDF文件用输出流写入到客户端,浏览器收到服务器的响应之后就会询问用户打开方式。
当然,我们也可以将文件写入磁盘等等。
求Java api 1.7的中文文档,要网盘链接
Javaapi1.7的中文文档网盘密码:hjbsJavaapi1.7的中文文档:一、JDK(JavaDevelopmentKit,Java开发包,Java开发工具)是一个写Java的applet和应用程序的程序开发环境。它由一个处于操作系统层之上的运行环境还有开发者编译,调试和运行用Java语言写的applet和应用程序所需的工具组成。二、JDK(JavaDevelopmentKit)是SunMicrosystems针对Java开发员的产品。自从Java推出以来,JDK已经成为使用最广泛的JavaSDK(Softwaredevelopmentkit)。三、JDK中还包括完整的JRE(JavaRuntimeEnvironment,Java运行环境),也被称为privateruntime。包括了用于产品环境的各种库类,以及给开发员使用的补充库,如国际化的库、IDL库。四、JDK包含的基本组件包括:1、javac–编译器,将源程序转成字节码。2、jar–打包工具,将相关的类文件打包成一个文件。3、javadoc–文档生成器,从源码注释中提取文档。4、jdb–debugger,查错工具。
好了,文章到此结束,希望可以帮助到大家。