2

I'm struggling to create a Android Module which I can build and use in Unity to render a PDF to an image for a commercial project I'm working on.

I have created a simple java program which works but only on windows due to its awt dependencies, but have now been trying for 2 days to create a version which works in android studio.

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import com.spire.pdf.PdfDocument;
import javax.imageio.ImageIO;

class PDFExporter {
     public static void main(String[] args) throws IOException {
            //load the sample PDF
            PdfDocument doc = new PdfDocument();
            doc.loadFromFile(args[0]);

            //save every PDF to .png image
            BufferedImage image;
            for (int i = 0; i < doc.getPages().getCount(); i++) {
                image = doc.saveAsImage(i);
                File file = new File( String.format(args[1] + "%d.png", i));
                ImageIO.write(image, "PNG", file);
            }

            doc.close();
        }

}

I've tried to reproduce this in android studio using their pdfrenderer and an android port of Apache's PDFrenderer. Android's documentation is horrible and Apache's only worked inside of an activity. Any help here would be massively appreciated

EDIT: I should also include that the final destination for the project is the Oculus Quest, hopefully that doesn't rule anything out.

  • 1
    I know this might be interpreted as spam but for a commercial product I wouldn't reinvent the wheel but rather invest the money to use an already existing Asset like e.g. [PDFReader](https://assetstore.unity.com/packages/tools/integration/pdfreader-17591) or depending on your project budget even [PDFRenderer](https://assetstore.unity.com/packages/tools/gui/pdf-renderer-32815) .. with the latter I had very good experiences – derHugo Jul 25 '19 at 10:55
  • 1
    I understand why, but this just opens a window with the PDF in it, I want to use it as a texture on a plane. I have it working with c# and java on windows but just can't get my head around it on android. – Andrew Nattress Jul 25 '19 at 10:58

0 Answers0