Skip to content

Extends Verify to allow verification of documents via QuestPDF.

License

Notifications You must be signed in to change notification settings

VerifyTests/Verify.QuestPDF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verify.QuestPDF

Discussions Build status NuGet Status

Extends Verify to allow verification of documents via QuestPDF.

See Milestones for release notes.

Designed to help assert the output of projects using QuestPDF to generate PDFs.

NuGet package

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

Usage

[ModuleInitializer]
public static void Init() =>
    VerifyQuestPdf.Initialize();

snippet source | anchor

Code that generates a document

static IDocument GenerateDocument() =>
    Document.Create(container =>
    {
        container.Page(AddPage);
        container.Page(AddPage);
    });

static void AddPage(PageDescriptor page)
{
    page.Size(PageSizes.A5);
    page.Margin(1, Unit.Centimetre);
    page.PageColor(Colors.Grey.Lighten3);
    page.DefaultTextStyle(_ => _.FontSize(20));

    page.Header()
        .Text("Hello PDF!")
        .SemiBold().FontSize(36);

    page.Content()
        .Column(_ => _.Item()
            .Text(Placeholders.LoremIpsum()));

    page.Footer()
        .AlignCenter()
        .Text(_ =>
        {
            _.Span("Page ");
            _.CurrentPageNumber();
        });
}

snippet source | anchor

Verify a Document

[Test]
public Task VerifyDocument()
{
    var document = GenerateDocument();
    return Verify(document);
}

snippet source | anchor

Results

Metadata

{
  Pages: 2,
  Metadata: {
    CreationDate: DateTimeOffset_1,
    ModifiedDate: DateTimeOffset_2
  },
  Settings: {
    ContentDirection: LeftToRight,
    PdfA: false,
    ImageCompressionQuality: High,
    ImageRasterDpi: 288
  }
}

snippet source | anchor

Pdf as image

PagesToInclude

To render only a defined number of pages at the start of a document:

[Test]
public Task PagesToInclude()
{
    var document = GenerateDocument();
    return Verify(document)
        .PagesToInclude(1);
}

snippet source | anchor

Dynamic

To dynamically control what pages are rendered:

[Test]
public Task PagesToIncludeDynamic()
{
    var document = GenerateDocument();
    return Verify(document)
        .PagesToInclude(pageNumber => pageNumber == 2);
}

snippet source | anchor

About

Extends Verify to allow verification of documents via QuestPDF.

Resources

License

Code of conduct

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages