QuestPDF icon indicating copy to clipboard operation
QuestPDF copied to clipboard

Image inside svg

Open borgues opened this issue 1 year ago • 9 comments

Eu tenho uma imagem em svg que contém uma imagem em base 64 como background. Essa imagem será inserido no pdf ocupando todo a página. O svg é carregado, mas a imagem de fundo que esta dentro do svg não é carregado, dado a seguinte mensagem: can't render image: load image failed

Thats is the svg file:

Teste

The expected result should be a PDF file with the image, as shown below:

image

Environment I'm using the latest version of the library on Windows 11 x64

Thank´s

borgues avatar May 22 '24 23:05 borgues

Thank you for sharing this issue 😄

I have investigated the bug, and it should be fixed in the 2024.3.10 release. Could you please give it a try?

MarcinZiabek avatar May 25 '24 13:05 MarcinZiabek

@MarcinZiabek Hello, we're facing similar issue. We have SVG which contains png images. When I use the image in PDF I can see everything from the SVG except the images. Do you know what could be problem?

.NET version: .NET Framework 4.7.2 QuestPDF version: 2024.6.4

Thanks

lukasvecerka23 avatar Jul 11 '24 15:07 lukasvecerka23

Could you please share the SVG file with me? Is the image embedded or provided as a path to local storage? Could you please validate your SVG file against the official specification? https://validator.w3.org

MarcinZiabek avatar Jul 12 '24 05:07 MarcinZiabek

Yes, here is the SVG file together with generated PDF.

It seems that some of the embedded pngs are generated but some of them not.

I tried to validate the SVG using provided validator but I'm getting 429 Too Many Requests.

background2

test.pdf

lukasvecerka23 avatar Jul 12 '24 06:07 lukasvecerka23

When I open your SVG file in Safar or Chrome, specific images are also not visible. It seems that your SVG file may contain issues that only some SVG parsers can handle.

image

I have opened your SVG in Affinity Designer and resaved it. After this operation, Chrome shows the file correctly. Please try it:

fixed.svg.zip

MarcinZiabek avatar Jul 12 '24 08:07 MarcinZiabek

Yeah now it works. The original SVG was converted from PDF so perhaps the converter doesn't work correctly. Do you have any idea how could be PDF vectors converted to SVG easily?

Thanks for help!

lukasvecerka23 avatar Jul 12 '24 13:07 lukasvecerka23

It's not easy... PDF does not support embedding SVG files. QuestPDF (through the Skia library) translates SVG contents into PDF drawing commands. So, the opposite process must be equally difficult: analyze every drawing command and find the nearest feature from SVG. It is wholly expected to produce not-perfect results.

MarcinZiabek avatar Jul 12 '24 14:07 MarcinZiabek

Thanks for explanation. And are you planning to add support to use PDF images as a background in QuestPDF? That would be helpful.

lukasvecerka23 avatar Jul 12 '24 14:07 lukasvecerka23

Could you please elaborate a bit more about that feature?

MarcinZiabek avatar Jul 12 '24 15:07 MarcinZiabek

Hi, I'm also facing same issue. I simply want to add an image as Page Background. Is there a direct way for this?

amitjaura avatar Nov 07 '24 05:11 amitjaura

This is already possible using layers. For example:

page.Content()
    .Layers(layers =>
    {
        // layer below main content
        layers
            .Layer()
            .Image("path/to/image.png");

        layers
            .PrimaryLayer()
            .Text("Your content goes here");
    });

girlpunk avatar Nov 07 '24 13:11 girlpunk

@girlpunk Thank you so much for answering this question.

Since there has been no recent activity, I’m closing this issue. If you experience a similar problem or have a related request, feel free to open a new GitHub issue. I appreciate your feedback! ❤️

MarcinZiabek avatar Mar 05 '25 09:03 MarcinZiabek