public void StartMerger() { this.DialogResult = DialogResult.OK; using (Stream s = new FileStream(this.Project.TempTarget, FileMode.Create, FileAccess.Write)) { this.merger = new PdfMerger(s); this.merger.PdfMergerProgress += new EventHandler<PdfMergerProgressEventArgs>(merger_PdfMergerProgress); foreach (PdfProjectElement ppe in this.Project.Elements) { if (this.merger.CancelPending) { this.DialogResult = DialogResult.Cancel; return; } if (ppe.Enabled) { ppe.AddToMerger(this.merger); } } this.merger.Finish(); } File.Copy(this.Project.TempTarget, this.Project.Target,true); File.Delete(this.Project.TempTarget); }
static void Main(string[] args) { string inputFile = args[0]; string outputFile = args[1]; int iterations = Int32.Parse(args[2]); // Merge the generated pdfs using (var outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { var merger = new PdfMerger(outputStream); for (int count = 1; count <= iterations; count++ ) { using (var inputStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var pdfParser = PdfParser.Parse(inputStream); merger.Add(pdfParser, null); } } merger.Finish(); } }
static void Main(string[] args) { string inputFile = args[0]; string outputFile = args[1]; int pageNumber = Int32.Parse(args[2]); string target = Path.Combine(Path.GetDirectoryName(outputFile), Path.GetFileNameWithoutExtension(outputFile) + " - " + pageNumber.ToString("00000") + ".pdf"); using (var inputStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var pdfParser = PdfParser.Parse(inputStream); using (Stream s = new FileStream(target, FileMode.Create, FileAccess.Write)) { var pdfMerger = new PdfMerger(s); pdfMerger = new PdfMerger(s); pdfMerger.Add(pdfParser, new int[] { pageNumber }); pdfMerger.Finish(); } } }
public abstract void AddToMerger(PdfMerger pdfMerger);
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { string temp = Path.Combine(Path.GetTempPath(), "preview.pdf"); using (Stream s = new FileStream(temp, FileMode.Create, FileAccess.Write)) { PdfMerger pm = new PdfMerger(s); this.CurrentElement.AddToMerger(pm); pm.Finish(); } Process.Start(temp); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void GenerateSplit(int n, string target, PdfParser parsedPdf, int page) { target = Path.Combine(Path.GetDirectoryName(target), Path.GetFileNameWithoutExtension(target) + " - " + n.ToString("00000") + ".pdf"); using (Stream s = new FileStream(target, FileMode.Create, FileAccess.Write)) { this.merger = new PdfMerger(s); this.merger.PdfMergerProgress += new EventHandler<PdfMergerProgressEventArgs>(merger_PdfMergerProgress); this.merger.Add(parsedPdf, new int[] { page }); this.merger.Finish(); } }
public override void AddToMerger(PdfMerger pdfMerger) { using (Stream s = new FileStream(this.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { PdfParser pa = PdfParser.Parse(s); pdfMerger.Add(pa, this.CalculatePageSelection(true)); } }
public override void AddToMerger(PdfMerger pdfMerger) { pdfMerger.Add(PdfParser.Parse(ImageToPDFConverter.ConvertImageToPDF(this.Path))); }
static void Main(string[] args) { Console.WriteLine("GIOS PDF Splitter and Merger - Version " + Assembly.GetEntryAssembly().GetName().Version); Console.WriteLine("Copyright © 2009 Paolo Gios - www.paologios.com"); Console.WriteLine(); Console.WriteLine("Merges PDF and JPG files into a single PDF file."); Console.WriteLine(); try { if (args.Length == 0) { Help(); #if DEBUG Console.ReadLine(); #endif return; } string output = ""; for (int index = 0; index < args.Length - 1; index++) { string f = args[index].ToLower(); if (f == "output") { output = args[index + 1]; break; } } if (output == null) return; using (FileStream outputStream = new FileStream(output, FileMode.Create, FileAccess.Write)) { Stopwatch sw = new Stopwatch(); sw.Start(); Console.WriteLine("Creating " + output + " ..."); PdfMerger merger = new PdfMerger(outputStream); merger.PdfMergerProgress += new EventHandler<PdfMergerProgressEventArgs>(merger_PdfMergerProgress); for (int index = 0; index < args.Length; index++) { string f = args[index].ToLower(); if (f == "output") { index++; continue; } string directory = Path.GetDirectoryName(f); if (string.IsNullOrEmpty(directory)) { directory = Environment.CurrentDirectory; } string[] files = Directory.GetFiles(directory, Path.GetFileName(f), SearchOption.TopDirectoryOnly); Array.Sort(files); foreach (string file in files) { if (string.Compare(file, outputStream.Name) == 0) continue; string extension = Path.GetExtension(file).ToLower(); Stream fs = null; switch (extension) { case ".pdf": fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); break; case ".jpg": fs = ImageToPDFConverter.ConvertImageToPDF(file); break; default : continue; } using (fs) { Console.WriteLine(); Console.WriteLine("Adding " + file + "... "); PdfParser pa = PdfParser.Parse(fs); merger.Add(pa, null); Console.SetCursorPosition(0, Console.CursorTop); Console.WriteLine("Done. "); } } } Console.WriteLine(); Console.Write("Finishing ... "); merger.Finish(); sw.Stop(); Console.WriteLine("Finished in " + sw.ElapsedMilliseconds + " ms."); } } catch (Exception e) { Console.WriteLine(e.Message); } #if DEBUG Console.ReadLine(); #endif }