.NET verifier SDK: PDF extraction
PayslipPdfReader
Section titled “PayslipPdfReader”Class in Verifiabl.Verifier.Extraction.Pdf
Reads the Verifiabl payload in a payslip PDF: its metadata payload, or its QR code when it has none.
The metadata payload is the XMP property payload in the
https://verifiabl.io/ns/ namespace. Only when the PDF has none are its
pages rendered and read for a QR code, so a code drawn as vector shapes is
found as well as one in an image. The payload is returned unchanged.
PDFs are untrusted, so they are read in a WebAssembly sandbox with no access to the host process.
public static class PayslipPdfReaderInheritance: System.Object
MaxPdfBytes
Section titled “MaxPdfBytes”Field
The largest PDF read: 20 MiB, the same limit as the Verifiabl portal.
public const int MaxPdfBytes = 20971520Returns: System.Int32
MaxPages
Section titled “MaxPages”Field
The most pages rendered. A longer PDF without a metadata payload is refused rather than read in part.
public const int MaxPages = 50Returns: System.Int32
Read(byte[], CancellationToken)
Section titled “Read(byte[], CancellationToken)”Method
Read the payload on the calling thread, without a time budget.
public static PdfPayloads Read(byte[] pdf, CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
pdf |
System. |
The PDF bytes, at most Verifiabl.. |
cancellationToken |
System. |
Stops reading within about 50 milliseconds. |
Returns: Verifiabl.Verifier.Extraction.Pdf.PdfPayloads, The payload found: the metadata payload, the QR code, or neither.
Exceptions
| Type | Condition |
|---|---|
Verifiabl. |
The PDF is too large, cannot be read, holds two different metadata payloads, or has no metadata payload and has too many pages or two different QR codes. |
System. |
Wasmtime’s native library could not be loaded. |
ReadAsync(byte[], PdfReadOptions?, CancellationToken)
Section titled “ReadAsync(byte[], PdfReadOptions?, CancellationToken)”Method
Read the payload within Verifiabl..
Reading runs on the thread pool, at most one read for each processor at a
time across the process, and the sandbox stops reading when the time
budget runs out.
The budget starts once the sandbox’s module is compiled, which the first
read in a process waits for; see Verifiabl..
public static Task<PdfPayloads> ReadAsync(byte[] pdf, PdfReadOptions? options = null, CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
pdf |
System. |
The PDF bytes, at most Verifiabl.. |
options |
Verifiabl. |
Optional settings, such as the time budget. |
cancellationToken |
System. |
Cancels reading. |
Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Pdf.PdfPayloads}, The payload found: the metadata payload, the QR code, or neither.
Exceptions
| Type | Condition |
|---|---|
Verifiabl. |
The PDF is too large, cannot be read, holds two different metadata payloads, has no metadata payload and has too many pages or two different QR codes, or reading took longer than the time budget. |
ReadAsync(Stream, PdfReadOptions?, CancellationToken)
Section titled “ReadAsync(Stream, PdfReadOptions?, CancellationToken)”Method
Read the payload from a stream within Verifiabl..
The stream is read to its end and not disposed.
The time budget covers reading the stream and the PDF. The stream is only read, never abandoned: if it ignores cancellation, this call waits for its read to return, so the stream is not used after the call ends.
public static Task<PdfPayloads> ReadAsync(Stream pdf, PdfReadOptions? options = null, CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
pdf |
System. |
The PDF bytes, at most Verifiabl.. |
options |
Verifiabl. |
Optional settings, such as the time budget. |
cancellationToken |
System. |
Cancels reading. |
Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Pdf.PdfPayloads}, The payload found: the metadata payload, the QR code, or neither.
Exceptions
| Type | Condition |
|---|---|
Verifiabl. |
The PDF is too large, cannot be read, holds two different metadata payloads, has no metadata payload and has too many pages or two different QR codes, or reading took longer than the time budget. |
PdfPayloads
Section titled “PdfPayloads”Class in Verifiabl.Verifier.Extraction.Pdf
The Verifiabl payload found in a PDF.
Verifiabl. reads the metadata payload first and renders the
PDF’s pages for a QR code only when there is none, so it sets at most one of
Verifiabl. and Verifiabl..
The payload text is encrypted, but treat it as sensitive and keep it out of logs.
public sealed class PdfPayloadsInheritance: System.Object
PdfPayloads(string?, string?, int)
Section titled “PdfPayloads(string?, string?, int)”Constructor
Create an instance for an adapter or test fake. This reads nothing.
public PdfPayloads(string? metadata, string? qrCode, int renderedPages = 0)| Parameter | Type | Description |
|---|---|---|
metadata |
System. |
|
qrCode |
System. |
|
renderedPages |
System. |
Exceptions
| Type | Condition |
|---|---|
System. |
renderedPages is negative. |
Metadata
Section titled “Metadata”Property
The payload in the PDF’s XMP metadata, or null.
public string? Metadata { get; }Returns: System.String
QrCode
Section titled “QrCode”Property
The text of the Verifiabl QR code on the PDF’s pages, or null. The reader
leaves it null when Verifiabl. was found.
public string? QrCode { get; }Returns: System.String
RenderedPages
Section titled “RenderedPages”Property
How many pages were rendered to look for a QR code: 0 when the PDF has a metadata payload.
public int RenderedPages { get; }Returns: System.Int32
ToString()
Section titled “ToString()”Method
Which payloads were found and the page count only, so the object is safe to log.
public override string ToString()Returns: System.String
PdfReadOptions
Section titled “PdfReadOptions”Class in Verifiabl.Verifier.Extraction.Pdf
Options for reading the payload in a PDF.
public sealed class PdfReadOptionsInheritance: System.Object
Timeout
Section titled “Timeout”Property
Time budget for reading a PDF, including reading a stream. Defaults to 30
seconds. It is separate from Verifiabl.,
which covers the verification call that follows.
public TimeSpan Timeout { get; set; }Returns: System.TimeSpan
PdfVerificationResult
Section titled “PdfVerificationResult”Class in Verifiabl.Verifier.Extraction.Pdf
A verified PDF and the payload found in it.
public sealed class PdfVerificationResultInheritance: System.Object
PdfVerificationResult(VerificationResult, PdfPayloads)
Section titled “PdfVerificationResult(VerificationResult, PdfPayloads)”Constructor
Create a result for an adapter or test fake. This does not perform verification.
public PdfVerificationResult(VerificationResult verification, PdfPayloads payloads)| Parameter | Type | Description |
|---|---|---|
verification |
Verifiabl. |
|
payloads |
Verifiabl. |
Verification
Section titled “Verification”Property
The verified payslip data, not an assessment of the PDF’s visible contents.
public VerificationResult Verification { get; }Returns: Verifiabl.Verifier.VerificationResult
Payloads
Section titled “Payloads”Property
The payloads found in the PDF.
public PdfPayloads Payloads { get; }Returns: Verifiabl.Verifier.Extraction.Pdf.PdfPayloads
ToString()
Section titled “ToString()”Method
The reference and schema only, so the result is safe to log.
public override string ToString()Returns: System.String
VerifierClientPdfExtensions
Section titled “VerifierClientPdfExtensions”Class in Verifiabl.Verifier.Extraction.Pdf
Verifies a payslip PDF from its metadata payload, or its QR code when it has none.
public static class VerifierClientPdfExtensionsInheritance: System.Object
VerifyPdfAsync(IVerifierClient, byte[], PdfReadOptions?, Guid?, CancellationToken)
Section titled “VerifyPdfAsync(IVerifierClient, byte[], PdfReadOptions?, Guid?, CancellationToken)”Method
Read the PDF’s metadata payload and verify it with
Verifiabl.. The PDF’s images are read for a
QR code only when there is no metadata payload.
Each call without idempotencyKey is a new verification
with a new key. To retry a failed call without a second charge, pass the
failure’s Verifiabl. within 1 hour.
Reading takes up to Verifiabl. and verification
up to the client’s own timeout, so the call can take their sum.
public static Task<PdfVerificationResult> VerifyPdfAsync(this IVerifierClient client, byte[] pdf, PdfReadOptions? options = null, Guid? idempotencyKey = null, CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
client |
Verifiabl. |
Any verifier client, including a fake or decorator. |
pdf |
System. |
The PDF bytes, at most Verifiabl.. |
options |
Verifiabl. |
Optional settings, such as the time budget. |
idempotencyKey |
System. |
The key of an earlier attempt to verify this PDF, from Verifiabl. or one you saved before the first attempt, or null for a new verification. See Verifiabl.. |
cancellationToken |
System. |
Cancels reading and verification. |
Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Pdf.PdfVerificationResult}, The verified payslip and the payload it was read from.
Exceptions
| Type | Condition |
|---|---|
Verifiabl. |
No single payload could be read. Nothing was sent to Verifiabl. |
Verifiabl. |
The payload could not be verified, or verification could not be completed; see Verifiabl.. |
VerifyPdfAsync(IVerifierClient, Stream, PdfReadOptions?, Guid?, CancellationToken)
Section titled “VerifyPdfAsync(IVerifierClient, Stream, PdfReadOptions?, Guid?, CancellationToken)”Method
Read a PDF stream’s metadata payload, or its QR code when it has none, and verify it. The stream is read to its end and not disposed.
Each call without idempotencyKey is a new verification
with a new key. To retry a failed call without a second charge, pass the
failure’s Verifiabl. within 1 hour.
Reading takes up to Verifiabl. and verification
up to the client’s own timeout, so the call can take their sum.
public static Task<PdfVerificationResult> VerifyPdfAsync(this IVerifierClient client, Stream pdf, PdfReadOptions? options = null, Guid? idempotencyKey = null, CancellationToken cancellationToken = default)| Parameter | Type | Description |
|---|---|---|
client |
Verifiabl. |
Any verifier client, including a fake or decorator. |
pdf |
System. |
The PDF bytes, at most Verifiabl.. |
options |
Verifiabl. |
Optional settings, such as the time budget. |
idempotencyKey |
System. |
The key of an earlier attempt to verify this PDF, from Verifiabl. or one you saved before the first attempt, or null for a new verification. See Verifiabl.. |
cancellationToken |
System. |
Cancels reading and verification. |
Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Pdf.PdfVerificationResult}, The verified payslip and the payload it was read from.
Exceptions
| Type | Condition |
|---|---|
Verifiabl. |
No single payload could be read. Nothing was sent to Verifiabl. |
Verifiabl. |
The payload could not be verified, or verification could not be completed; see Verifiabl.. |