Exemple #1
0
        protected override void DoProcessPdf(Job job)
        {
            var    profile        = job.Profile;
            string preProcessFile = null;
            Secure pdf            = null;

            try
            {
                var pdfFile = job.TempOutputFiles.First();
                preProcessFile = MoveFileToPreProcessFile(pdfFile, "PreProcess");
                //CertRegistrar may only be desposed after encryption
                using (var certRegistrar = new CertificateRegistrar(profile.PdfSettings.Signature, job.Passwords.PdfSignaturePassword))
                {
                    var backgroundAdder = new BackgroundAdder(this);
                    backgroundAdder.AddBackground(preProcessFile, profile);

                    var pdfAConverter = new PdfAConverter(this);
                    pdfAConverter.ConvertToPdfA(preProcessFile, profile);

                    pdf = new Secure();
                    pdf.Open(preProcessFile, "");

                    AssemblyHelper assemblyHelper = new AssemblyHelper();
                    pdf.SetInfoEntry("Producer", "PDFCreator " + assemblyHelper.GetPdfforgeAssemblyVersion());

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

                    var signer  = new Signer();
                    var success = signer.SignPdfFile(pdf, profile, certRegistrar.Certificate);

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

                    if (!success)
                    {
                        Validate(pdf);
                    }

                    pdf.Close();
                }
            }
            finally
            {
                pdf?.Close();
                //delete preprocess file
                if (!string.IsNullOrEmpty(preProcessFile))
                {
                    if (File.Exists(preProcessFile))
                    {
                        File.Delete(preProcessFile);
                    }
                }
            }
        }