Example #1
0
        private void DoUpdateXmpMetadata(PdfDocument pdfDocument, ConversionProfile profile, Job job)
        {
            var conformance = GetPdfAConformance(profile.OutputFormat);

            var xmlAuthor    = "";
            var xmlKeywords  = "";
            var xmlKeywords2 = "";
            var xmlSubject   = "";
            var xmlTitle     = "";

            Logger.Debug("Start updateing XMP Metadata for PDF/A");

            var ms = new PDFMetadataStrings("", "", "", "", "", "", "", "");

            var documentIDs = pdfDocument.GetOriginalDocumentId();

            string sDocumentId = GetHexString(GetRandomString(16));

            if (documentIDs != null)
            {
                var    o = documentIDs;
                string s = o.ToString();
                if (s.Length > 0)
                {
                    sDocumentId = GetHexString(s);
                }
            }

            if (!string.IsNullOrEmpty(job.JobInfo.Metadata.Author))
            {
                ms.Author = job.JobInfo.Metadata.Author;
                xmlAuthor = "    <dc:creator>\n" +
                            "     <rdf:Seq>\n" +
                            "      <rdf:li>" + ms.Author + "</rdf:li>\n" +
                            "     </rdf:Seq>\n" +
                            "    </dc:creator>\n";
            }

            if (pdfDocument.GetDocumentInfo().GetMoreInfo("CreationDate") != null)
            {
                ms.CreationDate = pdfDocument.GetDocumentInfo().GetMoreInfo("CreationDate");
            }

            if (!string.IsNullOrEmpty(job.Producer))
            {
                ms.Creator  = job.Producer;
                ms.Producer = job.Producer;
            }
            if (!string.IsNullOrEmpty(job.JobInfo.Metadata.Keywords))
            {
                ms.Keywords = job.JobInfo.Metadata.Keywords;
                xmlKeywords = "    <dc:subject>\n" +
                              "     <rdf:Bag>\n" +
                              "      <rdf:li>" + ms.Keywords + "</rdf:li>\n" +
                              "     </rdf:Bag>\n" +
                              "    </dc:subject>\n";
                xmlKeywords2 = "    <pdf:Keywords>" + ms.Keywords + "</pdf:Keywords>\n";
            }

            if (pdfDocument.GetDocumentInfo().GetMoreInfo("ModDate") != null)
            {
                ms.ModDate = pdfDocument.GetDocumentInfo().GetMoreInfo("ModDate");
            }

            if (!string.IsNullOrEmpty(job.JobInfo.Metadata.Subject))
            {
                ms.Subject = job.JobInfo.Metadata.Subject;
                xmlSubject = "    <dc:description>\n" +
                             "     <rdf:Alt>\n" +
                             "      <rdf:li xml:lang='x-default'>" + ms.Subject + "</rdf:li>\n" +
                             "     </rdf:Alt>\n" +
                             "    </dc:description>\n";
            }

            if (!string.IsNullOrEmpty(job.JobInfo.Metadata.Title))
            {
                ms.Title = job.JobInfo.Metadata.Title;
                xmlTitle = "    <dc:title>\n" +
                           "     <rdf:Alt>\n" +
                           "      <rdf:li xml:lang='x-default'>" + ms.Title + "</rdf:li>\n" +
                           "     </rdf:Alt>\n" +
                           "    </dc:title>\n";
            }

            string metadataStr = "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n" +
                                 " <x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-20:48:00'>\n" +
                                 "  <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n" +
                                 "   <rdf:Description rdf:about='' xmlns:pdfaid='http://www.aiim.org/pdfa/ns/id/' pdfaid:part='" + conformance.Item1 + "' pdfaid:conformance='" + conformance.Item2 + "'>\n" +
                                 "   </rdf:Description>\n" +
                                 "   <rdf:Description rdf:about=''\n" +
                                 "     xmlns:xmp='http://ns.adobe.com/xap/1.0/'>\n" +
                                 "    <xmp:CreateDate>" + GetXmpDate(ms.CreationDate) + "</xmp:CreateDate>\n" +
                                 "    <xmp:ModifyDate>" + GetXmpDate(ms.ModDate) + "</xmp:ModifyDate>\n" +
                                 "    <xmp:CreatorTool>" + ms.Creator + "</xmp:CreatorTool>\n" +
                                 "   </rdf:Description>\n" +
                                 "   <rdf:Description rdf:about=''\n" +
                                 "     xmlns:dc='http://purl.org/dc/elements/1.1/'>\n" +
                                 "    <dc:format>application/pdf</dc:format>\n" + xmlTitle + xmlSubject + xmlAuthor + xmlKeywords +
                                 "   </rdf:Description>\n" +
                                 "   <rdf:Description rdf:about=''\n" +
                                 "     xmlns:xmpMM='http://ns.adobe.com/xap/1.0/mm/'\n" +
                                 "     xmlns:stEvt='http://ns.adobe.com/xap/1.0/sType/ResourceEvent#'>\n" +
                                 "    <xmpMM:DocumentID>uuid:" + sDocumentId + "</xmpMM:DocumentID>\n" +
                                 "    <xmpMM:History><rdf:Seq><rdf:li rdf:parseType='Resource'></rdf:li></rdf:Seq></xmpMM:History>\n" +
                                 "   </rdf:Description>\n" +
                                 "   <rdf:Description rdf:about=''\n" +
                                 "     xmlns:pdf='http://ns.adobe.com/pdf/1.3/'>\n" +
                                 "    <pdf:Producer>" + ms.Producer + "</pdf:Producer>\n" +
                                 xmlKeywords2 +
                                 "   </rdf:Description>\n" +
                                 "  </rdf:RDF>\n" +
                                 " </x:xmpmeta>\n" +
                                 "<?xpacket end='w'?>";

            pdfDocument.SetXmpMetadata(new XMPMetaImpl(new XMPNode("XMP", metadataStr, new PropertyOptions())));
        }
Example #2
0
        /// <summary>
        ///     Determine PDF-Version according to settings in conversion profile.
        /// </summary>
        /// <param name="profile">ConversionProfile</param>
        /// <returns>PDF Version as string as interim value for inherited Processors</returns>
        public string DeterminePdfVersion(ConversionProfile profile)
        {
            //Important:
            //The string value is just an interim value!!!
            //If another PDFVersion is added, the inherited Processors have to evaluate it

            var pdfVersion = "1.3";

            if (profile.OutputFormat != OutputFormat.PdfX)
            {
                pdfVersion = "1.4";
            }

            if (profile.PdfSettings.Signature.Enabled)
            {
                pdfVersion = "1.4"; //todo: Could remain 1.3. Is it necessary to fix this?
            }
            if (profile.BackgroundPage.Enabled)
            {
                pdfVersion = "1.4"; //todo: Could remain 1.3. Is it necessary to fix this?
            }
            if (profile.OutputFormat == OutputFormat.Pdf)
            {
                if (profile.PdfSettings.Security.Enabled)
                {
                    if (profile.PdfSettings.Security.EncryptionLevel == EncryptionLevel.Aes128Bit)
                    {
                        pdfVersion = "1.6";
                    }
                }
            }

            if (profile.OutputFormat != OutputFormat.PdfA1B)
            {
                if (profile.PdfSettings.Signature.Enabled)
                {
                    if (!profile.PdfSettings.Signature.AllowMultiSigning)
                    {
                        pdfVersion = "1.6";
                    }
                }
            }

            if (profile.OutputFormat == OutputFormat.Pdf)
            {
                if (profile.PdfSettings.Security.Enabled)
                {
                    if (profile.PdfSettings.Security.EncryptionLevel == EncryptionLevel.Aes256Bit)
                    {
                        pdfVersion = "1.7";
                    }
                }
            }

            if (profile.OutputFormat == OutputFormat.PdfA2B || profile.OutputFormat == OutputFormat.PdfA3B)
            {
                pdfVersion = "1.7";
            }

            return(pdfVersion);
        }
 public PrintJobInteraction(JobInfo jobInfo, ConversionProfile profile)
 {
     JobInfo = jobInfo;
     Profile = profile;
 }
Example #4
0
 private void SetDefaultProperties(ConversionProfile profile, bool isDeletable)
 {
     profile.Properties.Renamable = false;
     profile.Properties.Deletable = isDeletable;
     profile.Properties.Editable  = true;
 }
Example #5
0
        private ActionResult CheckSignatureSettings(ConversionProfile profile, Accounts accounts, CheckLevel checkLevel)
        {
            var result = new ActionResult();

            var signature = profile.PdfSettings.Signature;

            if (!signature.Enabled)
                return result;

            if (!_outputFormatHelper.IsPdfFormat(profile.OutputFormat))
                return result;

            var isJobLevelCheck = checkLevel == CheckLevel.Job;

            if (profile.AutoSave.Enabled)
            {
                if (string.IsNullOrEmpty(signature.SignaturePassword))
                {
                    _logger.Error("Automatic saving without certificate password.");
                    result.Add(ErrorCode.Signature_AutoSaveWithoutCertificatePassword);
                }
            }

            var timeServerAccount = accounts.GetTimeServerAccount(profile);
            if (timeServerAccount == null)
            {
                _logger.Error("The specified time server account for signing is not configured.");
                result.Add(ErrorCode.Signature_NoTimeServerAccount);
            }
            else
            {
                if (timeServerAccount.IsSecured)
                {
                    if (string.IsNullOrEmpty(timeServerAccount.UserName))
                    {
                        _logger.Error("Secured Time Server without Login Name.");
                        result.Add(ErrorCode.Signature_SecuredTimeServerWithoutUsername);
                    }
                    if (string.IsNullOrEmpty(timeServerAccount.Password))
                    {
                        _logger.Error("Secured Time Server without Password.");
                        result.Add(ErrorCode.Signature_SecuredTimeServerWithoutPassword);
                    }
                }
            }

            var certificateFile = profile.PdfSettings.Signature.CertificateFile;

            if (string.IsNullOrEmpty(certificateFile))
            {
                _logger.Error("Error in signing. Missing certification file.");
                result.Add(ErrorCode.ProfileCheck_NoCertificationFile);
                return result;
            }

            if (!isJobLevelCheck && TokenIdentifier.ContainsTokens(certificateFile))
                return result;

            var pathUtilStatus = _pathUtil.IsValidRootedPathWithResponse(profile.PdfSettings.Signature.CertificateFile);
            switch (pathUtilStatus)
            {
                case PathUtilStatus.InvalidRootedPath:
                    result.Add(ErrorCode.CertificateFile_InvalidRootedPath);
                    return result;

                case PathUtilStatus.PathTooLongEx:
                    result.Add(ErrorCode.CertificateFile_TooLong);
                    return result;

                case PathUtilStatus.NotSupportedEx:
                    result.Add(ErrorCode.CertificateFile_InvalidRootedPath);
                    return result;

                case PathUtilStatus.ArgumentEx:
                    result.Add(ErrorCode.CertificateFile_IllegalCharacters);
                    return result;
            }

            if (!isJobLevelCheck && certificateFile.StartsWith(@"\\"))
                return result;

            if (!_file.Exists(certificateFile))
            {
                _logger.Error("Error in signing. The certification file '" + certificateFile +
                              "' doesn't exist.");
                result.Add(ErrorCode.CertificateFile_CertificateFileDoesNotExist);
            }

            return result;
        }
 private bool ProfileExists(ConversionProfile profile, IList <ConversionProfile> profiles)
 {
     return(profiles.Any(p => p.Name == profile.Name || p.Guid == profile.Guid));
 }
Example #7
0
 public static IEnumerable <TActionType> FilterForEnabledInProfile <TActionType>(this List <IAction> list, ConversionProfile profile) where TActionType : IAction
 {
     return(list.OfType <TActionType>().Where(x => x.IsEnabled(profile)));
 }
Example #8
0
        private PrintJobViewModel BuildViewModel(ApplicationSettings appSettings, IList <ConversionProfile> profiles, IJobInfoQueue queue, ConversionProfile preselectedProfile = null)
        {
            var settings = new PdfCreatorSettings(MockRepository.GenerateStub <IStorage>());

            settings.ApplicationSettings = appSettings;
            settings.ConversionProfiles  = profiles;

            var settingsHelper = Substitute.For <ISettingsProvider>();

            settingsHelper.Settings.Returns(settings);

            var settingsManager = Substitute.For <ISettingsManager>();

            settingsManager.GetSettingsProvider().Returns(settingsHelper);

            var translator = new BasicTranslator("default", _translationData);

            var userGuideHelper = Substitute.For <IUserGuideHelper>();

            var printJobViewModel = new PrintJobViewModel(settingsManager, queue, translator, new DragAndDropEventHandler(Substitute.For <IFileConversionHandler>()), MockRepository.GenerateStub <IInteractionInvoker>(), userGuideHelper, new ApplicationNameProvider("PDFCreator"));

            var interaction = new PrintJobInteraction(null, preselectedProfile);

            var interactionHelper = new InteractionHelper <PrintJobInteraction>(printJobViewModel, interaction);

            return(printJobViewModel);
        }
Example #9
0
 public void ResetProfileToDefault()
 {
     _profile            = new ConversionProfile();
     _profile.OpenViewer = false;
 }
 public ConversionProfileWrapper(ConversionProfile conversionProfile)
 {
     ConversionProfile = conversionProfile;
     MountView();
 }
 public void Setup()
 {
     _profile            = new ConversionProfile();
     _translationFactory = new TranslationFactory();
 }
Example #12
0
 public void ForceDefaultOrder(ConversionProfile conversionWorkflow)
 {
     conversionWorkflow.ActionOrder.Sort((x, y) => Comparison(x, y, conversionWorkflow));
 }
Example #13
0
        private static PdfStamper DoCreateStamperAccordingToEncryptionAndSignature(string sourceFilename, string destinationFilename, ConversionProfile profile, char pdfVersion)
        {
            Logger.Debug("Started creating PdfStamper according to Encryption.");

            var        reader     = new PdfReader(sourceFilename);
            var        fileStream = new FileStream(destinationFilename, FileMode.Create, FileAccess.Write);
            PdfStamper stamper    = null;

            if (profile.PdfSettings.Signature.Enabled)
            {
                stamper = PdfStamper.CreateSignature(reader, fileStream, pdfVersion);
            }
            else
            {
                stamper = new PdfStamper(reader, fileStream, pdfVersion);
            }

            if (stamper == null)
            {
                throw new ProcessingException("PDFStamper could not be created", ErrorCode.Encryption_Error);
            }
            return(stamper);
        }
Example #14
0
        /// <summary>
        ///     Create a PdfStamper with content of source file aiming to destination file.
        ///     If encryption is enabled, the stamper will be created with an corresponding signature,
        ///     which influences the PDF version. (1.4 for 40bit and 128bit encryption, 1.6 for 128bitAes).
        /// </summary>
        /// <param name="sourceFile">Full path to the source file</param>
        /// <param name="destinationFile">Full patch to the destination file</param>
        /// <param name="profile">Profile with encryption settings</param>
        /// <param name="pdfVersion">PDF Version as string, i.e. "1.6"</param>
        /// <returns>Stamper with content of source file stream, aiming to destination file</returns>
        /// <exception cref="ProcessingException">In case of any error</exception>
        internal static PdfStamper CreateStamperAccordingToEncryptionAndSignature(string sourceFile, string destinationFile, ConversionProfile profile,
                                                                                  char pdfVersion)
        {
            PdfStamper stamper;

            try
            {
                stamper = DoCreateStamperAccordingToEncryptionAndSignature(sourceFile, destinationFile, profile, pdfVersion);
            }
            catch (ProcessingException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ProcessingException(ex.GetType() + " while creating stamper:" + Environment.NewLine + ex.Message, ErrorCode.Encryption_GenericError);
            }

            return(stamper);
        }
 public static ConversionProfileUpdateRequestBuilder Update(int id, ConversionProfile conversionProfile)
 {
     return(new ConversionProfileUpdateRequestBuilder(id, conversionProfile));
 }
        private void DoUpdateXmpMetadata(PdfStamper stamper, ConversionProfile profile)
        {
            if (profile.OutputFormat != OutputFormat.PdfA2B)
            {
                return;
            }

            Logger.Debug("Start updateing XMP Metadata for PDF/A");

            var ms = new PDFMetadataStrings("", "", "", "", "", "", "", "");
            //var reader = new PdfReader(sourceFilename);
            var reader = stamper.Reader;

            var doc = new XmlDocument();
            var xmlMetadataString = Encoding.UTF8.GetString(reader.Metadata);

            doc.LoadXml(xmlMetadataString);
            var pdfa = "";

            if (xmlMetadataString.IndexOf("pdfaid:part='1'", StringComparison.InvariantCultureIgnoreCase) >= 0)
            {
                pdfa = "<pdfaid:part>1</pdfaid:part>\n";
            }
            else if (xmlMetadataString.IndexOf("pdfaid:part='2'", StringComparison.InvariantCultureIgnoreCase) >= 0)
            {
                pdfa = "<pdfaid:part>2</pdfaid:part>\n";
            }
            var pdfaConformance = "";

            if (xmlMetadataString.IndexOf("pdfaid:conformance='A'", StringComparison.InvariantCultureIgnoreCase) >= 0)
            {
                pdfaConformance = "<pdfaid:conformance>A</pdfaid:conformance>\n";
            }
            else if (xmlMetadataString.IndexOf("pdfaid:conformance='B'", StringComparison.InvariantCultureIgnoreCase) >= 0)
            {
                pdfaConformance = "<pdfaid:conformance>B</pdfaid:conformance>\n";
            }

            var documentIDs = (PdfArray)reader.Trailer.Get(PdfName.ID);

            var sDocumentId = GetHexString(GetRandomString(16));

            if (documentIDs != null)
            {
                var o = documentIDs.ArrayList[0];
                var s = o.ToString();
                if (s.Length > 0)
                {
                    sDocumentId = GetHexString(s);
                }
            }

            var xmlAuthor = "";

            if (reader.Info.ContainsKey("Author"))
            {
                ms.Author = reader.Info["Author"];
                xmlAuthor = "    <dc:creator>\n" +
                            "     <rdf:Seq>\n" +
                            "      <rdf:li>" + ms.Author + "</rdf:li>\n" +
                            "     </rdf:Seq>\n" +
                            "    </dc:creator>\n";
            }

            if (reader.Info.ContainsKey("CreationDate"))
            {
                ms.CreationDate = reader.Info["CreationDate"];
            }

            if (reader.Info.ContainsKey("Creator"))
            {
                ms.Creator = reader.Info["Creator"];
            }

            string xmlKeywords = "", xmlKeywords2 = "";

            if (reader.Info.ContainsKey("Keywords"))
            {
                ms.Keywords = reader.Info["Keywords"];
                xmlKeywords = "    <dc:subject>\n" +
                              "     <rdf:Bag>\n" +
                              "      <rdf:li>" + ms.Keywords + "</rdf:li>\n" +
                              "     </rdf:Bag>\n" +
                              "    </dc:subject>\n";
                xmlKeywords2 = "    <pdf:Keywords>" + ms.Keywords + "</pdf:Keywords>\n";
            }

            if (reader.Info.ContainsKey("ModDate"))
            {
                ms.ModDate = reader.Info["ModDate"];
            }

            if (reader.Info.ContainsKey("Producer"))
            {
                ms.Producer = reader.Info["Producer"];
            }

            var xmlSubject = "";

            if (reader.Info.ContainsKey("Subject"))
            {
                ms.Subject = reader.Info["Subject"];
                xmlSubject = "    <dc:description>\n" +
                             "     <rdf:Alt>\n" +
                             "      <rdf:li xml:lang='x-default'>" + ms.Subject + "</rdf:li>\n" +
                             "     </rdf:Alt>\n" +
                             "    </dc:description>\n";
            }

            var xmlTitle = "";

            if (reader.Info.ContainsKey("Title"))
            {
                ms.Title = reader.Info["Title"];
                xmlTitle = "    <dc:title>\n" +
                           "     <rdf:Alt>\n" +
                           "      <rdf:li xml:lang='x-default'>" + ms.Title + "</rdf:li>\n" +
                           "     </rdf:Alt>\n" +
                           "    </dc:title>\n";
            }

            var metadataStr = "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n" +
                              " <x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-20:48:00'>\n" +
                              "  <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n" +
                              "   <rdf:Description rdf:about='' xmlns:pdfaid='http://www.aiim.org/pdfa/ns/id/'>\n" +
                              pdfa +
                              pdfaConformance +
                              "   </rdf:Description>\n" +
                              "   <rdf:Description rdf:about=''\n" +
                              "     xmlns:xmp='http://ns.adobe.com/xap/1.0/'>\n" +
                              "    <xmp:CreateDate>" + GetXmpDate(ms.CreationDate) + "</xmp:CreateDate>\n" +
                              "    <xmp:ModifyDate>" + GetXmpDate(ms.ModDate) + "</xmp:ModifyDate>\n" +
                              "    <xmp:CreatorTool>" + ms.Creator + "</xmp:CreatorTool>\n" +
                              "   </rdf:Description>\n" +
                              "   <rdf:Description rdf:about=''\n" +
                              "     xmlns:dc='http://purl.org/dc/elements/1.1/'>\n" +
                              "    <dc:format>application/pdf</dc:format>\n" + xmlTitle + xmlSubject + xmlAuthor + xmlKeywords +
                              "   </rdf:Description>\n" +
                              "   <rdf:Description rdf:about=''\n" +
                              "     xmlns:xmpMM='http://ns.adobe.com/xap/1.0/mm/'\n" +
                              "     xmlns:stEvt='http://ns.adobe.com/xap/1.0/sType/ResourceEvent#'>\n" +
                              "    <xmpMM:DocumentID>uuid:" + sDocumentId + "</xmpMM:DocumentID>\n" +
                              "    <xmpMM:History><rdf:Seq><rdf:li rdf:parseType='Resource'></rdf:li></rdf:Seq></xmpMM:History>\n" +
                              "   </rdf:Description>\n" +
                              "   <rdf:Description rdf:about=''\n" +
                              "     xmlns:pdf='http://ns.adobe.com/pdf/1.3/'>\n" +
                              "    <pdf:Producer>" + ms.Producer + "</pdf:Producer>\n" +
                              xmlKeywords2 +
                              "   </rdf:Description>\n" +
                              "  </rdf:RDF>\n" +
                              " </x:xmpmeta>\n" +
                              "<?xpacket end='w'?>";

            var textEncoding = Encoding.GetEncoding("iso-8859-1");
            var newMetadata  = Encoding.Convert(Encoding.Default, Encoding.UTF8, textEncoding.GetBytes(metadataStr));

            stamper.Writer.XmpMetadata = newMetadata;
        }
 public bool IsEnabled(ConversionProfile profile)
 {
     return(profile.CustomScript.Enabled);
 }
 public bool IsEnabled(ConversionProfile profile)
 {
     return(profile.OpenViewer.Enabled);
 }
Example #19
0
        private List <IAction> CreateActionListWithOrder(ConversionProfile profile)
        {
            var orderedWorkflowList = profile.ActionOrder.Select(s => _actionFacades.FirstOrDefault(x => x.SettingsType.Name == s));

            return(orderedWorkflowList.Select(actionFacade => _allActions.FirstOrDefault(action => actionFacade != null && action.GetType() == actionFacade.Action)).ToList());
        }
Example #20
0
        /// <summary>
        ///     Checks for the correct PDF version and permission value, according to the pdf security settings.
        /// </summary>
        /// <param name="file">PDF Testfile</param>
        /// <param name="profile">Profile used for processing</param>
        /// <param name="ownerPassword">Owner Password to open secured file (set any value except NULL if encryption was disabled)</param>
        public static void DoSecurityTest(string file, ConversionProfile profile, string ownerPassword, bool isIText)
        {
            if (!profile.PdfSettings.Security.Enabled)
            {
                Assert.That(() =>
                {
                    var reader = new PdfReader(file);
                    Assert.AreEqual(PdfWriter.VERSION_1_4, reader.PdfVersion, "Pdf Version is not set to 1.4.");
                    Assert.AreEqual(-1, reader.GetCryptoMode(), "Encryption mode is not -1 (disabled)");
                    Assert.AreEqual(0, reader.Permissions, "Wrong permission value");
                }, !Throws.Exception.TypeOf <BadPasswordException>());
                return;
            }

            var pdfReader = new PdfReader(file, Encoding.Default.GetBytes(ownerPassword));

            CheckEncryptionLevel(profile, isIText, pdfReader);

            #region check permissions

            long permissionCode = pdfReader.Permissions;
            Assert.AreEqual(-3904, permissionCode & -3904, "Permission-Bit 7-8 and 13-32 are not true! (PDF-Reference)");
            Assert.AreEqual(-4, permissionCode | -4, "Permission-Bit 1-2 are not false! (PDF-Reference)");

            if (profile.PdfSettings.Security.AllowToCopyContent)
            {
                Assert.AreEqual(PdfWriter.ALLOW_COPY, permissionCode & PdfWriter.ALLOW_COPY,
                                "Requested Allow-Copy is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else
            {
                Assert.AreEqual(0, permissionCode & PdfWriter.ALLOW_COPY,
                                "Unrequested Allow-Copy is set");
            }

            if (profile.PdfSettings.Security.AllowToEditComments)
            {
                Assert.AreEqual(PdfWriter.ALLOW_MODIFY_ANNOTATIONS, permissionCode & PdfWriter.ALLOW_MODIFY_ANNOTATIONS,
                                "Requested Allow-Modify-Annotations is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else
            {
                Assert.AreEqual(0, permissionCode & PdfWriter.ALLOW_MODIFY_ANNOTATIONS,
                                "Unrequested Allow-Modify-Annotations is set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }

            if (profile.PdfSettings.Security.AllowToEditTheDocument)
            {
                Assert.AreEqual(PdfWriter.ALLOW_MODIFY_CONTENTS, permissionCode & PdfWriter.ALLOW_MODIFY_CONTENTS,
                                "Requested Allow-Modify-Content is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else
            {
                Assert.AreEqual(0, permissionCode & PdfWriter.ALLOW_MODIFY_CONTENTS,
                                "Unrequested Allow-Modify-Content is set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }

            //Printing
            Assert.IsFalse(!profile.PdfSettings.Security.AllowPrinting && profile.PdfSettings.Security.RestrictPrintingToLowQuality, "Restrict to degraded printing is set without allowed printing");

            if (profile.PdfSettings.Security.AllowPrinting && (!profile.PdfSettings.Security.RestrictPrintingToLowQuality || (profile.PdfSettings.Security.EncryptionLevel == EncryptionLevel.Rc40Bit)))
            {
                Assert.AreEqual(PdfWriter.ALLOW_PRINTING, permissionCode & PdfWriter.ALLOW_PRINTING,
                                "Requested Allow-Printing is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else if (!profile.PdfSettings.Security.AllowPrinting && (profile.PdfSettings.Security.EncryptionLevel == EncryptionLevel.Rc40Bit))
            {
                Assert.AreEqual(2048, permissionCode & PdfWriter.ALLOW_PRINTING,
                                "Requested Allow-Printing is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else if (!profile.PdfSettings.Security.AllowPrinting && !profile.PdfSettings.Security.RestrictPrintingToLowQuality)
            {
                Assert.AreEqual(0, permissionCode & PdfWriter.ALLOW_PRINTING,
                                "Unrequested Allow-Printing is set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else if (profile.PdfSettings.Security.AllowPrinting && profile.PdfSettings.Security.RestrictPrintingToLowQuality)
            {
                Assert.AreEqual(PdfWriter.ALLOW_DEGRADED_PRINTING, permissionCode & PdfWriter.ALLOW_PRINTING,
                                "No Restriction to degraded printing (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }

            //Extended permission set automatically for 40BitEncryption
            if (profile.PdfSettings.Security.AllowToEditAssembly || (profile.PdfSettings.Security.EncryptionLevel == EncryptionLevel.Rc40Bit))
            {
                Assert.AreEqual(PdfWriter.ALLOW_ASSEMBLY, permissionCode & PdfWriter.ALLOW_ASSEMBLY,
                                "Requested Allow-Assembly is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else
            {
                Assert.AreEqual(0, permissionCode & PdfWriter.ALLOW_ASSEMBLY,
                                "Unrequested Allow-Assembly is set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }

            //Extended permission set automatically for 40BitEncryption
            if (profile.PdfSettings.Security.AllowToFillForms || (profile.PdfSettings.Security.EncryptionLevel == EncryptionLevel.Rc40Bit))
            {
                Assert.AreEqual(PdfWriter.ALLOW_FILL_IN, permissionCode & PdfWriter.ALLOW_FILL_IN,
                                "Requested Allow-Fill-In is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else
            {
                Assert.AreEqual(0, permissionCode & PdfWriter.ALLOW_FILL_IN,
                                "Unrequested Allow-Fill-In is set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }

            //Extended permission set automatically for 40BitEncryption
            if (profile.PdfSettings.Security.AllowScreenReader || (profile.PdfSettings.Security.EncryptionLevel == EncryptionLevel.Rc40Bit))
            {
                Assert.AreEqual(PdfWriter.ALLOW_SCREENREADERS, permissionCode & PdfWriter.ALLOW_SCREENREADERS,
                                "Requested Allow-ScreenReaders is not set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }
            else
            {
                Assert.AreEqual(0, permissionCode & PdfWriter.ALLOW_SCREENREADERS,
                                "Unrequested Allow-ScreenReaders is set (" + profile.PdfSettings.Security.EncryptionLevel + ")");
            }

            #endregion
        }
Example #21
0
 public bool IsEnabled(ConversionProfile profile)
 {
     return(profile.DropboxSettings.Enabled);
 }
 private void UpdateActionOrderList(ConversionProfile profile, IEnumerable <string> newOrderList)
 {
     profile.ActionOrder.Clear();
     profile.ActionOrder.AddRange(newOrderList);
 }
Example #23
0
        private void DoAddBackground(PdfStamper stamper, ConversionProfile profile, IList <IDisposable> resources)
        {
            if (!profile.BackgroundPage.Enabled)
            {
                return;
            }

            Logger.Debug("Start adding background.");

            var nFile = stamper.Reader.NumberOfPages;

            var backgroundPdfReader = new PdfReader(profile.BackgroundPage.File);

            resources.Add(backgroundPdfReader);

            Logger.Debug("BackgroundFile: " + Path.GetFullPath(profile.BackgroundPage.File));
            var nBackground = backgroundPdfReader.NumberOfPages;

            int numberOfFrontPagesWithoutBackground;

            try
            {
                numberOfFrontPagesWithoutBackground = StartOffsetAccordingToCover(profile);
            }
            catch (Exception ex)
            {
                throw new ProcessingException(
                          ex.GetType() + " while detecting number of pages of the cover file: " + profile.AttachmentPage.File +
                          "\r\n" + ex, ErrorCode.Cover_CouldNotOpenFile, ex);
            }

            int lastPageWithBackground;

            try
            {
                lastPageWithBackground = nFile - EndOffsetAccordingToAttachment(profile);
            }
            catch (Exception ex)
            {
                throw new ProcessingException(
                          "Exception while detecting number of pages of the attachment file: " + profile.AttachmentPage.File +
                          "\r\n" + ex, ErrorCode.Attachment_CouldNotOpenFile, ex);
            }

            for (var i = 1; i <= nFile; i++)
            {
                var backgroundPageNumber = GetBackgroundPageNumber(i, nBackground, profile.BackgroundPage.Repetition,
                                                                   numberOfFrontPagesWithoutBackground, lastPageWithBackground);
                if (backgroundPageNumber < 1)
                {
                    continue;
                }

                var backgroundPage     = stamper.GetImportedPage(backgroundPdfReader, backgroundPageNumber);
                var backgroundPageSize = backgroundPdfReader.GetPageSize(backgroundPageNumber);

                var backgroundPageRotation = backgroundPdfReader.GetPageRotation(backgroundPageNumber);

                var documentPage     = stamper.GetUnderContent(i);
                var documentPageSize = stamper.Reader.GetPageSize(i);

                if ((stamper.Reader.GetPageRotation(i) == 90) || (stamper.Reader.GetPageRotation(i) == 270))
                {
                    //Turn with document page...
                    //*
                    backgroundPageRotation += 90;
                    backgroundPageRotation  = backgroundPageRotation % 360;
                    //*/
                    documentPageSize = new Rectangle(documentPageSize.Height, documentPageSize.Width);
                }

                AddPageWithRotationAndScaling(documentPage, documentPageSize, backgroundPage, backgroundPageSize, backgroundPageRotation);
            }
        }
 public void SetUp()
 {
     _profile    = new ConversionProfile();
     _smtpAction = new SmtpMailAction(Substitute.For <ISmtpPasswordProvider>());
 }
Example #25
0
 protected AbstractJob(IJobInfo jobInfo, ConversionProfile profile, JobTranslations jobTranslations)
     : this(jobInfo, profile, jobTranslations, new FileWrap(), new DirectoryWrap())
 {
 }
Example #26
0
 public override bool IsEnabled(ConversionProfile profile)
 {
     return(profile.Ftp.Enabled);
 }
 public bool IsEnabled(ConversionProfile profile)
 {
     return(profile.Printing.Enabled);
 }
 public static ConversionProfileAddRequestBuilder Add(ConversionProfile conversionProfile)
 {
     return(new ConversionProfileAddRequestBuilder(conversionProfile));
 }
 public bool IsEnabled(ConversionProfile profile)
 {
     return(profile.EmailClientSettings.Enabled);
 }
Example #30
0
 /// <summary>
 /// Creates a new EncryptPdfAction
 /// </summary>
 /// <param name="profile">The profile that is used for encrypting the pdf file</param>
 public EncryptPdfAction(ConversionProfile profile)
 {
     this.Profile = profile;
 }