You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a few features in the pdf-lib library that are hard to find in free libraries for pdf generation, PDFSharp is pretty good at delivering basic PDF's but as soon as you want things like AcroForm's this becomes really difficult to implement so I looked at embedding pdf-lib into Blazor server. For a majority of what I want to do with AcroForms is populate fields with data, ship the PDF allow the end user to update the data, save the PDF and send it back.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
There are a few features in the pdf-lib library that are hard to find in free libraries for pdf generation, PDFSharp is pretty good at delivering basic PDF's but as soon as you want things like AcroForm's this becomes really difficult to implement so I looked at embedding pdf-lib into Blazor server. For a majority of what I want to do with AcroForms is populate fields with data, ship the PDF allow the end user to update the data, save the PDF and send it back.
Key things to get this to work,
first you need to load pdf-lib library
pre .net 8.0
_Host.cshtml in the body
or .net 8.0
App.razor in the body
<script src="https://cdn.jsdelivr.net/npm/pdf-lib/dist/pdf-lib.js"></script>
in the javascript file
const pdfBytes = await pdfDoc.save()
did not work for me the content in pdfBytes I could not get back to a usable format on the server side.
const pdfBytes = await pdfDoc.saveAsBase64({dataUri: false});
does work, key thing is to turn off the dataUri = false
here is the 3 code blocks you need
first is the Blazor Server side code that calls the click event (I use MudBlazor for my UI)
which in turn calls
which is calling the javascript/ts function
Of course this is a very basic example, but does exactly what I need. Hope this example is of use to someone.
Great work on pdf-lib!
Beta Was this translation helpful? Give feedback.
All reactions