如何将不同的文档合并为一个文档? [英] How to merge different documents into single one?

查看:126
本文介绍了如何将不同的文档合并为一个文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将word,excel文档合并为PDF?我调查了iTextSharp,但我不确定是否可以做到这一点.我有一个要求,用户将在其中上传word,excel文档,并将它们合并为PDF文档.

Is there any way to merge word, excel documents into a PDF? I looked into iTextSharp but im not sure if it can do that. I have a requirement where user will upload word, excel document and i have merge them into a PDF document.

推荐答案

步骤1)将文件转换为PDF.

Step 1) Convert your files to PDF.

第2步)将PDF与PdfCopy合并.

Step 2) Merge the PDFs with PdfCopy.

大多数Office格式都可以通过OpenOffice.org调用转换为PDF(免费).可能有一些服务站点可以执行相同的操作,还提供了各种商业软件包. Vichle在他的评论中的链接可能会解决问题.

Most Office formats can be converted to PDF (for free) via OpenOffice.org calls. There are probably some service sites out there that can do the same, and various commercial software packages. Vichle's link in his comment will probably do the trick.

Vichle的链接还表明,在提出问题之前,您可能没有先搜索SO.调皮调皮.

Vichle's link also demonstrates that you probably didn't search SO first before asking your question. Naughty naughty.

合并PDF非常简单:

Document doc = new Document();
PdfCopy copy = new PdfCopy(doc, outputStream);
doc.open();

String paths[] = getPaths();
for (int i = 0; i < paths.length; ++i) {
  PdfReader reader = new PdfReader(paths[i]);

  /**** The first page is ONE, not zero ****/
  for (int j = 1; j <= reader.getNumberOfPages(); ++j) { 
    PdfImportedPage curPg = copy.getImportedPage(reader, j);
    copy.addPage(curPg);
  }
}

doc.close();

那是Java,但是要转换为C#,您实际上只需要将函数名切换为大写,并调整几个类名即可.这是微不足道的.

That's Java, but to convert to C# you really just need to switch the function names to upper case, and tweak a couple class names. It's trivial.

并且有证据表明C#只是MS的宠爱Java.

And supporting evidence that C# is just MS's pet Java.

这篇关于如何将不同的文档合并为一个文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆