Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] SVGs with image #569

Closed
polderudo opened this issue Sep 25, 2024 · 2 comments
Closed

[QUESTION] SVGs with image #569

polderudo opened this issue Sep 25, 2024 · 2 comments

Comments

@polderudo
Copy link

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
Copy link
Collaborator

sampila commented Sep 25, 2024

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
Copy link
Author

Ok thanks for the info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants