unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.61k stars 254 forks source link

[QUESTION] SVGs with image #569

Closed polderudo closed 2 weeks ago

polderudo commented 1 month ago

Is it possible to use the image tag in creator.NewGraphicSVGFromString? We are trying to use a simple SVG for frontend and PDF generation on backend and would like to use the same approach. On the frontend we are loading the images via the image tag into the SVG. On the backend we would use local files to generate a PDF, but the images are not beeing renderd into the PDF. Although no errors shows up.

package main

import (
    "log"
    "os"

    "github.com/unidoc/unipdf/v3/common/license"
    "github.com/unidoc/unipdf/v3/creator"
)

var (
    svg = `
<svg height="200" width="300" viewBox="0 0 300 200" xmlns="http://www.w3.org/2000/svg"> 
  <image x="0" y="0" width="300" height="200" href="img.jpg" />  
</svg>`
)

func init() {
    if err := license.SetLicenseKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`), "myComp"); err != nil {
        log.Println("Error loading unidocPDFLicense:", err)
        os.Exit(-1)
    }
}

func main() {
    c := creator.New()
    graphicSvg, err := creator.NewGraphicSVGFromString(svg)
    if err != nil {
        panic(err)
    }

    err = c.Draw(graphicSvg)
    if err != nil {
        panic(err)
    }

    if err := c.WriteToFile("svg.pdf"); err != nil {
        panic(err)
    }
}

img

sampila commented 1 month ago

Hi @polderudo,

Currently the supported tags is shapes and text element under svg.

However we had plan to support it in future, we will inform you about it later.

Best regards, Alip

polderudo commented 2 weeks ago

Ok thanks for the info