Skip to content
Verifiabl

.NET verifier SDK: PDF extraction

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 PayslipPdfReader

Inheritance: System.Object

Field

The largest PDF read: 20 MiB, the same limit as the Verifiabl portal.

public const int MaxPdfBytes = 20971520

Returns: System.Int32

Field

The most pages rendered. A longer PDF without a metadata payload is refused rather than read in part.

public const int MaxPages = 50

Returns: System.Int32

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.Byte[] The PDF bytes, at most Verifiabl.Verifier.Extraction.Pdf.PayslipPdfReader.MaxPdfBytes.
cancellationToken System.Threading.CancellationToken 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.Verifier.PayloadExtractionException 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.InvalidOperationException Wasmtime’s native library could not be loaded.

ReadAsync(byte[], PdfReadOptions?, CancellationToken)

Section titled “ReadAsync(byte[], PdfReadOptions?, CancellationToken)”

Method

Read the payload within Verifiabl.Verifier.Extraction.Pdf.PdfReadOptions.Timeout.

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.Verifier.Extraction.SandboxModule.LoadAsync(System.Threading.CancellationToken).

public static Task<PdfPayloads> ReadAsync(byte[] pdf, PdfReadOptions? options = null, CancellationToken cancellationToken = default)
Parameter Type Description
pdf System.Byte[] The PDF bytes, at most Verifiabl.Verifier.Extraction.Pdf.PayslipPdfReader.MaxPdfBytes.
options Verifiabl.Verifier.Extraction.Pdf.PdfReadOptions Optional settings, such as the time budget.
cancellationToken System.Threading.CancellationToken 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.Verifier.PayloadExtractionException 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.Verifier.Extraction.Pdf.PdfReadOptions.Timeout. 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.IO.Stream The PDF bytes, at most Verifiabl.Verifier.Extraction.Pdf.PayslipPdfReader.MaxPdfBytes.
options Verifiabl.Verifier.Extraction.Pdf.PdfReadOptions Optional settings, such as the time budget.
cancellationToken System.Threading.CancellationToken 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.Verifier.PayloadExtractionException 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.

Class in Verifiabl.Verifier.Extraction.Pdf

The Verifiabl payload found in a PDF.

Verifiabl.Verifier.Extraction.Pdf.PayslipPdfReader 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.Verifier.Extraction.Pdf.PdfPayloads.Metadata and Verifiabl.Verifier.Extraction.Pdf.PdfPayloads.QrCode.

The payload text is encrypted, but treat it as sensitive and keep it out of logs.

public sealed class PdfPayloads

Inheritance: System.Object

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.String
qrCode System.String
renderedPages System.Int32

Exceptions

Type Condition
System.ArgumentOutOfRangeException renderedPages is negative.

Property

The payload in the PDF’s XMP metadata, or null.

public string? Metadata { get; }

Returns: System.String

Property

The text of the Verifiabl QR code on the PDF’s pages, or null. The reader leaves it null when Verifiabl.Verifier.Extraction.Pdf.PdfPayloads.Metadata was found.

public string? QrCode { get; }

Returns: System.String

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

Method

Which payloads were found and the page count only, so the object is safe to log.

public override string ToString()

Returns: System.String

Class in Verifiabl.Verifier.Extraction.Pdf

Options for reading the payload in a PDF.

public sealed class PdfReadOptions

Inheritance: System.Object

Property

Time budget for reading a PDF, including reading a stream. Defaults to 30 seconds. It is separate from Verifiabl.Verifier.VerifierClientOptions.Timeout, which covers the verification call that follows.

public TimeSpan Timeout { get; set; }

Returns: System.TimeSpan

Class in Verifiabl.Verifier.Extraction.Pdf

A verified PDF and the payload found in it.

public sealed class PdfVerificationResult

Inheritance: 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.Verifier.VerificationResult
payloads Verifiabl.Verifier.Extraction.Pdf.PdfPayloads

Property

The verified payslip data, not an assessment of the PDF’s visible contents.

public VerificationResult Verification { get; }

Returns: Verifiabl.Verifier.VerificationResult

Property

The payloads found in the PDF.

public PdfPayloads Payloads { get; }

Returns: Verifiabl.Verifier.Extraction.Pdf.PdfPayloads

Method

The reference and schema only, so the result is safe to log.

public override string ToString()

Returns: System.String

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 VerifierClientPdfExtensions

Inheritance: 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.Verifier.IVerifierClient.VerifyAsync(Verifiabl.Verifier.VerificationRequest,System.Threading.CancellationToken). 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.Verifier.VerifierException.IdempotencyKey within 1 hour.

Reading takes up to Verifiabl.Verifier.Extraction.Pdf.PdfReadOptions.Timeout 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.Verifier.IVerifierClient Any verifier client, including a fake or decorator.
pdf System.Byte[] The PDF bytes, at most Verifiabl.Verifier.Extraction.Pdf.PayslipPdfReader.MaxPdfBytes.
options Verifiabl.Verifier.Extraction.Pdf.PdfReadOptions Optional settings, such as the time budget.
idempotencyKey System.Nullable{System.Guid} The key of an earlier attempt to verify this PDF, from Verifiabl.Verifier.VerifierException.IdempotencyKey or one you saved before the first attempt, or null for a new verification. See Verifiabl.Verifier.VerificationRequest.IdempotencyKey.
cancellationToken System.Threading.CancellationToken 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.Verifier.PayloadExtractionException No single payload could be read. Nothing was sent to Verifiabl.
Verifiabl.Verifier.VerifierException The payload could not be verified, or verification could not be completed; see Verifiabl.Verifier.IVerifierClient.VerifyAsync(Verifiabl.Verifier.VerificationRequest,System.Threading.CancellationToken).

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.Verifier.VerifierException.IdempotencyKey within 1 hour.

Reading takes up to Verifiabl.Verifier.Extraction.Pdf.PdfReadOptions.Timeout 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.Verifier.IVerifierClient Any verifier client, including a fake or decorator.
pdf System.IO.Stream The PDF bytes, at most Verifiabl.Verifier.Extraction.Pdf.PayslipPdfReader.MaxPdfBytes.
options Verifiabl.Verifier.Extraction.Pdf.PdfReadOptions Optional settings, such as the time budget.
idempotencyKey System.Nullable{System.Guid} The key of an earlier attempt to verify this PDF, from Verifiabl.Verifier.VerifierException.IdempotencyKey or one you saved before the first attempt, or null for a new verification. See Verifiabl.Verifier.VerificationRequest.IdempotencyKey.
cancellationToken System.Threading.CancellationToken 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.Verifier.PayloadExtractionException No single payload could be read. Nothing was sent to Verifiabl.
Verifiabl.Verifier.VerifierException The payload could not be verified, or verification could not be completed; see Verifiabl.Verifier.IVerifierClient.VerifyAsync(Verifiabl.Verifier.VerificationRequest,System.Threading.CancellationToken).