Home

Awesome

<img src="/src/icon.png" height="30px"> Verify.DocNet

Discussions Build status NuGet Status

Extends Verify to allow verification of documents via DocNet.

See Milestones for release notes. Converts pdf documents to png for verification.

This library uses SixLabors ImageSharp for png generation. For commercial application support visit SixLabors/Pricing.

NuGet package

https://nuget.org/packages/Verify.DocNet/

Usage

Enable Verify.DocNet

<!-- snippet: enable -->

<a id='snippet-enable'></a>

[ModuleInitializer]
public static void Initialize()
{
    VerifyDocNet.Initialize();
    VerifyImageMagick.RegisterComparers(
        threshold: 0.13,
        ImageMagick.ErrorMetric.PerceptualHash);
}

<sup><a href='/src/Tests/ModuleInitializer.cs#L3-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-enable' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

VerifyImageMagick.RegisterComparers (provided by https://github.com/VerifyTests/Verify.ImageMagick) allows minor image changes to be ignored.

Verify a file

<!-- snippet: VerifyPdf -->

<a id='snippet-VerifyPdf'></a>

[Test]
public Task VerifyPdf() =>
    VerifyFile("sample.pdf");

<sup><a href='/src/Tests/Samples.cs#L4-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyPdf' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Verify a Stream

<!-- snippet: VerifyPdfStream -->

<a id='snippet-VerifyPdfStream'></a>

[Test]
public Task VerifyPdfStream()
{
    var stream = File.OpenRead("sample.pdf");
    return Verify(stream, "pdf");
}

<sup><a href='/src/Tests/Samples.cs#L30-L39' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyPdfStream' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Result

Samples.VerifyPdf#01.verified.png:

<img src="/src/Tests/Samples.VerifyPdf%2300.verified.png" width="200px">

PreserveTransparency

<!-- snippet: PreserveTransparency -->

<a id='snippet-PreserveTransparency'></a>

[Test]
public Task VerifyPreserveTransparency() =>
    VerifyFile("sample.pdf")
        .PreserveTransparency();

<sup><a href='/src/Tests/Samples.cs#L12-L19' title='Snippet source file'>snippet source</a> | <a href='#snippet-PreserveTransparency' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

PageDimensions

<!-- snippet: PageDimensions -->

<a id='snippet-PageDimensions'></a>

[Test]
public Task VerifyPageDimensions() =>
    VerifyFile("sample.pdf")
        .PageDimensions(new(1080, 1920));

<sup><a href='/src/Tests/Samples.cs#L21-L28' title='Snippet source file'>snippet source</a> | <a href='#snippet-PageDimensions' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

VerifySinglePage

<!-- snippet: VerifySinglePage -->

<a id='snippet-VerifySinglePage'></a>

[Test]
public Task VerifyFirstPage()
{
    var stream = File.OpenRead("sample.pdf");
    return Verify(stream, "pdf").SinglePage(0);
}

[Test]
public Task VerifySecondPage()
{
    var stream = File.OpenRead("sample.pdf");
    return Verify(stream, "pdf").SinglePage(1);
}

<sup><a href='/src/Tests/Samples.cs#L41-L57' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifySinglePage' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

File Samples

http://file-examples.com/

Icon

Pdf designed by Alfredo from The Noun Project.