addSvgAsImage method does not display svg image with Angular 8
See original GitHub issueHello.
I try to add a svg image into my pdf. here is the code :
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { jsPDF } from 'jspdf';
@Injectable({
providedIn: 'root'
})
export class GeneratePdfService {
doc: jsPDF;
constructor(
private http: HttpClient
) {
this.doc = new jsPDF('p', 'pt', 'a4');
}
async generate(): Promise<void> {
await this._addHeader();
await this._addBody();
this.doc.save('test.pdf');
}
async _addHeader(): Promise<void> {
// let logo: string = await this.http.get('../../../../assets/images/building-flat-shadow.svg', { responseType: 'text' }).toPromise();
let logo:string = '<svg xmlns="http://www.w3.org/2000/svg" width="66" height="48" viewBox="0 0 66 48">'+
// ...
'</svg>';
this.doc.addSvgAsImage(logo, 20, 20, 66, 48, '', false);
}
async _addBody(): Promise<void> {
}
}
I get an error message :
Cannot read property 'fromString' of undefined
And svg image is not in the saved pdf. Could you help me please ? Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
addSvgAsImage method does not display svg image ... - GitHub
Hello. I try to add a svg image into my pdf. here is the code : import { Injectable } from '@angular/core'; import...
Read more >addSvgAsImage method does not display svg image with ...
Hello. I try to add a svg image into my pdf. here is the code : import { Injectable } from '@angular/core'; import...
Read more >Could not change SVG element background in jsPDF
When I try to change svg element background color using addSvgAsImage () method, background color is not changed and it always display black ......
Read more >SVG not showing - Angular - YouTube
angular # svg #notshowing #solvedIn this video tutorial I will show you how to display svg in image tag. I have faced the...
Read more >Managing SVG Icons in Your Angular App - Medium
SVG Icons. There are two ways to include SVG icons in your app. You can place a .svg image on the page, or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My svg:
But I can’t see the svg in the pdf?
There’s the issue that
addSvgAsImage()
is asynchronous. The code from this method:and when I do something like
save() method is executed earlier than doc.addImage(…)
It worked for me when I put
doc.save()
into small setTimeout(). The other solution would be to convert SVG to JPEG and useaddImage()
method instead ofaddSvgAsImage()
.