I may be pushing the library beyond its current limits, but I hope not. Equally, this could be something I’ve missed. My ultimate goal is to create a WASM in Blazor that will store the data client-side, which is then used to generate a client-side PDF based on a Word template. (think offline order taking app)
The following code is run off of a button onClick
in “Index.razor”:
public void onClick()
{
// If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
DocumentModel document = new DocumentModel();
Section section = new Section(document);
document.Sections.Add(section);
Paragraph paragraph = new Paragraph(document);
section.Blocks.Add(paragraph);
Run run = new Run(document, "Hello World!");
paragraph.Inlines.Add(run);
using (var stream = new MemoryStream())
{
document.Save(stream, SaveOptions.PdfDefault);
FileUtil.SaveAs(js, "HelloWorld.pdf", stream.ToArray());
}
}
The execution fails at the document.Save()
line with
Execution
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The type initializer for ‘D’ threw an exception.
System.TypeInitializationException: The type initializer for ‘D’ threw an exception. —> System.NullReferenceException: Object reference not set to an instance of an object.
at . () <0x386bbe0 + 0x00102> in :0
at D…ctor () <0x3840a58 + 0x00114> in :0
at D…cctor () <0x383f518 + 0x0000c> in :0
— End of inner exception stack trace —
at . () <0x38389b0 + 0x00032> in :0
at . ( ) <0x38387b8 + 0x00010> in :0
at . ( ) <0x3838588 + 0x00024> in :0
at . () <0x38381c8 + 0x00002> in :0
at . ( ) <0x38303f8 + 0x00046> in :0
at . ( , System.Int32 , , System.Boolean , & ) <0x382fa80 + 0x0000a> in :0
at . ( , System.Int32 , & ) <0x3825290 + 0x000a8> in :0
at B. ( , System.Int32 ) <0x3824d20 + 0x0001c> in :0
at B. (System.String , System.Boolean , System.Boolean , System.Int32 ) <0x3824660 + 0x00020> in :0
at . (GemBox.Document.CharacterFormat , , [] , B , System.Int32 ) <0x3804710 + 0x0014c> in :0
at . (GemBox.Document.CharacterFormat , , [] , B ) <0x3801238 + 0x00014> in :0
at . ( ) <0x38010e0 + 0x0003c> in :0
at . () <0x3775370 + 0x00190> in :0
at GemBox.Document.DocumentModel. (GemBox.Document.PaginatorOptions , ) <0x3746908 + 0x000b2> in :0
at GemBox.Document.PdfSaveOptions.67tg5rkvl9zwp8v7723mndgzuc3b4vj8 (GemBox.Document.DocumentModel , System.IO.Stream , System.String ) <0x372a030 + 0x00030> in :0
at GemBox.Document.DocumentModel.Save (System.IO.Stream stream, GemBox.Document.SaveOptions options) <0x3729c00 + 0x0004c> in :0
at WebApp.Pages.Index.onClick () [0x0005b] in C:\Source\BlazorTestApp\WebApp\Pages\Index.razor:32
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T] (System.MulticastDelegate delegate, T arg) <0x35ca030 + 0x0006e> in :0
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync (System.Object arg) <0x35c9f70 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync (Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, System.Object arg) <0x35c9ed0 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync (System.Object arg) <0x35cda18 + 0x00040> in :0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync (System.UInt64 eventHandlerId, Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo fieldInfo, System.EventArgs eventArgs) <0x35ccf90 + 0x000a8> in :0
GemBox.Document v33.0.1000 and its dependencies are installed from NuGet. The only discrepancy I can see is that the project is .NET Standard 2.1, not 2.0… if that makes a difference?
Many thanks in advance for your help