QuestPDF icon indicating copy to clipboard operation
QuestPDF copied to clipboard

Previewer stop working with LiveCharts package

Open enricobenedos opened this issue 2 years ago • 4 comments

Describe the bug We are trying to implement some charts in the PDF using LiveCharts as suggested also in a issue in this repo (tighter with Microcharts). Once simply added LiveCharts dependency the previewer stop working/refresh with no errors.

To Reproduce Create new console project, add QuestPDF 2022.09 and LiveCharts.SkiaSharpView 2.0.0-beta.400 and paste this code:


using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
using QuestPDF.Previewer;

Document.Create(container =>
{
    container.Page(page =>
    {
        page.Size(PageSizes.A4);
        page.Margin(2, Unit.Centimetre);
        page.PageColor(Colors.White);
        page.DefaultTextStyle(x => x.FontSize(20));

        page.Header()
            .Text("Hello PDF with LiveCharts!")
            .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);

        page.Content()
            .PaddingVertical(1, Unit.Centimetre)
            .Column(x =>
            {
                x.Spacing(20);

                x.Item().Text(Placeholders.LoremIpsum());
                x.Item().Image(Placeholders.Image(200, 100));
            });

        page.Footer()
            .AlignCenter()
            .Text(x =>
            {
                x.Span("Page ");
                x.CurrentPageNumber();
            });
    });
})
.ShowInPreviewer();

Expected behavior Preview refresh and show changes.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context We are trying LiveChart lib because it seems that Microcharts has been abandoned for now. It is a good lib but it is missing some more complicated chart like stacked bars, etc..

enricobenedos avatar Sep 26 '22 19:09 enricobenedos

LiveCharts.SkiaSharpView 2.0.0-beta.400 requires SkiaSharp 2.88.1, whereas the Previewer operates on the older branch 2.80.x. Unfortunatelly, SkiaSharp made some significant changes to the serialization algorithm.

MarcinZiabek avatar Sep 26 '22 20:09 MarcinZiabek

So we need to await for the QuestPDF SkiaSharp update right? Because working with only GeneratePDF is a little bit frustrating 😅

enricobenedos avatar Sep 26 '22 20:09 enricobenedos

So we need to await for the QuestPDF SkiaSharp update right?

This is not a straighforward upgrade for QuestPDF.

Without a doubt, new SkiaSharp (2.88.x) is superior. It offers much better multiplatform support, reduces application size and is generally speaking easier to use. Also, no changes in QuestPDF are required.

The tricky part is that many projects may have multiple dependencies requiring SkiaSharp at different versions. Exactly like in your case. If I update QuestPDF to use latest and greatest, there is a small chance that this change will impact already existing projects. Dependency hell, huh? 🤣

Still, this update needs to happen somewhere this year. The sooner the better.

Because working with only GeneratePDF is a little bit frustrating 😅

On your development environment, you can render the chart to an image, so Previewer does work. On the production, you can use the Canvas element. It shouldn't be difficult to make this type of condition.

MarcinZiabek avatar Sep 27 '22 09:09 MarcinZiabek

Dependency hell, huh? 🤣 ... 🥲 ...

Anyway I'm not sure to have been understood your suggestion. Do you mean to generate the charts/images in a separate project and then simply include them like images? Because as I've already wrote, as soon as include the LiveChart dependencies on my project previewer stop working.

So hope that update come as soon as possible, an idea can be start deploy it with a pre release package🙂

enricobenedos avatar Sep 28 '22 19:09 enricobenedos