合并PDF文件的接口: using System;using System.Collections.Generic;using System.Linq;using System.Text;using iTextSharp.text;using iTextSharp.text.pdf;using System.Windows.Forms;namespace BLL{ /// <summary> /// 合并接口 /// </summary> public interface IPdfMerger { /// <summary> /// 用於顯示進行狀態 /// </summary> Label Lb { get; set; } /// <summary> /// 用於顯示進行狀態 /// </summary> PictureBox pb { get; set; } /// <summary> /// PDF路径 /// </summary> string pdfCreatDir { get; set; } /// <summary> /// 合并 /// </summary> /// <param name="sender"></param> void MergeFilesExe(object sender); }} 实现类一:支持少量的PDF文件(100) using System;using System.Collections.Generic;using System.IO;using iTextSharp.text;using iTextSharp.text.pdf;using Spring.Objects.Factory.Attributes;using System.ComponentModel;using System.Windows.Forms;using System.Collections;namespace BLL{ /// <summary> /// 支持多文件(PDF)合并 /// </summary> public class PdfMerger : IPdfMerger { public string pdfCreatDir { get; set; } public PictureBox pb { get; set; } public Label Lb { get; set; } private IPdfPageEvent _pdfPageEvent; private string currentfileName=string.Empty; [Required] public IPdfPageEvent PdfPageEvent { get { return _pdfPageEvent; } set { _pdfPageEvent = value; } } /// <summary> /// Merge pdf files. /// </summary> /// <param name="sourceFiles">PDF files being merged.</param> /// <returns></returns> public byte[] GetByteFiles(List<byte[]> sourceFiles) { Document document = new Document(); MemoryStream output = new MemoryStream(); try { try { // Initialize pdf writer PdfWriter writer = PdfWriter.GetInstance(document, output); writer.PageEvent = this.PdfPageEvent; // Open document to write document.Open(); PdfContentByte content = writer.DirectContent; // Iterate through all pdf documents for (int fileCounter = 0; fileCounter < sourceFiles.Count; fileCounter++) { // Create pdf reader PdfReader reader = new PdfReader(sourceFiles[fileCounter]); int numberOfPages = reader.NumberOfPages; // Iterate through all pages for (int currentPageIndex = 1; currentPageIndex <= numberOfPages; currentPageIndex++) { // Determine page size for the current page document.SetPageSize(reader.GetPageSizeWithRotation(currentPageIndex)); // Create page document.NewPage(); PdfImportedPage importedPage = writer.GetImportedPage(reader, currentPageIndex); // Determine page orientation int pageOrientation = reader.GetPageRotation(currentPageIndex); if ((pageOrientation == 90) || (pageOrientation == 270)) { content.AddTemplate(importedPage, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(currentPageIndex).Height); } else { content.AddTemplate(importedPage, 1f, 0, 0, 1f, 0, 0); } } } } catch (Exception exception) { throw new Exception("There has an unexpected exception occured during the pdf merging process.", exception); } } finally { document.Close(); } return output.GetBuffer(); } /// <summary> /// 递归执行文件 /// </summary> /// <param name="path"></param> public void MergeFiles(object sender) { string path = sender.ToString(); DirectoryInfo[] ChildDirectory; DirectoryInfo FatherDirectory = new DirectoryInfo(path); ChildDirectory = FatherDirectory.GetDirectories("*.*"); //FileInfo[] NewFileInfo= FatherDirectory.GetFiles("*.pdf"); //FileInfo[] NewFileInfo2 = FatherDirectory.GetFiles("*.*"); string[] NewFileInfo3 = Directory.GetFiles(FatherDirectory.FullName,"*.pdf"); string[] NewFileInfo4 = Directory.GetFiles(FatherDirectory.FullName, "*.*",SearchOption.TopDirectoryOnly); // 排序 Array.Sort(NewFileInfo3, new MyDateSorter()); List<byte[]> filesByte = new List<byte[]>(); // 刪除除pdf以外的文件 foreach (string FI in NewFileInfo4) { if (FI.IndexOf(".pdf")==-1) { File.Delete(FI); } } foreach (string FI in NewFileInfo3) { filesByte.Add(File.ReadAllBytes(FI)); File.WriteAllBytes(FatherDirectory.FullName + "//" + FatherDirectory.Name + ".pdf", GetByteFiles(filesByte)); currentfileName = FI; setLableText(); File.Delete(FI); } foreach (DirectoryInfo dirInfo in ChildDirectory) { MergeFiles(dirInfo.FullName); } } # region 合并PDF public void MergeFilesExe(object sender) { System.ComponentModel.BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.RunWorkerAsync(sender); } # endregion # region 执行后台线程 void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { pb.Visible = false; this.Lb.Text = "PDF文件合并完成!"; } void bw_DoWork(object sender, DoWorkEventArgs e) { setVisible(); MergeFiles(e.Argument.ToString()); } # endregion # region 线程访问控件 delegate void setProgressBarPositionCallBack(System.Windows.Forms.PictureBox refpb); public void setVisiblebyDelegate(System.Windows.Forms.PictureBox refpb) { refpb.Visible = true; } public void setVisible() { setProgressBarPositionCallBack scc = new setProgressBarPositionCallBack(setVisiblebyDelegate); this.pb.Invoke(scc,new object[]{this.pb}); } delegate void setProgressBarPositionCallBackLable(string refLb); public void setVisiblebyDelegateLable(string refLb) { this.Lb.Text = "正在合并" + refLb + "......"; } public void setLableText() { setProgressBarPositionCallBackLable scc = new setProgressBarPositionCallBackLable(setVisiblebyDelegateLable); this.Lb.Invoke(scc, new object[] { currentfileName }); } # endregion } /// <summary> /// 文件排序 /// </summary> public class MyDateSorter : IComparer { #region IComparer Members public int Compare(object x, object y) { if (x == null && y == null) { return 0; } if (x == null) { return -1; } if (y == null) { return 1; } string xInfo = (string)x; string yInfo = (string)y; //依名稱排序 //return xInfo.Name.CompareTo(yInfo.Name);//遞增 int index = xInfo.IndexOf("-"); string strXInfo = ""; string strYInfo = ""; // 期刊数据 if (index == -1) { strXInfo = xInfo.Replace(".pdf",""); strYInfo = yInfo.Replace(".pdf", ""); } // 中文会议 else { strXInfo = xInfo.Substring(index + 1).Replace(".pdf", ""); strYInfo = yInfo.Substring(index + 1).Replace(".pdf", ""); } strXInfo = strXInfo.Replace("//","|"); string[] temp = strXInfo.Split('|'); strXInfo = temp[temp.Length - 1].ToString(); temp = null; strYInfo = strYInfo.Replace("//", "|"); temp = strYInfo.Split('|'); strYInfo = temp[temp.Length - 1].ToString(); if (int.Parse(strXInfo) > int.Parse(strYInfo)) { return 1; } else if (int.Parse(strXInfo) < int.Parse(strYInfo)) { return -1; } else { return 0; } //return yInfo.FullName.CompareTo(xInfo.FullName);//遞減 //依修改日期排序 //return xInfo.LastWriteTime.CompareTo(yInfo.LastWriteTime);//遞增 //return yInfo.LastWriteTime.CompareTo(xInfo.LastWriteTime);//遞減 } #endregion }} 实现类二:支持多量的PDF文件(不限) using System;using System.Collections.Generic;using System.IO;using iTextSharp.text;using iTextSharp.text.pdf;using Spring.Objects.Factory.Attributes;using System.ComponentModel;using System.Windows.Forms;using System.Collections;namespace BLL{ /// <summary> /// 不支持多文件(PDF)合并 /// </summary> public class PdfMerger2 : IPdfMerger { public string pdfCreatDir { get; set; } public PictureBox pb { get; set; } public Label Lb { get; set; } private IPdfPageEvent _pdfPageEvent; private string currentfileName = string.Empty; [Required] public IPdfPageEvent PdfPageEvent { get { return _pdfPageEvent; } set { _pdfPageEvent = value; } } /// <summary> /// Merge pdf files. /// </summary> /// <param name="sourceFiles">PDF files being merged.</param> /// <returns></returns> public byte[] GetByteFiles(List<byte[]> sourceFiles) { Document document = new Document(); MemoryStream output = new MemoryStream(); try { try { // Initialize pdf writer PdfWriter writer = PdfWriter.GetInstance(document, output); writer.PageEvent = this.PdfPageEvent; // Open document to write document.Open(); PdfContentByte content = writer.DirectContent; // Iterate through all pdf documents for (int fileCounter = 0; fileCounter < sourceFiles.Count; fileCounter++) { // Create pdf reader PdfReader reader = new PdfReader(sourceFiles[fileCounter]); int numberOfPages = reader.NumberOfPages; // Iterate through all pages for (int currentPageIndex = 1; currentPageIndex <= numberOfPages; currentPageIndex++) { // Determine page size for the current page document.SetPageSize(reader.GetPageSizeWithRotation(currentPageIndex)); // Create page document.NewPage(); PdfImportedPage importedPage = writer.GetImportedPage(reader, currentPageIndex); // Determine page orientation int pageOrientation = reader.GetPageRotation(currentPageIndex); if ((pageOrientation == 90) || (pageOrientation == 270)) { content.AddTemplate(importedPage, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(currentPageIndex).Height); } else { content.AddTemplate(importedPage, 1f, 0, 0, 1f, 0, 0); } } } } catch (Exception exception) { throw new Exception("There has an unexpected exception occured during the pdf merging process.", exception); } } finally { document.Close(); } return output.GetBuffer(); } /// <summary> /// 递归执行文件 /// </summary> /// <param name="path"></param> public void MergeFiles(object sender) { string path = sender.ToString(); DirectoryInfo[] ChildDirectory; DirectoryInfo FatherDirectory = new DirectoryInfo(path); ChildDirectory = FatherDirectory.GetDirectories("*.*"); FileInfo[] NewFileInfo = FatherDirectory.GetFiles("*.pdf"); FileInfo[] NewFileInfo2 = FatherDirectory.GetFiles("*.*"); // 排序 Array.Sort(NewFileInfo, new MyDateSorter2()); List<byte[]> filesByte = new List<byte[]>(); // 刪除除pdf以外的文件 foreach (FileInfo FI in NewFileInfo2) { if (!FI.Extension.Equals(".pdf")) { File.Delete(FI.FullName); } } foreach (FileInfo FI in NewFileInfo) { filesByte.Add(File.ReadAllBytes(FI.FullName)); currentfileName = FI.Name; setLableText(); File.Delete(FI.FullName); } if (filesByte.Count > 0) { File.WriteAllBytes(FatherDirectory.FullName + "//" + FatherDirectory.Name + ".pdf", GetByteFiles(filesByte)); } foreach (DirectoryInfo dirInfo in ChildDirectory) { MergeFiles(dirInfo.FullName); } } # region 合并PDF public void MergeFilesExe(object sender) { System.ComponentModel.BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.RunWorkerAsync(sender); } # endregion # region 执行后台线程 void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { pb.Visible = false; this.Lb.Text = "PDF文件合并完成!"; } void bw_DoWork(object sender, DoWorkEventArgs e) { setVisible(); MergeFiles(e.Argument.ToString()); } # endregion # region 线程访问控件 delegate void setProgressBarPositionCallBack(System.Windows.Forms.PictureBox refpb); public void setVisiblebyDelegate(System.Windows.Forms.PictureBox refpb) { refpb.Visible = true; } public void setVisible() { setProgressBarPositionCallBack scc = new setProgressBarPositionCallBack(setVisiblebyDelegate); this.pb.Invoke(scc, new object[] { this.pb }); } delegate void setProgressBarPositionCallBackLable(string refLb); public void setVisiblebyDelegateLable(string refLb) { this.Lb.Text = "正在合并" + refLb + "......"; } public void setLableText() { setProgressBarPositionCallBackLable scc = new setProgressBarPositionCallBackLable(setVisiblebyDelegateLable); this.Lb.Invoke(scc, new object[] { currentfileName }); } # endregion } /// <summary> /// 文件排序 /// </summary> public class MyDateSorter2 : IComparer { #region IComparer Members public int Compare(object x, object y) { if (x == null && y == null) { return 0; } if (x == null) { return -1; } if (y == null) { return 1; } FileInfo xInfo = (FileInfo)x; FileInfo yInfo = (FileInfo)y; //依名稱排序 //return xInfo.Name.CompareTo(yInfo.Name);//遞增 int index = xInfo.Name.IndexOf("-"); string strXInfo = ""; string strYInfo = ""; // 期刊数据 if (index == -1) { strXInfo = xInfo.Name.Replace(".pdf", ""); strYInfo = yInfo.Name.Replace(".pdf", ""); } // 中文会议 else { strXInfo = xInfo.Name.Substring(index + 1).Replace(".pdf", ""); strYInfo = yInfo.Name.Substring(index + 1).Replace(".pdf", ""); } if (int.Parse(strXInfo) > int.Parse(strYInfo)) { return 1; } else if (int.Parse(strXInfo) < int.Parse(strYInfo)) { return -1; } else { return 0; } //return yInfo.FullName.CompareTo(xInfo.FullName);//遞減 //依修改日期排序 //return xInfo.LastWriteTime.CompareTo(yInfo.LastWriteTime);//遞增 //return yInfo.LastWriteTime.CompareTo(xInfo.LastWriteTime);//遞減 } #endregion }} 合并文档触发事件: using System;using System.Collections.Generic;using System.Linq;using System.Text;using iTextSharp.text;using iTextSharp.text.pdf;namespace BLL{ /// <summary> /// Implements custom page events. /// </summary> internal class PdfPageEvents : IPdfPageEvent { #region members private BaseFont _baseFont = null; private PdfContentByte _content; #endregion #region IPdfPageEvent Members public void OnOpenDocument(PdfWriter writer, Document document) { _baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); _content = writer.DirectContent; } public void OnStartPage(PdfWriter writer, Document document) { } public void OnEndPage(PdfWriter writer, Document document) { Write header text //string headerText = "PDF Merger by Smart-Soft"; //_content.BeginText(); //_content.SetFontAndSize(_baseFont, 8); //_content.SetTextMatrix(GetCenterTextPosition(headerText, writer), writer.PageSize.Height - 10); //_content.ShowText(headerText); //_content.EndText(); Write footer text (page numbers) //string text = "Page " + writer.PageNumber; //_content.BeginText(); //_content.SetFontAndSize(_baseFont, 8); //_content.SetTextMatrix(GetCenterTextPosition(text, writer), 10); //_content.ShowText(text); //_content.EndText(); } public void OnCloseDocument(PdfWriter writer, Document document) { } public void OnParagraph(PdfWriter writer, Document document, float paragraphPosition) { } public void OnParagraphEnd(PdfWriter writer, Document document, float paragraphPosition) { } public void OnChapter(PdfWriter writer, Document document, float paragraphPosition, Paragraph title) { } public void OnChapterEnd(PdfWriter writer, Document document, float paragraphPosition) { } public void OnSection(PdfWriter writer, Document document, float paragraphPosition, int depth, Paragraph title) { } public void OnSectionEnd(PdfWriter writer, Document document, float paragraphPosition) { } public void OnGenericTag(PdfWriter writer, Document document, Rectangle rect, string text) { } #endregion private float GetCenterTextPosition(string text, PdfWriter writer) { return writer.PageSize.Width / 2 - _baseFont.GetWidthPoint(text, 8) / 2; } }} 执行合并代理类: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;using Spring.Objects.Factory.Attributes;using System.IO;using iTextSharp.text;using iTextSharp.text.pdf;namespace BLL{ /// <summary> /// 执行合并代理 /// </summary> public class ProxyPdfMerger { private IPdfMerger _pdfMerger; [Required] public IPdfMerger PdfMerger { get { return _pdfMerger; } set { _pdfMerger = value; } } /// <summary> /// 递归执行文件 /// </summary> /// <param name="path"></param> public void MergeFiles(string sourcefilePath ,string MbfilePath ,ref System.Windows.Forms.PictureBox refpb ,ref System.Windows.Forms.Label refLb) { PdfMerger.Lb = refLb; PdfMerger.pb = refpb; PdfMerger.pdfCreatDir = MbfilePath; PdfMerger.MergeFilesExe(sourcefilePath); } }} 显示窗体: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using BLL;using Spring.Context;using Spring.Context.Support;using Spring.Objects.Factory.Config;using Spring.Objects.Factory.Support;using Spring.Objects.Factory.Xml;namespace PDF_Merger{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// <summary> /// 合併PDF文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMerge_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("請指定文件目錄!"); return; } IApplicationContext ctx = ContextRegistry.GetContext(); ProxyPdfMerger Merger = (ProxyPdfMerger)ctx.GetObject("ProxyPdfMer"); Merger.MergeFiles(this.textBox1.Text,"",ref this.pbLoading,ref this.label3); } /// <summary> /// 選擇文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnChooseFolder_Click(object sender, EventArgs e) { folderBrowserDialog1 = new FolderBrowserDialog(); if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = folderBrowserDialog1.SelectedPath; } } }} namespace PDF_Merger{ partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.btnMerge = new System.Windows.Forms.Button(); this.pbLoading = new System.Windows.Forms.PictureBox(); this.label3 = new System.Windows.Forms.Label(); this.btnChooseFolder = new System.Windows.Forms.Button(); this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); ((System.ComponentModel.ISupportInitialize)(this.pbLoading)).BeginInit(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(89, 18); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(169, 21); this.textBox1.TabIndex = 0; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(12, 24); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(77, 12); this.label1.TabIndex = 1; this.label1.Text = "PDF文件目录:"; // // btnMerge // this.btnMerge.FlatStyle = System.Windows.Forms.FlatStyle.System; this.btnMerge.Location = new System.Drawing.Point(242, 49); this.btnMerge.Name = "btnMerge"; this.btnMerge.Size = new System.Drawing.Size(56, 23); this.btnMerge.TabIndex = 4; this.btnMerge.Text = "合 并"; this.btnMerge.UseVisualStyleBackColor = true; this.btnMerge.Click += new System.EventHandler(this.btnMerge_Click); // // pbLoading // this.pbLoading.Image = global::PDF_Merger.Properties.Resources.ajax_loaderControl_1; this.pbLoading.Location = new System.Drawing.Point(12, 61); this.pbLoading.Name = "pbLoading"; this.pbLoading.Size = new System.Drawing.Size(18, 17); this.pbLoading.TabIndex = 5; this.pbLoading.TabStop = false; this.pbLoading.Visible = false; // // label3 // this.label3.AutoSize = true; this.label3.Enabled = false; this.label3.Font = new System.Drawing.Font("宋体", 7F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label3.Location = new System.Drawing.Point(38, 68); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(0, 10); this.label3.TabIndex = 6; // // btnChooseFolder // this.btnChooseFolder.FlatAppearance.BorderSize = 0; this.btnChooseFolder.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnChooseFolder.Image = ((System.Drawing.Image)(resources.GetObject("btnChooseFolder.Image"))); this.btnChooseFolder.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.btnChooseFolder.Location = new System.Drawing.Point(260, 17); this.btnChooseFolder.Name = "btnChooseFolder"; this.btnChooseFolder.Size = new System.Drawing.Size(28, 21); this.btnChooseFolder.TabIndex = 7; this.btnChooseFolder.UseVisualStyleBackColor = true; this.btnChooseFolder.Click += new System.EventHandler(this.btnChooseFolder_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(309, 84); this.Controls.Add(this.btnChooseFolder); this.Controls.Add(this.label3); this.Controls.Add(this.pbLoading); this.Controls.Add(this.btnMerge); this.Controls.Add(this.label1); this.Controls.Add(this.textBox1); this.HelpButton = true; this.MaximizeBox = false; this.Name = "Form1"; this.ShowIcon = false; this.Text = "PDF文件合并"; ((System.ComponentModel.ISupportInitialize)(this.pbLoading)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btnMerge; private System.Windows.Forms.PictureBox pbLoading; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button btnChooseFolder; private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; }} 配置文件: <?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <sectionGroup name="spring"> <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/> <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /> </sectionGroup> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> </sectionGroup> </configSections> <common> <logging> <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"> <!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL--> <!-- otherwise BasicConfigurer.Configure is used --> <!-- log4net configuration file is specified with key configFile--> <arg key="configType" value="INLINE" /> </factoryAdapter> </logging> </common> <spring> <context> <resource uri="config://spring/objects"/> </context> <!--`合并PDF文件代理--> <objects xmlns="http://www.springframework.net" > <object id="ProxyPdfMer" type="BLL.ProxyPdfMerger,BLL"> <property name="PdfMerger" ref="PdfMergerB"/> </object> <!-- 不支持多PDF文件合并--> <object name="PdfMergerA" type="BLL.PdfMerger2,BLL"> <property name="PdfPageEvent" ref="PdfPageEventA"/> </object> <!-- 支持多PDF文件合并--> <object name="PdfMergerB" type="BLL.PdfMerger,BLL"> <property name="PdfPageEvent" ref="PdfPageEventA"/> </object> <object name="PdfPageEventA" type="BLL.PdfPageEvents,BLL"> </object> </objects> </spring> <log4net> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <file value="log-file.txt" /> <appendToFile value="true" /> <encoding value="unicode" /> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" /> </layout> </appender> <!-- Set default logging level to DEBUG --> <root> <level value="DEBUG" /> <appender-ref ref="ConsoleAppender" /> </root> <logger name="MySpringNet1.EatForDinner"> <level value="DEBUG" /> </logger> <!-- Set logging for Spring to INFO. Logger names in Spring correspond to the namespace --> <logger name="Spring"> <level value="INFO" /> </logger> </log4net> </configuration>