Files
PdfPig/src/UglyToad.PdfPig.Tests/Integration/SinglePageLibreOfficeImages.cs
Eliot Jones 68bcaf3901 #55 move support for images to page and add inline images
support both xobject and inline images. adds unsupported filters so that exceptions are only thrown when accessing lazily evaluated image.bytes property rather than when opening the page.

treat all warnings as errors.
2019-10-08 14:04:36 +01:00

88 lines
2.9 KiB
C#

namespace UglyToad.PdfPig.Tests.Integration
{
using System;
using System.Linq;
using Xunit;
public class SinglePageLibreOfficeImages
{
private static string GetFilePath() => IntegrationHelpers.GetDocumentPath(@"Single Page Images - from libre office.pdf");
[Fact]
public void Has3Images()
{
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
{
var page = document.GetPage(1);
var images = page.GetImages().ToList();
Assert.Equal(3, images.Count);
}
}
[Fact]
public void ImagesHaveCorrectDimensionsAndLocations()
{
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
{
var page = document.GetPage(1);
var images = page.GetImages().OrderBy(x => x.Bounds.Width).ToList();
var pdfPigSquare = images[0];
Assert.Equal(148.3m, pdfPigSquare.Bounds.Width);
Assert.Equal(148.3m, pdfPigSquare.Bounds.Height);
Assert.Equal(60.1m, pdfPigSquare.Bounds.Left);
Assert.Equal(765.8m, pdfPigSquare.Bounds.Top);
var pdfPigSquished = images[1];
Assert.Equal(206.8m, pdfPigSquished.Bounds.Width);
Assert.Equal(83.2m, pdfPigSquished.Bounds.Height);
Assert.Equal(309.8m, pdfPigSquished.Bounds.Left);
Assert.Equal(552.1m, pdfPigSquished.Bounds.Top);
var birthdayPigs = images[2];
Assert.Equal(391m, birthdayPigs.Bounds.Width);
Assert.Equal(267.1m, birthdayPigs.Bounds.Height);
Assert.Equal(102.2m, birthdayPigs.Bounds.Left);
Assert.Equal(426.3m, birthdayPigs.Bounds.Top);
}
}
[Fact]
public void HasCorrectText()
{
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
{
var page = document.GetPage(1);
Assert.Equal("Oink oink", page.Text);
}
}
[Fact]
public void CanAccessImageBytesExceptUnsupported()
{
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
{
var page = document.GetPage(1);
foreach (var image in page.GetImages())
{
try
{
Assert.NotNull(image.Bytes);
}
catch (NotSupportedException )
{
// Should allow access to raw bytes.
Assert.NotNull(image.RawBytes);
}
}
}
}
}
}