0

I'm getting blob PDF from API. the PDF contains some pages, and I want to convert every page to image. the result I'm hoping is I get the list of image. And then I want to display that image in HTML.

i already tried many ways, the latest code i try is

let thisIsMyPDF = new Blob([data.body], {type: 'application/pdf'});
console.log(blob);

and

const imagePath = this.sanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,'
                                        + data.body);

let objectURL = 'data:application/pdf;base64,' + data.body;
this.image = this.sanitizer.bypassSecurityTrustUrl(objectURL);

display image

<img id="image1" class="bi x0 y0 w1 h1" alt=""
                         [src]="image"/>

its easy to find image to PDF library, or HTML to PDF library. But its hard to find PDF to image library.

Is it possible?

JustAG33K
  • 1,403
  • 3
  • 13
  • 28
Risli Azis
  • 33
  • 5
  • Have you looked at this question? https://stackoverflow.com/questions/12921052/parsing-pdf-pages-as-javascript-images – A_A Aug 15 '22 at 13:08
  • And what is the purpose of converting it to an image? If you just want to display it, there is probably a more straightforward solution – A_A Aug 15 '22 at 13:08
  • display the pdf in a canvas using pdfjs, then you can save the canvas as an image – Zerotwelve Aug 15 '22 at 13:19
  • @A_A for some purpose. if i just want to display it. i can use ng-pdf-viewer or other library. but i display it as image for spesific purpose – Risli Azis Aug 15 '22 at 13:36
  • @Zerotwelve no, thats not my purpose. my purpose is display it as image. not pdf. "display PDF as Image". – Risli Azis Aug 15 '22 at 13:38
  • with a canvas you can generate an image and show it using a `` tag, but that's overkill. It's better to use directly. Another option is to generate some thumbnails server-side and then load the images. I think you don't have many other options – Zerotwelve Aug 15 '22 at 13:52
  • @RisliAzis Then please take a look at the question I've linked above. This shows how you can use pdfjs to display it as an image – A_A Aug 15 '22 at 14:13

0 Answers0