Click or drag to resize
Pdf Library for .NET

PdfCanvasAddAsync(PdfPageElement) Method

Adds a pdf page element to the canvas without waiting for it to be rendered.

Namespace: SelectPdf.Universal
Assembly: SelectPdf.HtmlToPdf.Universal (in SelectPdf.HtmlToPdf.Universal.dll) Version: 26.4
Syntax
public Task<PdfRenderingResult> AddAsync(
	PdfPageElement element
)

Parameters

element  PdfPageElement
The page element to be rendered.

Return Value

TaskPdfRenderingResult
A task that completes with the result of rendering the element.
Remarks

The element starts rendering at once - an element that renders a web page or html in the Chromium engine begins that render in the background - and it is placed on the canvas after every element added to the same document before it, in the order the calls were made. So a document built from several html elements renders them at the same time and still lays them out one after the other. The task completes when the element has been placed.

Until then the element's rendering result, and the pages it may have added, are not known. An element positioned from the result of another one (for example below its PdfPageLastRectangle) must await that element first, or be placed on a page of its own. Do not change an element after passing it here until its task has completed.

Save(String), Close, Append(PdfDocument), Add(PdfPageElement) and the members of Pages wait for the pending additions of their document before they run.

Example
PdfDocument doc = new PdfDocument();
PdfPage page1 = doc.AddPage();
PdfPage page2 = doc.AddPage();
// both pages render in parallel and are placed in order
Task<PdfRenderingResult> first =
    page1.AddAsync(new PdfHtmlElement("https://selectpdf.com"));
Task<PdfRenderingResult> second =
    page2.AddAsync(new PdfHtmlElement("https://selectpdf.com/pricing/"));
await Task.WhenAll(first, second);
doc.Save("document.pdf");
doc.Close();
See Also