1

I'm currently working on a Unity project and I need to be able to open a PDF received from an API call. I'm able to download the PDF just fine, but now I need to convert it to an image so I can display it as a texture in Unity (I'm aware there's a PDF viewer on the asset store but I'm not willing to spend the money for this project). My question is, how can I do this? It seems very easy to do with Javascript with the PDF.js library, however I'm not sure how I'd execute Javascript code within C#. I'm looking for something along the lines of opening the already downloaded PDF in the browser, converting it to an image, and then using this image in my C# code. Any advice on how I could go about this?

Evan Scanlon
  • 43
  • 1
  • 4

1 Answers1

1

You can use the C# .NET IronPDF Library to achieve this easily. Simply create a ChromePdfRenderer using C# then create Bitmaps from an input PDF.

Simply return each page as an image as shown in the last line and now every page is a seperate JPG/PNG file.

using IronPdf;

var Renderer = new IronPdf.ChromePdfRenderer();

PdfDocument Pdf = new PdfDocument("inputexample.pdf");

System.Drawing.Bitmap[] pageImages = Pdf.ToBitmap();

Pdf.RasterizeToImageFiles(@"thumbnail_*.jpg");

A full code example can be found here.

michael_b
  • 124
  • 7