Skip to content

Commit 0a2dd09

Browse files
committed
Added AddPageAsync methods
1 parent 942c81a commit 0a2dd09

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Synercoding.FileFormats.Pdf/PdfWriter.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ public PdfWriter AddPage<T>(T data, Action<T, PdfPage> pageAction)
9898
return this;
9999
}
100100

101+
/// <summary>
102+
/// Add a page to the pdf file
103+
/// </summary>
104+
/// <param name="pageAction">Action used to setup the page</param>
105+
/// <returns>Returns an awaitable task that resolves into this <see cref="PdfWriter"/> to chain calls</returns>
106+
public async Task<PdfWriter> AddPageAsync(Func<PdfPage, Task> pageAction)
107+
=> await AddPageAsync(pageAction, static async (action, page) => await action(page));
108+
109+
/// <summary>
110+
/// Add a page to the pdf file
111+
/// </summary>
112+
/// <param name="data">Data passed into the action</param>
113+
/// <param name="pageAction">Action used to setup the page</param>
114+
/// <returns>Returns an awaitable task that resolves into this <see cref="PdfWriter"/> to chain calls</returns>
115+
public async Task<PdfWriter> AddPageAsync<T>(T data, Func<T, PdfPage, Task> pageAction)
116+
{
117+
using (var page = new PdfPage(_tableBuilder, _pageTree))
118+
{
119+
await pageAction(data, page);
120+
121+
page.WriteToStream(_stream);
122+
}
123+
124+
return this;
125+
}
126+
101127
/// <summary>
102128
/// Add an <see cref="SixLabors.ImageSharp.Image"/> to the pdf file and get the <see cref="Image"/> reference returned
103129
/// </summary>

0 commit comments

Comments
 (0)