Example #1
0
        protected override void DoProcessPdf(Job job)
        {
            var profile = job.Profile;

            var pdfFile = job.TempOutputFiles.First();

            var backgroundAdder = new BackgroundAdder(this);

            pdfFile = backgroundAdder.AddBackground(pdfFile, profile);

            var pdfAConverter = new PdfAConverter(this);

            pdfFile = pdfAConverter.ConvertToPdfA(pdfFile, profile);

            using (var pdf = new Secure())
            {
                pdf.Open(pdfFile, "");

                pdf.SetInfoEntry("Producer", "PDFCreator " + _versionHelper.ApplicationVersion);

                //Bug in PDF Tools, Linearize breaks encryption
                //pdf.Linearize = true;

                var signer  = new Signer(_certificateManager);
                var success = signer.SignPdfFile(pdf, profile, job.Passwords, job.Accounts);

                if (success)
                {
                    pdfFile = Path.ChangeExtension(pdfFile, "_secured.pdf");
                    var encrypter = new Encrypter();
                    success = encrypter.SaveEncryptedFileAs(pdf, profile, job.Passwords, pdfFile);
                }

                if (success)
                {
                    //Set the final output pdf
                    job.TempOutputFiles.Clear();
                    job.TempOutputFiles.Add(pdfFile);
                }
                else
                {
                    EvaluateError(pdf);
                }
            }
        }