add initial png support

This commit is contained in:
Eliot Jones
2020-08-21 10:50:17 +01:00
parent 6f26b274c4
commit 5ac7a957d0
24 changed files with 1521 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -529,6 +529,44 @@
}
}
[Fact]
public void CanWriteSinglePageWithPng()
{
var builder = new PdfDocumentBuilder();
var page = builder.AddPage(PageSize.A4);
var font = builder.AddStandard14Font(Standard14Font.Helvetica);
page.AddText("Piggy", 12, new PdfPoint(25, page.PageSize.Height - 52), font);
var img = IntegrationHelpers.GetDocumentPath("pdfpig.png", false);
var expectedBounds = new PdfRectangle(25, page.PageSize.Height - 300, 200, page.PageSize.Height - 200);
var imageBytes = File.ReadAllBytes(img);
page.AddPng(imageBytes, expectedBounds);
var bytes = builder.Build();
WriteFile(nameof(CanWriteSinglePageWithPng), bytes);
using (var document = PdfDocument.Open(bytes))
{
var page1 = document.GetPage(1);
Assert.Equal("Piggy", page1.Text);
var image = Assert.Single(page1.GetImages());
Assert.NotNull(image);
Assert.Equal(expectedBounds.BottomLeft, image.Bounds.BottomLeft);
Assert.Equal(expectedBounds.TopRight, image.Bounds.TopRight);
Assert.Equal(imageBytes, image.RawBytes);
}
}
private static void WriteFile(string name, byte[] bytes)
{
try