How do I create raw html in Blazor for creating a pdf file?

Viewed 14

I want to create a pdf-file by copying a razor-page. This page is different from the page which is showing.

When I press the Download button, I expect a pdf-file on my computer.

I tried code like this:

placing in index.html

<script type="text/javascript">
    window.copyHtml = function () {
        return $("html").html();
    };
</script>

... and then placing in

_rawHtml = await _js.InvokeAsync<string>("copyHtml", Array.Empty<object>());

or maybe this:

var rawHtml = new ComponentRenderer<MyListForConvertingToPdf>().Set(c => c.DateToStr, dateToStr).Render();

            PdfPageModel model = new PdfPageModel()
                {
                    FullFileName = $"e:\\temp\\{message}.pdf",
                    Width = 2480,
                    Height = 3508,
                    ConversionDelay = 2,
                    PageCount = 1,
                    NavigationTimeOut = 60,
                    Html = rawHtml,
                    Url = _navigationManager.Uri 
                };

            await _exportService.PostPdfPage(model);

... and when I have the raw html, it will be simple. Then I use SelectPdf and save it in a pdf file.

0 Answers
Related