java8pdf的简单介绍

博主:adminadmin 2022-11-26 01:20:10 73

今天给各位分享java8pdf的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求《java8实战》全文免费下载百度网盘资源,谢谢~

《java8实战》百度网盘pdf最新全集下载:

链接:

?pwd=xr28 提取码: xr28

简介:Java 8的发布使Java程序设计发生了翻天覆地的变化。利用Java 8中新引入的函数式特性,你可以在更短的时间内用更简洁的代码完成更复杂的功能,同时还能充分利用硬件的多核架构。  

java 如何读取PDF文件内容

import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStreamWriter;

import java.io.Writer;

import java.net.MalformedURLException;

import java.net.URL;

import org.pdfbox.pdmodel.PDDocument;

import org.pdfbox.util.PDFTextStripper;

public class PdfReader {

public void readFdf(String file) throws Exception {

// 是否排序

boolean sort = false;

// pdf文件名

String pdfFile = file;

// 输入文本文件名称

String textFile = null;

// 编码方式

String encoding = "UTF-8";

// 开始提取页数

int startPage = 1;

// 结束提取页数

int endPage = Integer.MAX_VALUE;

// 文件输入流,生成文本文件

Writer output = null;

// 内存中存储的PDF Document

PDDocument document = null;

try {

try {

// 首先当作一个URL来装载文件,如果得到异常再从本地文件系统//去装载文件

URL url = new URL(pdfFile);

//注意参数已不是以前版本中的URL.而是File。

document = PDDocument.load(pdfFile);

// 获取PDF的文件名

String fileName = url.getFile();

// 以原来PDF的名称来命名新产生的txt文件

if (fileName.length() 4) {

File outputFile = new File(fileName.substring(0, fileName

.length() - 4)

+ ".txt");

textFile = outputFile.getName();

}

} catch (MalformedURLException e) {

// 如果作为URL装载得到异常则从文件系统装载

//注意参数已不是以前版本中的URL.而是File。

document = PDDocument.load(pdfFile);

if (pdfFile.length() 4) {

textFile = pdfFile.substring(0, pdfFile.length() - 4)

+ ".txt";

}

}

// 文件输入流,写入文件倒textFile

output = new OutputStreamWriter(new FileOutputStream(textFile),

encoding);

// PDFTextStripper来提取文本

PDFTextStripper stripper = null;

stripper = new PDFTextStripper();

// 设置是否排序

stripper.setSortByPosition(sort);

// 设置起始页

stripper.setStartPage(startPage);

// 设置结束页

stripper.setEndPage(endPage);

// 调用PDFTextStripper的writeText提取并输出文本

stripper.writeText(document, output);

} finally {

if (output != null) {

// 关闭输出流

output.close();

}

if (document != null) {

// 关闭PDF Document

document.close();

}

}

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

PdfReader pdfReader = new PdfReader();

try {

// 取得E盘下的SpringGuide.pdf的内容

pdfReader.readFdf("E://SpringGuide.pdf");

} catch (Exception e) {

e.printStackTrace();

}

}

}

《OnJava8》pdf下载在线阅读,求百度网盘云资源

《On Java 8》(Bruce Eckel)电子书网盘下载免费在线阅读

资源链接:

链接:

 提取码:aeh1    

书名:On Java 8

作者:Bruce Eckel

豆瓣评分:9.3

出版社:MindView LLC

出版年份:2017-6

内容简介:NOTE: Although the book refers to the web site , that site is not yet live.

The examples are freely available at .

On Java 8 is only available as an eBook, and only via Google Play Books. Any other source or delivery mechanism is illegitimate.

This book is far too large to publish as a single print volume, and my intent has always been to only publish it as an eBook. Color syntax highlighting for code listings is, alone, worth the cost of admission. Searchability, font resizing or text-to-voice for the vision-impaired, the fact you can always keep it with you---there are so many benefits to eBooks it's hard to name them all.

Anyone buying this book needs a computer to run the programs and write code, and the eBook reads nicely on a computer (I was also surprised to discover that it even reads tolerably well on a phone). However, the best reading experience is on a tablet computer. Tablets are inexpensive enough you can now buy one for less than you'd pay for an equivalent print version of this book (which, note, does not exist). It's much easier to read a tablet in bed (for example) than trying to manage the pages of a physical book, especially one this big. When working at your computer, you don't have to hold the pages open when using a tablet at your side. It might feel different at first, but I think you'll find the benefits far outweigh the discomfort of adapting.

I've done the research, and Google Play Books provides a very nice reading experience on every platform, including Linux and iOS devices. As an experiment, I've decided to try publishing exclusively through Google Books.

The free sample includes a complete table of contents.

作者简介:Bruce Eckel is the author of the multi-award-winning books Thinking in Java and Thinking in C++.

怎么用java动态生成pdf文档

Flying-Saucer + iText + Velocity

1. 第一步

将jar包放到你的工程里,需要的jar如下:

bcprov-jdk15-140.jar

core-renderer.jar

iText-2.0.8.jar

iTextAsian.jar

velocity-1.4.jar

Jar包下载地址:

2. 第二步

设计模版,进行排版调整样式,css样式也可以导入@import 等,通过Velocity模版引擎动态替换 页面内容,以下是模版内容:

?xml version="1.0" encoding="UTF-8" ?

html

head

meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /

titlePDF模版/title

style type="text/css"

!--

body {

font: 100% Verdana, Arial, Helvetica, sans-serif;

margin: 0;

padding: 0;

text-align: center;

color: #000000;

}

.oneColLiqCtrHdr #container {

width: 100%;

margin: 0 auto;

text-align: left;

}

div.header-left {display: none}

div.header-right {display: none}

div.footer-left {display: none}

div.footer-right {display: none}

java怎么输出pdf格式的文件

java导出pdf需要用到iText库,iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf

的文档,而且可以将XML、Html文件转化为PDF文件。

iText的安装非常方便,下载iText.jar文件后,只需要在系统的CLASSPATH中加入iText.jar的路径,在程序中就可以使用

iText类库了。

代码如下:

public class createPdf {

//自己做的一个简单例子,中间有图片之类的

//先建立Document对象:相对应的 这个版本的jar引入的是com.lowagie.text.Document

Document document = new Document(PageSize.A4, 36.0F, 36.0F, 36.0F, 36.0F);

public void getPDFdemo() throws DocumentException, IOException{

//这个导出用的是 iTextAsian.jar 和iText-2.1.3.jar 属于比较老的方法。 具体下在地址见:

//首先

//字体的定义:这里用的是自带的jar里面的字体

BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);

// 当然你也可以用你电脑里面带的字体库

//BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

//定义字体 注意在最新的包里面 颜色是封装的

Font fontChinese8 = new Font(bfChinese, 10.0F, 0, new Color(59, 54, 54));

//生成pdf的第一个步骤:

//保存本地指定路径

saveLocal();

document.open();

ByteArrayOutputStream ba = new ByteArrayOutputStream();

// PdfWriter writer = PdfWriter.getInstance(document, ba);

document.open();

//获取此编译的文件路径

String path = this.getClass().getClassLoader().getResource("").getPath();

//获取根路径

String filePath = path.substring(1, path.length()-15);

//获取图片路径 找到你需要往pdf上生成的图片

//这里根据自己的获取的路径写 只要找到图片位置就可以

String picPath = filePath +"\\WebContent" +"\\images\\";

//往PDF中添加段落

Paragraph pHeader = new Paragraph();

pHeader.add(new Paragraph(" 你要生成文字写这里", new Font(bfChinese, 8.0F, 1)));

//pHeader.add(new Paragraph("文字", 字体 可以自己写 也可以用fontChinese8 之前定义好的 );

document.add(pHeader);//在文档中加入你写的内容

//获取图片

Image img2 = Image.getInstance(picPath +"ccf-stamp-new.png");

//定义图片在文档中显示的绝对位置

img2.scaleAbsolute(137.0F, 140.0F);

img2.setAbsolutePosition(330.0F, 37.0F);

//将图片添加到文档中

document.add(img2);

//关闭文档

document.close();

/*//设置文档保存的文件名

response.setHeader("Content-

disposition", "attachment;filename=\""+ new String(("CCF会员资格确认

函.pdf").getBytes("GBK"),"ISO-8859-1") + "\"");

//设置类型

response.setContentType("application/pdf");

response.setContentLength(ba.size());

ServletOutputStream out = response.getOutputStream();

ba.writeTo(out);

out.flush();*/

}

public static void main(String[]args) throws DocumentException, IOException{

createPdf pdf= new createPdf();

pdf.getPDFdemo();

}

//指定一个文件进行保存 这里吧文件保存到D盘的text.pdf

public void saveLocal() throws IOException, DocumentException{

//直接生成PDF 制定生成到D盘test.pdf

File file = new File("D:\\text2.pdf");

file.createNewFile();

PdfWriter.getInstance(document, new FileOutputStream(file));

}

}

java生成pdf

从JAVA直接读取EXCEL、WORD并生成PDF文件

1。操作EXCEL和WORD文件

使用JAVA从EXCEL、WORD文件中读写数据,可以使用 提供的JAVA API-Java Excel API,这里有其指南 ,可由此下载JAR文件 。

此API提供所有的读、写、修改、建立的功能。对于一般应用足够了。在任何支持JAVA的系统上使用。目前,JExcelApi尚不支持有关chart、graph 或者 macro的信息,但是会拷贝并保留这些信息。只支持PNG图像。

2。生成PDF文件

若从JAVA生成PDF文件,可以使用 提供的应用程序库jPDFWriter。jPDFWriter是一个类库,可以直接从JAVA的应用程序调用以产生PDF文件。其网站的下载文件中包含了说明和例子,有兴趣可以仔细研究。

3。把JExcelAPI和jPDFWriter结合起来,就可以在应用中直接把XLS文件转换成PDF文件。如果再结合Database,就可以直接把有关的报告数据生成XLS文件的同时生成PDF文件。

下边给出了一个例子,是针对XLS,虽然简单,但是完整,以此为基础,可以按照自己的需要展开工作了。对于WORD也是一样,所有不再另给了。

//

//Compile:

//javac -classpath .;jexcelapi/jxl.jar;jPDFWriter/jPDFWriter.jar xlsPrinter.java

//Run:

//java -classpath .;jexcelapi/jxl.jar;jPDFWriter/jPDFWriter.jar xlsPrinter

//

//

import java.awt.Graphics;

import java.awt.print.PageFormat;

import java.awt.print.Printable;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

import java.io.File;

import java.util.Vector;

import java.util.Date;

import jxl.*;//JExcelAPI

import com.qoppa.pdfPrinter.PDFPrinterJob;//jPDFWriter

public class xlsPrinter implements Printable

{

private int m_CurrentPage;

private int m_CurrentPageStartRow;

private int m_CurrentPageEndRow;

private final static int DEFAULT_COLUMN_WIDTH = 72;

private final static int CELL_MARGIN_X = 4;

private final static int CELL_MARGIN_Y = 4;

private Vector m_Data;

private int m_ColumnWidths [];

private boolean m_DrawGrid;

/**

* @param printString

*/

public xlsPrinter(Vector data, int [] colWidths, boolean drawGrid)

{

super();

m_Data = data;

m_ColumnWidths = colWidths;

m_DrawGrid = drawGrid;

}

//读取EXCEL数据并存入内存

private static Vector initData ()

{

Vector data = new Vector ();

try{

Workbook workbook = Workbook.getWorkbook(new File("output.xls"));

Sheet sheet = workbook.getSheet(0);

int rows = sheet.getRows();

int cols = sheet.getColumns();

// Initialize data

for (int row = 0; row rows; ++row){

Vector rowData = new Vector ();

for (int col = 0; col cols; ++col){

rowData.addElement (sheet.getCell(col,row).getContents());

}

data.addElement (rowData);

}

workbook.close();

}catch(Exception e){

e.printStackTrace();

}

return data;

}

//主程序

public static void main (String args [])

{

xlsPrinter gridPrinter = new xlsPrinter(initData (), null, true);

PrinterJob printerJob = PDFPrinterJob.getPrinterJob();

printerJob.setPrintable(gridPrinter);

try{

printerJob.print();

}catch (PrinterException pe){

pe.printStackTrace();

}

System.exit(0);

}

//打印接口,由此生成PDF文件,此段代码来源于jPDFWriter的例子

public int print (Graphics g, PageFormat pf, int pageIndex)

{

int lineHeight = g.getFontMetrics().getHeight();

// Reset current pos

int currentRow = 0;

if (pageIndex == 0)

{

// Need to do this in case the instance of this class

// gets used multiple times to print a string

m_CurrentPage = 0;

m_CurrentPageStartRow = 0;

}

// Need to do this because Java PrinterJob can call this

// method multiple times for the same page;

else if (m_CurrentPage == pageIndex)

{

currentRow = m_CurrentPageStartRow;

}

else

{

currentRow = m_CurrentPageEndRow + 1;

m_CurrentPageStartRow = currentRow;

}

// If we're out of lines, tell the PrinterJob we're done

if (currentRow = m_Data.size())

{

return Printable.NO_SUCH_PAGE;

}

// Loop through lines until we fill the page

int currentY = (int)(pf.getImageableY() + lineHeight);

while (currentRow m_Data.size()

currentY + lineHeight pf.getImageableY() + pf.getImageableHeight())

{

// Draw the next line

int currentX = (int)pf.getImageableX();

Vector nextRow = (Vector)m_Data.elementAt (currentRow);

for (int col = 0; col nextRow.size(); ++col)

{

String cellString = (String)nextRow.elementAt (col);

g.drawString (cellString, currentX + CELL_MARGIN_X, currentY + CELL_MARGIN_Y);

int colWidth = DEFAULT_COLUMN_WIDTH;

if (m_ColumnWidths != null m_ColumnWidths.length col)

{

colWidth = m_ColumnWidths [col];

}

// Draw grid if needed

if (m_DrawGrid)

{

g.drawRect (currentX, currentY - (lineHeight / 2), colWidth, lineHeight);

}

// Advance x

currentX += colWidth;

}

// Advance to the next line

++currentRow;

currentY += lineHeight;

}

// Save the ned line and current page

// Again, we have to do this because of multiple calls for the same page.

m_CurrentPageEndRow = currentRow;

m_CurrentPage = pageIndex;

return Printable.PAGE_EXISTS;

}

}

关于java8pdf和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-26,除非注明,否则均为首码项目网原创文章,转载请注明出处。