导航:首页 > 文档加密 > java替换pdf

java替换pdf

发布时间:2022-08-15 19:28:12

❶ 在linux环境下,java怎么实现从word格式转换为pdf格式

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

/**
* @author XuMing Li
*
* @version 1.00, 2007-4-9
*
*/
public class D2P {
private ActiveXComponent wordCom = null;

private Object wordDoc = null;

private final Variant False = new Variant(false);

private final Variant True = new Variant(true);

/**
* 打开word文档
*
* @param filePath
* word文档
* @return 返回word文档对象
*/
public boolean openWord(String filePath) {
//建立ActiveX部件
wordCom = new ActiveXComponent( "Word.Application ");

try {
//返回wrdCom.Documents的Dispatch
Dispatch wrdDocs = wordCom.getProperty( "Documents ").toDispatch();
//调用wrdCom.Documents.Open方法打开指定的word文档,返回wordDoc
wordDoc = Dispatch.invoke(wrdDocs, "Open ", Dispatch.Method,
new Object[] { filePath }, new int[1]).toDispatch();
return true;
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}

/**
* 关闭word文档
*/
public void closeWord() {
//关闭word文件
wordCom.invoke( "Quit ", new Variant[] {});
}

/**
* * 将word文档打印为PS文件后,使用Distiller将PS文件转换为PDF文件 *
*
* @param sourceFilePath
* 源文件路径 *
* @param destinPSFilePath
* 首先生成的PS文件路径 *
* @param destinPDFFilePath
* 生成PDF文件路径
*/
public void docToPDF(String sourceFilePath, String destinPSFilePath,
String destinPDFFilePath) {
if (!openWord(sourceFilePath)) {
closeWord();
return;
}
//建立Adobe Distiller的com对象
ActiveXComponent distiller = new ActiveXComponent(
"PDFDistiller.PDFDistiller.1 ");
try {
//设置当前使用的打印机,我的Adobe Distiller打印机名字为 "Adobe PDF "
wordCom.setProperty( "ActivePrinter ", new Variant( "Adobe PDF "));
//设置printout的参数,将word文档打印为postscript文档。目前只使用了前5个参数,如果要使用更多的话可以参考MSDN的office开发相关api
//是否在后台运行
Variant Background = False;
//是否追加打印
Variant Append = False;
//打印所有文档
int wdPrintAllDocument = 0;
Variant Range = new Variant(wdPrintAllDocument);
//输出的postscript文件的路径
Variant OutputFileName = new Variant(destinPSFilePath);

Dispatch.callN((Dispatch) wordDoc, "PrintOut ", new Variant[] {
Background, Append, Range, OutputFileName });
System.out.println( "由word文档打印为ps文档成功! ");
//调用Distiller对象的FileToPDF方法所用的参数,详细内容参考Distiller Api手册
//作为输入的ps文档路径
Variant inputPostScriptFilePath = new Variant(destinPSFilePath);
//作为输出的pdf文档的路径
Variant outputPDFFilePath = new Variant(destinPDFFilePath);
//定义FileToPDF方法要使用adobe pdf设置文件的路径,在这里没有赋值表示并不使用pdf配置文件
Variant PDFOption = new Variant( " ");
//调用FileToPDF方法将ps文档转换为pdf文档
Dispatch.callN(distiller, "FileToPDF ", new Variant[] {
inputPostScriptFilePath, outputPDFFilePath, PDFOption });
System.out.println( "由ps文档转换为pdf文档成功! ");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
closeWord();
}
}

public static void main(String[] argv) {
D2P d2p = new D2P();
// d2p.openWord( "c:/12.doc ");
// d2p.callWordMacro( "c:/12.docc ", "MyWordMacro ",
// new String[] { "这是调用word宏的测试程序 " });
d2p.docToPDF( "d:/12.doc ", "c:/1p.ps ", "c:/1p.pdf ");
}
}

❷ java怎么将word文档转换为pdf

如何将word文件转换成pdf文件_网络经验 http://jingyan..com/article/fcb5aff7ef1969edaa4a71b7.html

❸ JAVA实现读取pdf模板,替换内容后生成新pdf文档

为什么要采用替换的方法呢?
读取后经过处理,重新新建一个PDF,把内容写到新的PDF里面就行了,用这些jar可以实现了

我的意思是,你有PDF模板,然后用java读取模板的内容,然后按你的要求对读取的内容进行处理(这里的处理是根据你自己的需求而定,如:从数据库读取数据,然后填充到从模板读取到的表格中),再把处理完后的内容重新写到一个新建的PDF中

❹ 使用freemarker生成的word文档,如何利用java代码将其转换为pdf格式

首先,通过xml模板可以将基本上所有的格式都事先锁定,包括页码和分页,只要你事先预设好就能够通过freemarker实现生成,接下来就是我这个问题了,目录怎么解决,下面是解决思路:1:目录的内容可以根据之前其他的内容一样解决,通过XML模板预先设置好,2:目录的页码已经研究过是不能直接通过xml模板实现动态对应了(至少我没搞定0.0)3:由于不能够一步到位,我采取了在模板中预留了一页空白页,只留了抬头的目录两个字,然后通过查询目录二字进行目录的生成,这个功能也是我刚刚折腾出来的0.0目前还没测试能不能用模板生成目录后再更新目录0.0,不过想想可以直接生成目录应该就不用这么麻烦了,至于word生成后的修改0.0我觉得还是以后再说吧..整体来说应该还算完美解决了,代码我就不在这贴出来了~虽然中间折腾了半天走了半天弯路~讲道理还是用的jacob来实现的。。

❺ java pptx 转换pdf

用jacob转doc和xls能成功,如果你转pptx是拷贝doc或者xls的代码,那么就会报错,中间有两个细节的地方要注意,有区别:
setProperty("Visible", new Variant(true)); doc和xls是false,pptx要改为true
下面这两段代码要删除
Variant f = new Variant(false);
Dispatch.call(xls, "Close", f);

❻ java itext转换PDF

public void GenerateAllParts() {
Document document = new Document();

try {
PdfWriter.getInstance(document, new FileOutputStream("d:\\all.pdf"));

// 生成字体
BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);
// 标题字体
Font f30 = new Font(bfChinese, 30, Font.NORMAL, Color.BLACK);
// 正文字体
Font f12 = new Font(bfChinese, 12, Font.NORMAL, Color.BLACK);
Font f6 = new Font(bfChinese, 6, Font.NORMAL, Color.BLACK);
Font f8 = new Font(bfChinese, 8, Font.NORMAL, Color.BLACK);

document.open();

// 标题
document.add(new Paragraph("报表实例", f30));
// 换行
document.add(new Chunk("\n\n"));
//
document.add(
new Paragraph(
new Chunk(".......................点击查看报表", f12)
.setLocalGoto("table")));
// 换行
document.add(new Chunk("\n\n"));
document.add(
new Paragraph(
new Chunk(".......................点击查看图片", f12)
.setLocalGoto("image")));
document.add(new Chunk("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"));

///////////////////////////////////////////////////
// 报表位置
document.add(new Chunk("报表实例", f12).setLocalDestination("table"));
// 添加table实例
PdfPTable table = new PdfPTable(5);
table.setWidthPercentage(100);
table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
PdfPCell cell = new PdfPCell();
cell.setBackgroundColor(new Color(213, 141, 69));
cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

// 表格标题
cell.setPhrase(new Paragraph("标题一", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题二", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题三", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题四", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题五", f8));
table.addCell(cell);

// 表格数据
PdfPCell newcell = new PdfPCell();
newcell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
newcell.setPhrase(new Paragraph("数据一", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据二", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据三", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据四", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据五", f8));
table.addCell(newcell);

document.add(table);
////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////
// 添加连接
document.add(new Chunk("图片实例", f12).setLocalDestination("image"));
Image jpg = Image.getInstance("d:\\3.jpg");
document.add(jpg);
//////////////////////////////////////////////////////////

document.close();
} catch (Exception e) {
// TODO: handle exception
}
}

❼ 如何时候使用java编写程序将PDF文件转换为

用Adobe Acrobat才是最好的选择。该软件不但转换的速度快,还也可以逆转换。兼容的格式多,而且可以在该软件里修改、编辑等操作。

❽ java将html文件转成pdf

核心代码如下
package com.hmkcode;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.html2pdf.HtmlConverter;

public class App {
public static final String HTML = "<h1>Hello</h1>"
+ "<p>This was created using iText</p>"
+ "<a href='hmkcode.com'>hmkcode.com</a>";

public static void main( String[] args ) throws FileNotFoundException, IOException
{
HtmlConverter.convertToPdf(HTML, new FileOutputStream("string-to-pdf.pdf"));

System.out.println( "PDF Created!" );
}
}

❾ Java能直接修改pdf文件吗

貌似没见过这个插件,还有pdf有一部分是根本不能修改的,哪怕用专业工具都不行,如果pdf里面的文字可以读取出来,倒是可以导入txt然后就很好修改了,pdf图文混排,觉得java修改难度较大

阅读全文

与java替换pdf相关的资料

热点内容
思科常用配置命令 浏览:377
水容易被压缩吗 浏览:753
java项目试题 浏览:315
为什么安卓拍照没有苹果成相快 浏览:516
安卓版的苹果手机叫什么 浏览:373
手机怎么解压文件夹压缩包 浏览:459
起源任务咋解压 浏览:976
加密式的监督检查 浏览:549
光遇怎么分辨安卓国服和渠道服 浏览:242
ico解压教程 浏览:632
程序员偏右 浏览:17
超算上可以进行vasp编译嘛 浏览:174
北京通app怎么注册登录 浏览:820
iphone上的数据怎么转移到安卓 浏览:743
python求每个时段平均值 浏览:244
安卓手机右上出现Hg什么意思 浏览:69
程序员神经 浏览:753
dns服务器在电脑上有什么用 浏览:915
杭州大妈喜欢程序员 浏览:687
python评论树讲解 浏览:680