예제 #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);
                    }
                }
            }
        }
예제 #2
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);
                }
            }
        }