private void createCombinedPdf_Acrobat(List <CockleFilePdf> selectedPdfFiles, string new_file_name) { Acrobat.CAcroApp app = new Acrobat.AcroApp(); // Acrobat Acrobat.CAcroPDDoc doc = new Acrobat.AcroPDDoc(); // First document Acrobat.CAcroPDDoc docToAdd = new Acrobat.AcroPDDoc(); // Next documents try { int numPages = 0, numPagesToAdd = 0; foreach (var _f in selectedPdfFiles) { var f = _f.FullName; if (_f == selectedPdfFiles.First()) // both 0 { doc.Open(f); numPages = doc.GetNumPages(); } else { if (!docToAdd.Open(f)) { break; } numPagesToAdd = docToAdd.GetNumPages(); if (!doc.InsertPages(numPages - 1, docToAdd, 0, numPagesToAdd, 0)) { break; } if (!docToAdd.Close()) { break; } numPages = doc.GetNumPages(); } } doc.Save(1, new_file_name); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { doc.Close(); app.CloseAllDocs(); app.Exit(); doc = null; docToAdd = null; app = null; GC.Collect(); } }
private void carryOutPdfExtractPages(string new_file_name, int lo, int hi) { Acrobat.CAcroApp app = new Acrobat.AcroApp(); // Acrobat Acrobat.CAcroPDDoc doc = new Acrobat.AcroPDDoc(); // First document // use reflection to center the pdf try { var opened = doc.Open(selectedPdfFile.FullName); if (opened) { object js_object = doc.GetJSObject(); Type js_type = js_object.GetType(); //object[] js_param = { 0, 0, "/c/scratch/blah.pdf" }; object[] js_param = { lo - 1, hi - 1, new_file_name }; // subtract 1 to make base 0 string script_name = Models.Utilities.AcrobatJS.Javascripts [Models.Utilities.LocalJavascripts.extractPagesFromDocument]; js_type.InvokeMember(script_name, System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, js_object, js_param); } } catch (Exception ex) { UpdateLabelPdf = ex.Message; } finally { doc.Close(); app.CloseAllDocs(); app.Exit(); doc = null; app = null; GC.Collect(); } }
static void Main(string[] args) { if (args.Length > 2) { string originalFile = args[0]; string outputPath = args[1]; string type = args[2]; if (File.Exists(originalFile))//Check File exxists { string fileName = Path.GetFileNameWithoutExtension(originalFile); string fileExtension = Path.GetExtension(originalFile); Acrobat.AcroPDDoc pdfDoc = new Acrobat.AcroPDDoc(); pdfDoc.Open(@originalFile); object jsObj = pdfDoc.GetJSObject(); var jsObjType = jsObj.GetType(); string target = outputPath + "/" + fileName + "." + type; string exportFormat = null; switch (type) { case "eps": exportFormat = "com.adobe.acrobat.eps"; break; case "html": case "htm": exportFormat = "com.adobe.acrobat.html"; break; case "jpg": case "jpeg": case "jpe": exportFormat = "com.adobe.acrobat.jpeg"; break; case "doc": exportFormat = "com.adobe.acrobat.doc"; break; case "docx": exportFormat = "com.adobe.acrobat.docx"; break; case "png": exportFormat = "com.adobe.acrobat.png"; break; case "ps": exportFormat = "com.adobe.acrobat.ps"; break; case "rtf": exportFormat = "com.adobe.acrobat.rtf"; break; case "xlsx": exportFormat = "com.adobe.acrobat.xlsx"; break; /* Doesn't work well * case "xls": * exportFormat = "com.adobe.acrobat.spreadsheet"; * break; */ case "txt": exportFormat = "com.adobe.acrobat.accesstext"; break; case "tiff": case "tif": exportFormat = "com.adobe.acrobat.tiff"; break; case "xml": exportFormat = "com.adobe.acrobat.xml-1-00"; break; } jsObjType.InvokeMember("saveAs", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, jsObj, new object[] { @target, exportFormat }); Console.WriteLine("Convert complete"); } else { Console.WriteLine("PDF doesn't exists"); } } else { Console.WriteLine("Not enough args"); } }