using PdfSharp.Pdf; using PdfSharp.Pdf.IO; using System.Collections.Generic; namespace SteamWare { /// /// Utilities gestione PDF tramite PdfSharp /// public class pdfUtils { /// /// Init classe /// public pdfUtils() { } /// /// Effettua il merge di più files pdf in un UNICO file pdf di output /// /// Nome del file da creare (full path) /// Elenco files pdf da includere (full path) /// public static bool mergePdfFiles(string pdfOutFilename, List pdfInFileList) { bool answ = false; PdfDocument currPdfIn; // merge! using (PdfDocument outPdf = new PdfDocument()) { // copio ogni SINGOLA pagina foreach (var fileName in pdfInFileList) { try { currPdfIn = PdfReader.Open(fileName, PdfDocumentOpenMode.Import); CopyPages(currPdfIn, outPdf); } catch { } } // salvo! outPdf.Save(pdfOutFilename); answ = true; } return answ; } /// /// Effettua copia di ogni singola pagina pdf (from --> to) /// /// /// protected static void CopyPages(PdfDocument from, PdfDocument to) { for (int i = 0; i < from.PageCount; i++) { to.AddPage(from.Pages[i]); } } } }