Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        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();
            }
        }