public virtual void AnnotationCheckTest05() { 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); PdfStream s = new PdfStream("Hello World".GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1)); annot.SetDownAppearance(new PdfDictionary()); annot.SetNormalAppearance(s); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.APPEARANCE_DICTIONARY_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_STREAM_VALUE)) ; }
public virtual void AnnotationCheckTest11() { String outPdf = destinationFolder + "pdfA2b_annotationCheckTest11.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest11.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, 650, 400, 100); Rectangle formRect = new Rectangle(400, 100); PdfAnnotation annot = new PdfTextAnnotation(rect); annot.SetContents(new PdfString("")); annot.SetFlags(PdfAnnotation.PRINT | PdfAnnotation.NO_ZOOM | PdfAnnotation.NO_ROTATE); annot.SetNormalAppearance(CreateAppearance(doc, formRect)); page.AddAnnotation(annot); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void AnnotationCheckTest13() { 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); annot.SetContents("Hello world"); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.EVERY_ANNOTATION_SHALL_HAVE_AT_LEAST_ONE_APPEARANCE_DICTIONARY)); ; }
public virtual void PdfA1DocWithPdfA1SignatureFieldTest() { String name = "pdfA1DocWithPdfA1SignatureField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1SignatureField.pdf"; PdfFont fontFreeSans = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); fontFreeSans.SetSubset(false); 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.CreateSignature(pdfDoc, conformanceLevel).SetFieldName("signature").SetFont(fontFreeSans ).SetFontSize(20)); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
public virtual void AnnotationCheckTest05() { 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); PdfStream s = new PdfStream("Hello World".GetBytes()); annot.SetDownAppearance(new PdfDictionary()); annot.SetNormalAppearance(s); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AppearanceDictionaryShallContainOnlyTheNKeyWithStreamValue)); ; }
public virtual void ColorCheckTest2() { 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_1B, outputIntent); doc.AddNewPage(); PdfCanvas canvas = new PdfCanvas(doc.GetLastPage()); 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)) ; }
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 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 AnnotationCheckTest09() { String outPdf = destinationFolder + "pdfA1a_annotationCheckTest09.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA1a_annotationCheckTest09.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_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); annot.SetContents("Hello world"); page.AddAnnotation(annot); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void TransparencyCheckTest1() { 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_1B, outputIntent); doc.AddNewPage(); PdfCanvas canvas = new PdfCanvas(doc.GetLastPage()); PdfFormXObject xObject = new PdfFormXObject(new Rectangle(100, 100)); PdfCanvas xObjCanvas = new PdfCanvas(xObject, doc); xObjCanvas.Rectangle(30, 30, 10, 10).Fill(); PdfTransparencyGroup group = new PdfTransparencyGroup(); xObject.SetGroup(group); canvas.AddXObject(xObject, new Rectangle(300, 300)); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.A_GROUP_OBJECT_WITH_AN_S_KEY_WITH_A_VALUE_OF_TRANSPARENCY_SHALL_NOT_BE_INCLUDED_IN_A_FORM_XOBJECT)) ; }
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.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AppearanceDictionaryOfWidgetSubtypeAndBtnFieldTypeShallContainOnlyTheNKeyWithDictionaryValue)); ; }
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.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.IfTheDocumentDoesNotContainAPdfAOutputIntentTransparencyIsForbidden)); ; }
public virtual void ColorCheckTest6() { String outPdf = destinationFolder + "pdfA2b_colorCheckTest6.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA2b_colorCheckTest6.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_2B, outputIntent); PdfCanvas canvas = new PdfCanvas(doc.AddNewPage()); String shortText = "text"; PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true); canvas.SetFontAndSize(font, 12); canvas.SetStrokeColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)); canvas.SetFillColor(Color.RED); canvas.BeginText().ShowText(shortText).EndText(); canvas.SetFillColor(DeviceGray.GRAY).BeginText().ShowText(shortText).EndText(); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void PdfA1DocWithPdfA1RadioButtonFieldTest() { String name = "pdfA1DocWithPdfA1RadioButtonField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1RadioButtonField.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); PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "radio group", "", conformanceLevel); PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(36, 496, 20, 20), radioGroup, "1", conformanceLevel). SetBorderWidth(2).SetBorderColor(ColorConstants.ORANGE); PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(66, 496, 20, 20), radioGroup, "2", conformanceLevel). SetBorderWidth(2).SetBorderColor(ColorConstants.ORANGE); form.AddField(radioGroup); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
public virtual void PdfA1DocWithPdfA1ChoiceFieldTest() { String name = "pdfA1DocWithPdfA1ChoiceField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ChoiceField.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); PdfArray options = new PdfArray(); options.Add(new PdfString("Name")); options.Add(new PdfString("Surname")); form.AddField(PdfFormField.CreateChoice(pdfDoc, new Rectangle(36, 696, 100, 70), "choice", "1", options, 0 , fontFreeSans, conformanceLevel)); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
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 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)) ; }
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 FlushingTest01() { String outPdf = destinationFolder + "pdfA1b_flushingTest01.pdf"; String cmpPdf = sourceFolder + "cmp/PdfAFlushingTest/cmp_pdfA1b_flushingTest01.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_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfCanvas canvas = new PdfCanvas(doc.AddNewPage()); PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "Desert.jpg")); imageXObject.MakeIndirect(doc); canvas.AddXObject(imageXObject, new Rectangle(30, 300, 300, 300)); imageXObject.Flush(); if (imageXObject.IsFlushed()) { NUnit.Framework.Assert.Fail("Flushing of unchecked objects shall be forbidden."); } doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void CatalogCheck08() { 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)); 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(); PdfDictionary orderItem2 = new PdfDictionary(); orderItem2.Put(PdfName.Name, new PdfString("CustomName4")); ocgs.Add(orderItem2); PdfDictionary orderItem3 = new PdfDictionary(); orderItem3.Put(PdfName.Name, new PdfString("CustomName5")); ocgs.Add(orderItem3); 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.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS)) ; }
public virtual void RunTest() { //TODO(DEVSIX-2979): Produces non-conforming PDF/A document String file = "pdfABigNumber.pdf"; String filename = destinationFolder + file; using (Stream icm = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read )) { using (PdfADocument pdf = new PdfADocument(new PdfWriter(new FileStream(filename, FileMode.Create)), PdfAConformanceLevel .PDF_A_3U, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", icm))) { using (Document document = new Document(pdf)) { Div div = new Div(); div.SetMinWidth(float.MaxValue / 4); div.SetMinHeight(100); div.SetBackgroundColor(ColorConstants.LIGHT_GRAY); document.Add(div); } } } NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder , "diff_")); }
public virtual void ActionCheck15() { String outPdf = destinationFolder + "pdfA2b_actionCheck15.pdf"; String cmpPdf = sourceFolder + "cmp/PdfA2ActionCheckTest/cmp_pdfA2b_actionCheck15.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.GetOutlines(true); PdfOutline @out = doc.GetOutlines(false); @out.AddOutline("New").AddAction(PdfAction.CreateGoTo("TestDest")); doc.AddNewPage(); doc.Close(); String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"); if (result != null) { NUnit.Framework.Assert.Fail(result); } }
public virtual void FileSpecCheckTest03() { 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_2B, 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(); MemoryStream txt = new MemoryStream(); StreamWriter @out = new StreamWriter(txt); @out.Write("<foo><foo2>Hello world</foo2></foo>"); @out.Dispose(); pdfDocument.AddFileAttachment("foo file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, txt.ToArray(), "foo file" , "foo.xml", PdfName.ApplicationXml, null, PdfName.Source)); pdfDocument.Close(); }
public virtual void PdfA1DocWithPdfA1ListFieldTest() { String name = "pdfA1DocWithPdfA1ListField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ListField.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); PdfChoiceFormField f = PdfFormField.CreateList(pdfDoc, new Rectangle(86, 556, 50, 200), "list", "9", new String [] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, fontFreeSans, conformanceLevel); f.SetValue("4"); f.SetTopIndex(2); f.SetListSelected(new String[] { "3", "5" }); form.AddField(f); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
public virtual void PdfA1bCheckFieldOnAppearanceTest() { String name = "pdfA1b_checkFieldOnAppearance"; String outPath = destinationFolder + name + ".pdf"; String cmpPath = cmpFolder + "cmp_" + name + ".pdf"; String diff = "diff_" + name + "_"; PdfWriter writer = new PdfWriter(outPath); 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)); doc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField chk = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "On", PdfFormField .TYPE_CHECK, PdfAConformanceLevel.PDF_A_1B); chk.SetBorderColor(ColorConstants.BLACK); chk.SetBorderWidth(1); form.AddField(chk); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff )); }
public virtual void CanvasCheckTest1() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); 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_2B, outputIntent); pdfDocument.AddNewPage(); PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage()); for (int i = 0; i < 29; i++) { canvas.SaveState(); } for (int i = 0; i < 28; i++) { canvas.RestoreState(); } pdfDocument.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.GRAPHICS_STATE_STACK_DEPTH_IS_GREATER_THAN_28)) ; }
public virtual void ColourSpaceTest02() { 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(); PdfColorSpace alternateSpace = new PdfDeviceCs.Rgb(); //Tint transformation function is a dictionary PdfArray domain = new PdfArray(new float[] { 0, 1 }); PdfArray range = new PdfArray(new float[] { 0, 1, 0, 1, 0, 1 }); PdfArray C0 = new PdfArray(new float[] { 0, 0, 0 }); PdfArray C1 = new PdfArray(new float[] { 1, 1, 1 }); PdfNumber n = new PdfNumber(1); PdfFunction.Type2 type2 = new PdfFunction.Type2(domain, range, C0, C1, n); PdfColorSpace separationColourSpace = new PdfSpecialCs.Separation("separationTestFunction2", alternateSpace , type2); //Add to document page.GetResources().AddColorSpace(separationColourSpace); doc.Close(); }
public virtual void ColorCheckTest5() { 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()); String shortText = "text"; PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true); canvas.SetFontAndSize(font, 12); canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.CLIP); canvas.SetFillColor(ColorConstants.RED).BeginText().ShowText(shortText).EndText(); canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE); canvas.SetStrokeColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)).BeginText().ShowText(shortText).EndText(); canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL); canvas.SetFillColor(DeviceGray.GRAY).BeginText().ShowText(shortText).EndText(); 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 CatalogCheck01() { 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)); 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("CustomName")); configs.Add(config); ocProperties.Put(PdfName.D, d); ocProperties.Put(PdfName.Configs, configs); doc.GetCatalog().Put(PdfName.OCProperties, ocProperties); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.VALUE_OF_NAME_ENTRY_SHALL_BE_UNIQUE_AMONG_ALL_OPTIONAL_CONTENT_CONFIGURATION_DICTIONARIES)) ; }