Esempio n. 1
0
        /* validate file name, and if it exists, open it in Acrobat.
         * Then enable tasks.
         */
        private void filenameTextBox_LostFocus(object sender, EventArgs e)
        {
            String   filename = filenameTextBox.Text;
            FileInfo fileinfo = new FileInfo(filename);

            if (fileinfo.Exists)
            {
                filenameTextBox.ForeColor = Color.Black;
                //assume this is a request to load a new doc or reopen the current one
                if (g_AVDoc != null)
                {
                    currentStatus.Text = "Closing Document...";
                    g_AVDoc.Close(0);
                }
                currentStatus.Text = "Opening Document...";
                g_AVDoc            = new AcroAVDoc();
                g_AVDoc.Open(filename, "");
                currentStatus.Text  = "Document Open";
                tasksPanel.Enabled  = true;
                searchPanel.Enabled = true;
            }
            else
            {
                currentStatus.Text        = "Document Doesn't Exist";
                filenameTextBox.ForeColor = Color.Red;
                tasksPanel.Enabled        = false;
                searchPanel.Enabled       = false;
            }
        }
Esempio n. 2
0
        private static void ProcessFile(string file)
        {
            if (g_AVDoc != null)
            {
                g_AVDoc.Close(0);
            }
            g_AVDoc = new AcroAVDoc();
            g_AVDoc.Open(file, "");
            while (!g_AVDoc.IsValid())
            {
                Thread.Sleep(1000);
            }
            if (g_AVDoc.IsValid())
            {
                ExportPages();

                g_AVDoc.Close(1);
            }
            try
            {
                Console.WriteLine("{0}: Copying file", DateTime.Now);
                File.Copy(file, copyPath + Path.GetFileName(file));
                if (archivePath != null)
                {
                    File.Copy(file, archivePath + Path.GetFileName(file));
                }
                File.Delete(file);
                Console.WriteLine("{0}: File deleted", DateTime.Now);
            }
            catch (IOException e)
            {
                Console.WriteLine("Error copying/deleting file {0}: {1}", file, e.Message);
            }
        }
Esempio n. 3
0
        private void AcrobatPrint(string filePath)
        {
            AcroApp app = new AcroApp();

            app.Hide();
            AcroAVDoc doc = new AcroAVDoc();

            doc.Open(filePath, "打印预览");
            int pageCount = doc.GetPDDoc().GetNumPages();

            doc.PrintPagesSilent(0, pageCount - 1, 0, 1, 1);
            doc.Close(1);
            app.Exit();
        }
        /// <summary>
        /// Constructor invoked on auto creation of files.
        /// </summary>
        /// <param name="src"></param>
        /// <param name="list"></param>
        /// <param name="cvLen"></param>
        /// <param name="bind"></param>
        /// <param name="ticket"></param>
        /// <param name="atty"></param>
        public ImposeSaddleStitch(
            string src,
            IOrderedEnumerable <CockleFilePdf> list,
            int cvLen,
            TypeOfBindEnum bind,
            int?ticket,
            string atty)
        {
            SourceFolder    = src;
            ImposedFiles    = new List <CockleFilePdf>(list);
            TypeOfBind      = bind;
            CoverLength     = cvLen;
            PageCountOfBody = 0;
            NewFilesCreated = new List <CockleFilePdf>();

            // get total page count
            ImposedFiles.ForEach(f =>
            {
                using (PdfReader r = new PdfReader(f.FullName))
                {
                    PageCountOfBody += r.NumberOfPages;
                }
            });
            if (PageCountOfBody == 0)
            {
                PageCountOfBody = null;
            }

            // create folder for processed files
            ProcessedFolder = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(SourceFolder, "processed"));

            // create new file names
            NewFileNames = new Dictionary <string, string>
            {
                { "Cover", System.IO.Path.Combine(ProcessedFolder.FullName, "Cover.pdf") },
                { "Brief", System.IO.Path.Combine(ProcessedFolder.FullName, "Brief.pdf") },
                { "Combined", System.IO.Path.Combine(ProcessedFolder.FullName, "Combined.pdf") },
                { "FinalVersion", System.IO.Path.Combine(SourceFolder, string.Format(
                                                             "{0} {1} cv{2}{3}br{4}{5}B4 pr.pdf", ticket, atty,
                                                             ImposedFiles.Any(x => x.FileType == SourceFileTypeEnum.InsideCv) ? " icv " : " ",
                                                             ImposedFiles.Any(x => x.FileType == SourceFileTypeEnum.Motion) ? " brmo " : " ",
                                                             ImposedFiles.Any(x => x.FileType == SourceFileTypeEnum.App_Index) ? " ain " : " ",
                                                             ImposedFiles.Any(x => x.FileType == SourceFileTypeEnum.App_File) ? " app " : " ")
                                                         .Replace("  ", " ")) },
                { "FinalVersionWithOnlyCover", System.IO.Path.Combine(SourceFolder, string.Format("{0} {1} cv B4 pr.pdf", ticket, atty)) }
            };

            bool hasCover = ImposedFiles.Any(f => f.FileType == SourceFileTypeEnum.Cover);

            if (hasCover)
            {
                ImposeCover(ImposedFiles, NewFileNames["Cover"]);
            }

            bool hasOnlyCover = true;

            ImposedFiles.ForEach(f => { if (f.FileType != SourceFileTypeEnum.Cover)
                                        {
                                            hasOnlyCover = false;
                                        }
                                 });
            if (!hasOnlyCover)
            {
                ImposeBrief(ImposedFiles, NewFileNames["Brief"], TypeOfBind);
            }

            // COMBINE COVER WITH BRIEF
            try
            {
                if (hasCover && !hasOnlyCover)
                {
                    if (!combinedImposedCoverAndBrief(NewFileNames["Brief"], NewFileNames["Cover"], NewFileNames["Combined"]))
                    {
                        System.Diagnostics.Debug.WriteLine("Failure here!");
                    }
                }
            }
            catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); }

            // copy file to main folder
            try
            {
                if (System.IO.File.Exists(NewFileNames["FinalVersion"]))
                {
                    System.IO.File.Delete(NewFileNames["FinalVersion"]);
                }
                //File.Copy(NewFileNames["Combined"], NewFileNames["FinalVersion"], true);

                // open, save, close with acrobat
                AcroApp   _myAdobe = new Acrobat.AcroApp();
                AcroAVDoc _acroDoc = new AcroAVDoc();

                CAcroPDDoc _pdDoc = null;
                if (hasOnlyCover)
                {
                    _acroDoc.Open(NewFileNames["Cover"], null);
                    _pdDoc = (Acrobat.AcroPDDoc)(_acroDoc.GetPDDoc());
                    _pdDoc.Save(1, NewFileNames["FinalVersionWithOnlyCover"]);

                    // keep track of files created
                    NewFilesCreated.Add(new CockleFilePdf(
                                            NewFileNames["FinalVersionWithOnlyCover"], atty, ticket, SourceFileTypeEnum.Imposed_Cover, ""));
                }
                else
                {
                    _acroDoc.Open(NewFileNames["Combined"], null);
                    _pdDoc = (Acrobat.AcroPDDoc)(_acroDoc.GetPDDoc());
                    _pdDoc.Save(1, NewFileNames["FinalVersion"]);

                    // keep track of files created
                    NewFilesCreated.Add(new CockleFilePdf(
                                            NewFileNames["FinalVersion"], atty, ticket, SourceFileTypeEnum.Imposed_Cover_and_Brief, ""));
                }
                _pdDoc.Close();
                _acroDoc.Close(0);
                _myAdobe.Exit();
            }
            catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); }

            // attempt to delete processed folder
            try { ProcessedFolder.Delete(true); }
            catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); }
        }