public virtual void AnnotationCheckTest02() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); annot.SetOpacity(new PdfNumber(0.5)); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AnAnnotationDictionaryShallNotContainTheCaKeyWithAValueOtherThan1)); ; }
public virtual void AnnotationCheckTest04() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); annot.SetFlag(PdfAnnotation.INVISIBLE); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.TheFKeysPrintFlagBitShallBeSetTo1AndItsHiddenInvisibleAndNoviewFlagBitsShallBeSetTo0)); ; }
public virtual void KeywordsInfoTestPdfA2b() { String outFile = destinationFolder + "keywordsInfoTestPdfA2b.pdf"; String cmpFile = cmpFolder + "cmp_keywordsInfoTestPdfA2b.pdf"; Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument doc = new PdfADocument(new PdfWriter(outFile), PdfAConformanceLevel.PDF_A_2B, outputIntent); doc.AddNewPage(); doc.GetDocumentInfo().SetKeywords("key1, key2 , key3;key4,key5"); doc.Close(); CompareTool ct = new CompareTool(); NUnit.Framework.Assert.IsNull(ct.CompareByContent(outFile, cmpFile, destinationFolder)); NUnit.Framework.Assert.IsNull(ct.CompareDocumentInfo(outFile, cmpFile)); NUnit.Framework.Assert.IsNull(ct.CompareXmp(outFile, cmpFile, true)); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> private void CreateDocumentWithFont(String outFileName, String fontFileName, String encoding, PdfAConformanceLevel conformanceLevel) { String outPdf = outputDir + outFileName; String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_" + outFileName; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfDocument doc = new PdfADocument(writer, conformanceLevel, new PdfOutputIntent("Custom", "", "http://www.color.org" , "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); PdfFont font = PdfFontFactory.CreateFont(sourceFolder + fontFileName, encoding, true); PdfCanvas canvas = new PdfCanvas(page); canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 12).ShowText("Hello World").EndText( ).RestoreState(); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void TransparencyCheckTest3() { String outPdf = destinationFolder + "pdfA1b_transparencyCheckTest3.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA1b_transparencyCheckTest3.pdf"; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); doc.AddNewPage(); PdfCanvas canvas = new PdfCanvas(doc.GetLastPage()); canvas.SetExtGState(new PdfExtGState().SetSoftMask(PdfName.None)); canvas.Rectangle(30, 30, 100, 100).Fill(); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void AnnotationCheckTest02() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); annot.SetOpacity(new PdfNumber(0.5)); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AN_ANNOTATION_DICTIONARY_SHALL_NOT_CONTAIN_THE_CA_KEY_WITH_A_VALUE_OTHER_THAN_1)); ; }
public virtual void CidFontCheckTest3() { String outPdf = outputDir + "pdfA2b_cidFontCheckTest3.pdf"; String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA2b_cidFontCheckTest3.pdf"; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); // Identity-H must be embedded PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKtc-Light.otf", "Identity-H", true); PdfCanvas canvas = new PdfCanvas(page); canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 12).ShowText("Hello World").EndText( ).RestoreState(); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void AnnotationCheckTest04() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); annot.SetFlag(PdfAnnotation.INVISIBLE); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.THE_F_KEYS_PRINT_FLAG_BIT_SHALL_BE_SET_TO_1_AND_ITS_HIDDEN_INVISIBLE_AND_NOVIEW_FLAG_BITS_SHALL_BE_SET_TO_0)); ; }
public virtual void AnnotationCheckTest06() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfAnnotation annot = new PdfWidgetAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); annot.SetNormalAppearance(new PdfDictionary()); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.APPEARANCE_DICTIONARY_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_STREAM_VALUE)); ; }
public virtual void PdfA1DocWithPdfA1PushButtonFieldTest() { String name = "pdfA1DocWithPdfA1PushButtonField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1PushButtonField.pdf"; PdfFont fontFreeSans = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B; PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom" , "", "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); form.AddField(PdfFormField.CreatePushButton(pdfDoc, new Rectangle(36, 526, 100, 20), "push button", "Push" , fontFreeSans, 12, conformanceLevel)); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
public virtual void AnnotationCheckTest04() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 650, 400, 100); PdfAnnotation annot = new PdfWidgetAnnotation(rect); annot.SetContents(new PdfString("")); annot.SetFlag(PdfAnnotation.PRINT); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.EVERY_ANNOTATION_SHALL_HAVE_AT_LEAST_ONE_APPEARANCE_DICTIONARY)) ; }
public virtual void AnnotationCheckTest03() { String outPdf = destinationFolder + "pdfA2b_annotationCheckTest03.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest03.pdf"; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 0, 0); PdfAnnotation annot = new PdfWidgetAnnotation(rect); annot.SetContents(new PdfString("")); annot.SetFlag(PdfAnnotation.PRINT); page.AddAnnotation(annot); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void PdfA1DocWithPdfA1ComboBoxFieldTest() { String name = "pdfA1DocWithPdfA1ComboBoxField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ComboBoxField.pdf"; PdfFont fontCJK = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKtc-Light.otf", PdfEncodings.IDENTITY_H , true); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B; PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom" , "", "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); form.AddField(PdfFormField.CreateComboBox(pdfDoc, new Rectangle(156, 616, 70, 70), "combo", "用", new String [] { "用", "规", "表" }, fontCJK, conformanceLevel)); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
public virtual void AnnotationCheckTest08() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.SetTagged(); doc.GetCatalog().SetLang(new PdfString("en-US")); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfAnnotation annot = new PdfStampAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AnnotationOfType1ShouldHaveContentsKey)); ; }
public virtual void AnnotationCheckTest09() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 650, 400, 100); PdfAnnotation annot = new PdfWidgetAnnotation(rect); annot.SetContents(new PdfString("")); annot.SetFlags(PdfAnnotation.PRINT); annot.SetNormalAppearance(new PdfDictionary()); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AppearanceDictionaryShallContainOnlyTheNKeyWithStreamValue)); ; }
public virtual void ColorCheckTest3() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new MemoryStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent); PdfCanvas canvas = new PdfCanvas(doc.AddNewPage()); canvas.SetFillColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)); canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom()); canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom()); canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop()); canvas.Fill(); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.DevicecmykMayBeUsedOnlyIfTheFileHasACmykPdfAOutputIntentOrDefaultCmykInUsageContext)); ; }
public virtual void PdfA1DocWithPdfA1ButtonFieldTest() { String name = "pdfA1DocWithPdfA1ButtonField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ButtonField.pdf"; Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B; PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom" , "", "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfFormField emptyField = PdfFormField.CreateEmptyField(pdfDoc, conformanceLevel).SetFieldName("empty"); emptyField.AddKid(PdfFormField.CreateButton(pdfDoc, new Rectangle(36, 756, 20, 20), PdfAnnotation.PRINT, conformanceLevel ).SetFieldName("button").SetValue("hello")); form.AddField(emptyField); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
public virtual void AnnotationCheckTest12() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.SetTagged(); doc.GetCatalog().SetLang(new PdfString("en-US")); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 650, 400, 100); PdfAnnotation annot = new PdfStampAnnotation(rect); annot.SetFlags(PdfAnnotation.PRINT); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(MessageFormatUtil.Format(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY, PdfName.Stamp.GetValue()))) ; }
public virtual void ColorCheckTest3() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new MemoryStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent); PdfCanvas canvas = new PdfCanvas(doc.AddNewPage()); canvas.SetFillColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)); canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom()); canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom()); canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop()); canvas.Fill(); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT_OR_DEFAULTCMYK_IN_USAGE_CONTEXT)) ; }
public virtual void FileSpecCheckTest02() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new MemoryStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); PdfStream stream = new PdfStream(); pdfDocument.GetCatalog().Put(new PdfName("testStream"), stream); PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav" , "sample", null, null); stream.Put(PdfName.F, spec.GetPdfObject()); pdfDocument.AddNewPage(); pdfDocument.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.STREAM_OBJECT_DICTIONARY_SHALL_NOT_CONTAIN_THE_F_FFILTER_OR_FDECODEPARAMS_KEYS)) ; }
public virtual void TestTransparencyObjectsAbsence() { String outPdf = destinationFolder + "transparencyObjectsAbsence.pdf"; String cmpPdf = cmpFolder + "cmp_transparencyObjectsAbsence.pdf"; PdfDocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_3B, null); PdfPage page = pdfDocument.AddNewPage(); PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", true); PdfCanvas canvas = new PdfCanvas(page); canvas.BeginText().MoveText(36, 750).SetFontAndSize(font, 16).ShowText("Page 1").EndText(); PdfDictionary groupObj = new PdfDictionary(); groupObj.Put(PdfName.Type, PdfName.Group); groupObj.Put(PdfName.S, PdfName.Transparency); page.GetPdfObject().Put(PdfName.Group, groupObj); page.GetResources().SetDefaultGray(new PdfCieBasedCs.CalGray(GetCalGrayArray())); pdfDocument.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void FileSpecCheckTest03() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new MemoryStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); PdfStream stream = new PdfStream(); pdfDocument.GetCatalog().Put(new PdfName("testStream"), stream); PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav" , "sample", null, null, true); stream.Put(new PdfName("fileData"), spec.GetPdfObject()); pdfDocument.AddNewPage(); pdfDocument.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.FileSpecificationDictionaryShallNotContainTheEFKey)); ; }
public virtual void AcroFormCheck01() { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.AddNewPage(); PdfDictionary acroForm = new PdfDictionary(); acroForm.Put(PdfName.NeedAppearances, new PdfBoolean(true)); doc.GetCatalog().Put(PdfName.AcroForm, acroForm); try { doc.Close(); NUnit.Framework.Assert.Fail("PdfAConformanceException expected"); } catch (PdfAConformanceException) { } }
public virtual void EgsCheckTest2() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new MemoryStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent); doc.AddNewPage(); PdfCanvas canvas = new PdfCanvas(doc.GetLastPage()); PdfDictionary dict = new PdfDictionary(); dict.Put(PdfName.HalftoneType, new PdfNumber(5)); dict.Put(PdfName.HalftoneName, new PdfName("Test")); canvas.SetExtGState(new PdfExtGState().SetHalftone(dict)); canvas.Rectangle(30, 30, 100, 100).Fill(); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.HALFTONES_SHALL_NOT_CONTAIN_HALFTONENAME)) ; }
public virtual void AddPageInAppendModeTest() { String inputFile = destinationFolder + "in_addPageInAppendModeTest.pdf"; String outputFile = destinationFolder + "out_addPageInAppendModeTest.pdf"; String cmpFile = cmpFolder + "cmp_addPageInAppendModeTest.pdf"; CreateInputPdfADocument(inputFile); PdfDocument pdfADocument = new PdfADocument(new PdfReader(inputFile), new PdfWriter(outputFile), new StampingProperties ().UseAppendMode()); PdfCanvas canvas = new PdfCanvas(pdfADocument.AddNewPage()); canvas.SaveState().BeginText().MoveText(36, 750).SetFontAndSize(PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf" , true), 16).ShowText("This page 2").EndText().RestoreState(); canvas.Release(); pdfADocument.Close(); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(inputFile)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outputFile)); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outputFile, cmpFile, destinationFolder, "diff_" )); }
public virtual void CatalogCheck05() { String outPdf = destinationFolder + "pdfA2b_catalogCheck05.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA2b_catalogCheck05.pdf"; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.AddNewPage(); PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.Put(PdfName.Name, new PdfString("CustomName")); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.Put(PdfName.Name, new PdfString("CustomName1")); PdfArray order = new PdfArray(); PdfDictionary orderItem = new PdfDictionary(); orderItem.Put(PdfName.Name, new PdfString("CustomName2")); order.Add(orderItem); PdfDictionary orderItem1 = new PdfDictionary(); orderItem1.Put(PdfName.Name, new PdfString("CustomName3")); order.Add(orderItem1); config.Put(PdfName.Order, order); PdfArray ocgs = new PdfArray(); ocgs.Add(orderItem); ocgs.Add(orderItem1); ocProperties.Put(PdfName.OCGs, ocgs); configs.Add(config); ocProperties.Put(PdfName.D, d); ocProperties.Put(PdfName.Configs, configs); doc.GetCatalog().Put(PdfName.OCProperties, ocProperties); doc.Close(); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf)); CompareResult(outPdf, cmpPdf); }
public virtual void TransparencyCheckTest1() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new MemoryStream()); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, null); PdfCanvas canvas = new PdfCanvas(doc.AddNewPage()); canvas.SaveState(); canvas.SetExtGState(new PdfExtGState().SetBlendMode(PdfName.Darken)); canvas.Rectangle(100, 100, 100, 100); canvas.Fill(); canvas.RestoreState(); canvas.SaveState(); canvas.SetExtGState(new PdfExtGState().SetBlendMode(PdfName.Lighten)); canvas.Rectangle(200, 200, 100, 100); canvas.Fill(); canvas.RestoreState(); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE)) ; }
public virtual void ColorCheckTest4() { String outPdf = destinationFolder + "pdfA1b_colorCheckTest4.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA1b_colorCheckTest4.pdf"; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); doc.AddNewPage(); PdfCanvas canvas = new PdfCanvas(doc.GetLastPage()); canvas.SetFillColor(ColorConstants.GREEN); canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom()); canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom()); canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop()); canvas.Fill(); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void FileSpecCheckTest03() { String outPdf = destinationFolder + "pdfA3b_fileSpecCheckTest03.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA3b_fileSpecCheckTest03.pdf"; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, outputIntent); PdfPage page = pdfDocument.AddNewPage(); PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); PdfCanvas canvas = new PdfCanvas(page); canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText ().RestoreState(); byte[] somePdf = new byte[25]; pdfDocument.AddAssociatedFile("some pdf file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, somePdf, "some pdf file" , "foo.pdf", PdfName.ApplicationPdf, null, PdfName.Data)); pdfDocument.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void AnnotationCheckTest08() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 650, 400, 100); Rectangle formRect = new Rectangle(400, 100); PdfAnnotation annot = new PdfWidgetAnnotation(rect); annot.SetContents(new PdfString("")); annot.SetFlags(PdfAnnotation.PRINT); annot.GetPdfObject().Put(PdfName.FT, PdfName.Btn); annot.SetNormalAppearance(CreateAppearance(doc, formRect)); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.APPEARANCE_DICTIONARY_OF_WIDGET_SUBTYPE_AND_BTN_FIELD_TYPE_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_DICTIONARY_VALUE)) ; }