Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

71
Views
How to save a PDF as an image with C#/Javascript?

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?

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs