public static void SplitPdf(string filePath, string outputDir = null) { if (filePath == string.Empty || filePath == null) { return; } if (outputDir == null) { outputDir = System.IO.Path.GetDirectoryName(filePath) + "\\"; } using (var pdfDoc = new PdfDocument(new PdfReader(filePath))) { var splitter = new CustomSplitter(pdfDoc, outputDir); var splittedDocs = splitter.SplitByPageCount(1); foreach (var splittedDoc in splittedDocs) { splittedDoc.Close(); } } OpenFolderInExplorer(outputDir); }
protected override void Execute(CodeActivityContext context) { try { SplitOptions splitter = Splitter; List <string> temp = new List <string>(); String[] stringsplitter; string input; switch (splitter) { case SplitOptions.Comma: input = Input.Get(context); stringsplitter = new String[] { "," }; var tmp = input.Split(stringsplitter, StringSplitOptions.RemoveEmptyEntries); temp = tmp.ToList <string>(); break; case SplitOptions.Newline: input = Input.Get(context); stringsplitter = new String[] { Environment.NewLine.ToString() }; tmp = input.Split(stringsplitter, StringSplitOptions.RemoveEmptyEntries); temp = tmp.ToList <string>(); break; case SplitOptions.Pipe: input = Input.Get(context); stringsplitter = new String[] { "|" }; tmp = input.Split(stringsplitter, StringSplitOptions.RemoveEmptyEntries); temp = tmp.ToList <string>(); break; case SplitOptions.Custom: input = Input.Get(context); string[] customSplitter = CustomSplitter.Get(context); if (customSplitter != null) { tmp = input.Split(customSplitter, StringSplitOptions.RemoveEmptyEntries); temp = tmp.ToList <string>(); break; } else { throw new NullReferenceException("Custom splitter cannot be null if Custom is selected"); } default: Console.WriteLine("Invalid Splitter"); break; } Result.Set(context, temp.ToArray()); } catch (NullReferenceException e) { Console.WriteLine(e.Message); throw; } catch (Exception e) { Console.WriteLine(e.Message); throw; } }