将两个(或更多)的PDF [英] Combine two (or more) PDF's

查看:190
本文介绍了将两个(或更多)的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我要为我的销售人员提供的每周报告包。这个包包含几个(5-10)水晶报表。

Background: I need to provide a weekly report package for my sales staff. This package contains several (5-10) crystal reports.

问题: 我想允许用户运行所有报表,也只需运行一个报告。我想我能做到这一点通过创建报告,然后做:

Problem: I would like to allow a user to run all reports and also just run a single report. I was thinking I could do this by creating the reports and then doing:

List<ReportClass> reports = new List<ReportClass>();
reports.Add(new WeeklyReport1());
reports.Add(new WeeklyReport2());
reports.Add(new WeeklyReport3());
<snip>

foreach (ReportClass report in reports)
{
    report.ExportToDisk(ExportFormatType.PortableDocFormat, @"c:\reports\" + report.ResourceName + ".pdf");
}

这会为我充满了报表的文件夹,但我想每个人都发电子邮件单一的PDF与所有的每周报告。所以,我需要将它们结合起来。

This would provide me a folder full of the reports, but I would like to email everyone a single PDF with all the weekly reports. So I need to combine them.

有一个简单的方法来做到这一点没有安装任何更多的第三方控件?我已经有DevEx preSS和放大器; CrystalReports和我preFER不要加太多了。

Is there an easy way to do this without install any more third party controls? I already have DevExpress & CrystalReports and I'd prefer not to add too many more.

这将是最好将它们组合在foreach循环中,或在一个单独的循环? (或另一种方式)

Would it be best to combine them in the foreach loop or in a seperate loop? (or an alternate way)

感谢

推荐答案

我不得不解决一个类似的问题,我落得这样做创建使用的 PDFSharp 这基本上是MIT许可的项目。

I had to solve a similar problem and what I ended up doing was creating a small pdfmerge utility that uses the PDFSharp project which is essentially MIT licensed.

在code是死的简单,我需要一个CMDLINE工具,所以我有更多的code,致力于解析参数比我做的PDF合并:

The code is dead simple, I needed a cmdline utility so I have more code dedicated to parsing the arguments than I do for the PDF merging:

using (PdfDocument one = PdfReader.Open("file1.pdf", PdfDocumentOpenMode.Import))
using (PdfDocument two = PdfReader.Open("file2.pdf", PdfDocumentOpenMode.Import))
using (PdfDocument outPdf = new PdfDocument())
{                
    CopyPages(one, outPdf);
    CopyPages(two, outPdf);

    outPdf.Save("file1and2.pdf");
}

void CopyPages(PdfDocument from, PdfDocument to)
{
    for (int i = 0; i < from.PageCount; i++)
    {
        to.AddPage(from.Pages[i]);
    }
}

这篇关于将两个(或更多)的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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