本站发布的所有文件/源码/文档/软件等均提供免费下载。
但本站带宽较低、流量有限,为防止恶意下载、盗刷流量,所以只能登陆网站后才能下载!
若给您带来不便请见谅~
为了方便,您可以通过qq授权登陆,也可以通过钉钉授权登陆。也可以通过邮箱注册后登陆。
java实现word转pdf在线预览-所需jar包
java实现world转pdf所需jar包-实现pdf在线预览
一、依赖文件
二、java代码实现
package test.pdftest;
import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.aspose.words.Document;
import com.aspose.words.HeaderFooter;
import com.aspose.words.HeaderFooterType;
import com.aspose.words.HorizontalAlignment;
import com.aspose.words.Paragraph;
import com.aspose.words.RelativeHorizontalPosition;
import com.aspose.words.RelativeVerticalPosition;
import com.aspose.words.SaveFormat;
import com.aspose.words.Section;
import com.aspose.words.Shape;
import com.aspose.words.ShapeType;
import com.aspose.words.VerticalAlignment;
import com.aspose.words.WrapType;
/**
* world转pdf实现在线预览
* @author 硅谷探秘者(jia)
*
*/
public class Test {
public static void main(String[] args) {
doc2pdf("E:\\test\\files\\a.docx","E:\\test\\files\\a.pdf");
}
public static void doc2pdf(String inPath, String outPath) {
FileOutputStream os =null;
try {
File file = new File(outPath); // 新建一个空白pdf文档
os = new FileOutputStream(file);
Document doc = new Document(inPath); // Address是将要被转化的word文档
insertWatermarkText(doc,"贾佳佳");//带水印,如果不需要直接注释掉就行了
doc.save(os, SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
}finally{
if(os!=null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* @Description: PDF生成水印
* @throws
*/
private static void insertWatermarkText(Document doc, String watermarkText) throws Exception
{
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
//水印内容
watermark.getTextPath().setText(watermarkText);
//水印字体
watermark.getTextPath().setFontFamily("宋体");
//水印宽度
watermark.setWidth(500);
//水印高度
watermark.setHeight(100);
//旋转水印
watermark.setRotation(-40);
//水印颜色
watermark.getFill().setColor(Color.lightGray);
watermark.setStrokeColor(Color.lightGray);
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setVerticalAlignment(VerticalAlignment.CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(watermark);
for (Section sect : doc.getSections())
{
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
}
System.out.println("Watermark Set");
}
private static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, int headerType) throws Exception
{
HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);
if (header == null)
{
header = new HeaderFooter(sect.getDocument(), headerType);
sect.getHeadersFooters().add(header);
}
header.appendChild(watermarkPara.deepClone(true));
}
}
二、实现效果:
猜你喜欢
工具
2105
java实现word转pdf实现在线预览(可以带水印)使用之前需要两个jar包的依赖文件下载地址:http://www.jiajiajia.club/file/info/4uwe2d/111Java
blog
Aspose实现word转图片、pdf
其他
449
Aspose Aspose.Total是Aspose公司旗下的最全的一套office文档管理方案,主要提供.net跟java两个开发语言的控件套包,通过它,可以有计划地操纵一些商业中最流行的文件格
blog
java完美实现html转pdf
工具
4918
java完美实现html转pdf1.pom依赖:dependencygroupIdcom.itextpdf/groupIdartifactIditextpdf
official
569
viewer.js和viewer.css,这两个文件在项目的dist文件夹中。例如:htmlheadtitletitle/titlemetahttp-equiv="Content-Type"content="t
blog
java生成二维码跳转链接
工具
3525
java生成二维码跳转链接需要的jar包!--https://mvnrepository.com/artifact/com.google.zxing/core
blog
java集合之TreeMap实现原理
java基础
1527
java集合之TreeMap实现原理TreeMap集合的实现其实说简单也简单说复杂也复杂,说简单是因为TreeMap底层实现完全依靠红黑树这个数据结构,相比与HashMap来说TreeMap不用考虑
框架
1273
http://www.jiajiajia.club/weblog/blog/artical/88springboot(1)中已经创建了一个项目并且运行了起来,现在就把独立的jar包运行起来。1.在
springboot,java基础
928
从springboot的文档知道,springboot打包一个可以在systemV直接执行的jar文件。操作也很简单,只需要在pom.xml中加入