public virtual void CalculateProportionallyFitRectangleWithHeightTest() { String fileName = "calculateProportionallyFitRectangleWithHeightTest.pdf"; String destPdf = DESTINATION_FOLDER + fileName; String cmpPdf = SOURCE_FOLDER + "cmp_" + fileName; FileStream fos = new FileStream(destPdf, FileMode.Create); PdfWriter writer = new PdfWriter(fos); PdfDocument document = new PdfDocument(writer); PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(5, 5, 15, 20)); formXObject.Put(PdfName.Matrix, new PdfArray(new float[] { 1, 0.57f, 0, 2, 20, 5 })); new PdfCanvas(formXObject, document).Circle(10, 15, 10).Fill(); PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(SOURCE_FOLDER + "itext.png")); PdfPage page = document.AddNewPage(); PdfCanvas canvas = new PdfCanvas(page); Rectangle rect = PdfXObject.CalculateProportionallyFitRectangleWithHeight(formXObject, 0, 0, 20); canvas.AddXObjectFittedIntoRectangle(formXObject, rect); rect = PdfXObject.CalculateProportionallyFitRectangleWithHeight(imageXObject, 20, 0, 20); canvas.AddXObjectFittedIntoRectangle(imageXObject, rect); canvas.Release(); page.Flush(); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destPdf, cmpPdf, DESTINATION_FOLDER, "diff_" )); }
public virtual void CalculateProportionallyFitRectangleWithHeightForCustomXObjectTest() { NUnit.Framework.Assert.That(() => { PdfXObject pdfXObject = new PdfXObjectTest.CustomPdfXObject(new PdfStream()); PdfXObject.CalculateProportionallyFitRectangleWithHeight(pdfXObject, 0, 0, 20); } , NUnit.Framework.Throws.InstanceOf <ArgumentException>().With.Message.EqualTo("PdfFormXObject or PdfImageXObject expected.")) ; }
public virtual void AddFormXObjectXYHeightLargerOneWithoutMatrixTest() { String fileName = "addXObjectXYHeightLargerOneWithoutMatrixTest.pdf"; String destPdf = DESTINATION_FOLDER + fileName; String cmpPdf = SOURCE_FOLDER + "cmp_" + fileName; FileStream fos = new FileStream(destPdf, FileMode.Create); PdfWriter writer = new PdfWriter(fos); PdfDocument document = new PdfDocument(writer); PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(5, 5, 15, 20)); new PdfCanvas(formXObject, document).Circle(10, 15, 10).Fill(); PdfPage page = document.AddNewPage(); PdfCanvas canvas = new PdfCanvas(page); Rectangle rect = PdfXObject.CalculateProportionallyFitRectangleWithHeight(formXObject, 0, 0, 30); canvas.AddXObjectFittedIntoRectangle(formXObject, rect); canvas.Release(); page.Flush(); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destPdf, cmpPdf, DESTINATION_FOLDER, "diff_" )); }