/// <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); }
        }
Exemple #2
0
        public ImposePerfectBind(
            string src, IOrderedEnumerable <CockleFilePdf> list, IEnumerable <CockleFilePdf> listFoldouts,
            int cvLen, TypeOfBindEnum bind, int?ticket, string atty)
        {
            this.SourceFolder    = src;
            this.ImposedFiles    = new List <CockleFilePdf>(list);
            this.TypeOfBind      = bind;
            this.CoverLength     = cvLen;
            this.PageCountOfBody = 0;
            this.NewFilesCreated = new List <CockleFilePdf>();

            // create folder for processed files
            this.ProcessedFolder = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(this.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") },
                { "FinalCover", System.IO.Path.Combine(SourceFolder, string.Format("{0} {1} cv B4 PB pr.pdf", ticket, atty)) },
                { "FinalBrief", System.IO.Path.Combine(SourceFolder, string.Format("{0} {1} br app B5 pr.pdf", ticket, atty)) }
            };

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

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

            bool hasOnlyCover = true;

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

            // move files to main folder
            try
            {
                if (hasCover)
                {
                    if (System.IO.File.Exists(this.NewFileNames["FinalCover"]))
                    {
                        System.IO.File.Delete(this.NewFileNames["FinalCover"]);
                    }
                    System.IO.File.Copy(this.NewFileNames["Cover"], this.NewFileNames["FinalCover"], true);
                    this.NewFilesCreated.Add(new CockleFilePdf(
                                                 this.NewFileNames["FinalCover"], atty, ticket, SourceFileTypeEnum.Imposed_Cover, ""));
                }
            }
            catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); }
            try
            {
                if (!hasOnlyCover)
                {
                    if (System.IO.File.Exists(this.NewFileNames["FinalBrief"]))
                    {
                        System.IO.File.Delete(this.NewFileNames["FinalBrief"]);
                    }
                    System.IO.File.Copy(this.NewFileNames["Brief"], this.NewFileNames["FinalBrief"], true);
                    this.NewFilesCreated.Add(new CockleFilePdf(
                                                 this.NewFileNames["FinalBrief"], atty, ticket, SourceFileTypeEnum.Imposed_Brief, ""));
                }
            }
            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); }
        }