https://github.com/verifytests/verify.questpdf
Extends Verify to allow verification of documents via QuestPDF.
https://github.com/verifytests/verify.questpdf
Last synced: about 1 year ago
JSON representation
Extends Verify to allow verification of documents via QuestPDF.
- Host: GitHub
- URL: https://github.com/verifytests/verify.questpdf
- Owner: VerifyTests
- License: mit
- Created: 2022-05-08T00:06:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T11:24:37.000Z (about 1 year ago)
- Last Synced: 2025-04-14T12:29:57.424Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 1.26 MB
- Stars: 16
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.txt
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
#
Verify.QuestPDF
[](https://github.com/orgs/VerifyTests/discussions)
[](https://ci.appveyor.com/project/SimonCropp/Verify-QuestPDF)
[](https://www.nuget.org/packages/Verify.QuestPDF/)
Extends [Verify](https://github.com/VerifyTests/Verify) to allow verification of documents via [QuestPDF](https://www.questpdf.com/).
**See [Milestones](../../milestones?state=closed) 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
```cs
[ModuleInitializer]
public static void Init()
{
VerifyImageMagick.RegisterComparers(0.015);
VerifyQuestPdf.Initialize();
}
```
snippet source | anchor
This sample uses [Verify.ImageMagick](https://github.com/VerifyTests/Verify.ImageMagick) to ignore small rendering differences that are expected between differens operating systesm.
Other [compares](https://github.com/VerifyTests/Verify/blob/main/docs/comparer.md) options:
* https://github.com/VerifyTests/Verify.ImageHash
* https://github.com/VerifyTests/Verify.ImageMagick
* https://github.com/VerifyTests/Verify.Phash
* https://github.com/VerifyTests/Verify.ImageSharp.Compare
### Code that generates a document
```cs
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
```cs
[Test]
public Task VerifyDocument()
{
var document = GenerateDocument();
return Verify(document);
}
```
snippet source | anchor
### Results
#### Metadata
```txt
{
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:
```cs
[Test]
public Task PagesToInclude()
{
var document = GenerateDocument();
return Verify(document)
.PagesToInclude(1);
}
```
snippet source | anchor
### Dynamic
To dynamically control what pages are rendered:
```cs
[Test]
public Task PagesToIncludeDynamic()
{
var document = GenerateDocument();
return Verify(document)
.PagesToInclude(pageNumber => pageNumber == 2);
}
```
snippet source | anchor