// TODO after DEVSIX-1220 finished: // 1. Create with both inputString and prepareString. // 1.1 Check opening both of these documents with both strings. // 2. Try encrypt document with invalid input string. // 3. Try open encrypted document with password that contains unassigned code points and ensure error is due to wrong password instead of the invalid input string. private void EncryptAes256AndCheck(String filename, byte[] ownerPassword) { int permissions = EncryptionConstants.ALLOW_SCREENREADERS; WriterProperties writerProperties = new WriterProperties().SetStandardEncryption(PdfEncryptionTest.USER, ownerPassword , permissions, EncryptionConstants.ENCRYPTION_AES_256).SetPdfVersion(PdfVersion.PDF_2_0); PdfWriter writer = new PdfWriter(destinationFolder + filename, writerProperties.AddXmpMetadata()); PdfDocument document = new PdfDocument(writer); document.GetDocumentInfo().SetMoreInfo(PdfEncryptionTest.customInfoEntryKey, PdfEncryptionTest.customInfoEntryValue ); PdfPage page = document.AddNewPage(); PdfEncryptionTest.WriteTextBytesOnPageContent(page, PdfEncryptionTest.pageTextContent); page.Flush(); document.Close(); PdfEncryptionTest.CheckDecryptedWithPasswordContent(destinationFolder + filename, ownerPassword, PdfEncryptionTest .pageTextContent); CompareTool compareTool = new CompareTool().EnableEncryptionCompare(); String compareResult = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_", ownerPassword, ownerPassword); if (compareResult != null) { NUnit.Framework.Assert.Fail(compareResult); } }
public virtual void EncryptWithPassword2(String filename, int encryptionType, int compression, bool isPdf2 ) { int permissions = EncryptionConstants.ALLOW_SCREENREADERS; WriterProperties writerProperties = new WriterProperties().SetStandardEncryption(USER, OWNER, permissions, encryptionType); if (isPdf2) { writerProperties.SetPdfVersion(PdfVersion.PDF_2_0); } PdfWriter writer = new PdfWriter(destinationFolder + filename, writerProperties.AddXmpMetadata()); writer.SetCompressionLevel(compression); PdfDocument document = new PdfDocument(writer); document.GetDocumentInfo().SetMoreInfo(customInfoEntryKey, customInfoEntryValue); PdfPage page = document.AddNewPage(); WriteTextBytesOnPageContent(page, pageTextContent); page.Flush(); document.Close(); CompareEncryptedPdf(filename); CheckEncryptedWithPasswordDocumentStamping(filename, OWNER); CheckEncryptedWithPasswordDocumentAppending(filename, OWNER); }
public void ManipulatePdf(string src, string dest) { WriterProperties writerProperties = new WriterProperties(); writerProperties.AddXmpMetadata(); PdfWriter pdfWriter = new PdfWriter(dest, writerProperties); PdfDocument pdfDoc = new PdfDocument(pdfWriter); pdfDoc.GetCatalog().SetLang(new PdfString("en-US")); pdfDoc.SetTagged(); pdfDoc.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo pdfMetaData = pdfDoc.GetDocumentInfo(); pdfMetaData.SetAuthor("Samuel Huylebroeck"); pdfMetaData.AddCreationDate(); pdfMetaData.GetProducer(); pdfMetaData.SetCreator("iText Software"); pdfMetaData.SetKeywords("example, accessibility"); pdfMetaData.SetSubject("PDF accessibility"); // Title is derived from html // pdf conversion ConverterProperties props = new ConverterProperties(); FontProvider fontProvider = new FontProvider(); fontProvider.AddStandardPdfFonts(); fontProvider.AddDirectory(SRC); // The noto-nashk font file (.ttf extension) is placed in the resources props.SetFontProvider(fontProvider); // Base URI is required to resolve the path to source files props.SetBaseUri(SRC); // Setup custom tagworker factory for better tagging of headers DefaultTagWorkerFactory tagWorkerFactory = new AccessibilityTagWorkerFactory(); props.SetTagWorkerFactory(tagWorkerFactory); HtmlConverter.ConvertToPdf(new FileStream(src, FileMode.Open), pdfDoc, props); pdfDoc.Close(); }
public virtual void ImgAttrAlignLeftReadOrderPdfTest() { String pdfDestinationFile = destinationFolder + "imgAttrAlignLeftReadOrderPdf.pdf"; String htmlSource = sourceFolder + "imgAttrAlignLeftReadOrderPdf.html"; String cmpPdfDestinationFile = sourceFolder + "cmp_imgAttrAlignLeftReadOrderPdf.pdf"; FileStream fileOutputStream = new FileStream(pdfDestinationFile, FileMode.Create); WriterProperties writerProperties = new WriterProperties(); writerProperties.AddXmpMetadata(); PdfWriter pdfWriter = new PdfWriter(fileOutputStream, writerProperties); PdfDocument pdfDocument = new PdfDocument(pdfWriter); pdfDocument.GetCatalog().SetLang(new PdfString("en-US")); pdfDocument.SetTagged(); ConverterProperties converterProperties = new ConverterProperties(); converterProperties.SetBaseUri(sourceFolder); FileStream fileInputStream = new FileStream(htmlSource, FileMode.Open, FileAccess.Read); HtmlConverter.ConvertToPdf(fileInputStream, pdfDocument, converterProperties); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(pdfDestinationFile, cmpPdfDestinationFile , destinationFolder)); }