title: How to write and view converted pdfs to and from memory?
body: <p>Right now I am using ghostscript in Unity to convert pdfs to jpgs and view them in my project.</p>
  
  <p>Currently it flows like so:<br>
  -Pdfs are converted into multiple jpegs (one for each page)<br>
  -The converted jpegs are written to disk<br>
  -They are then read in by bytes into a 2D texture<br>
  -And this 2D texture is assigned to a GameObjects RawImage component  </p>
  
  <p>This works perfectly in Unity, but... (now comes the hiccup) my project is intended to run on the Microsoft Hololens.
  The Hololens runs on the Windows 10 API, but in a limited capacity.</p>
  
  <p>Where the issue arises is when <strong>I</strong> try to convert pdfs and view them on the Hololens. Quite simply, the Hololens cannot create or delete files outside of its known folders (Pictures, Documents, etc).</p>
  
  <p>My imagined solution to this problem is to instead of write the converted jpeg files to disk, write them to memory and view them from there.</p>
  
  <p>In talking with GhostScript devs, I was told GhostScript.NET does what I am looking to do - convert pdfs and view them from memory (It does this with the Rasterizer/Viewer classes, I believe, but again I don't understand it quite well).</p>
  
  <p>I've been lead to look at the latest GhostScript.NET docs to route out how this is done, but I simply don't understand them well enough to approach this.</p>
  
  <p>My question is then, based on how I'm using ghostscript now, how do I use GhostScript.NET in my project to write the converted jpegs into memory and view them there?</p>
  
  <p>Here's how I'm doing it now (code-wise):</p>
  
  <pre><code>        //instantiate
          byte[] fileData;
          Texture2D tex = null;
  
          //if a PDF file exists at the current head path
          if (File.Exists(CurrentHeadPath))
          {
              //Transform pdf to jpg
              PdfToImage.PDFConvert pp = new PDFConvert();
              pp.OutputFormat = "jpeg"; //format
              pp.JPEGQuality = 100; //100% quality
              pp.ResolutionX = 300; //dpi
              pp.ResolutionY = 500;
              pp.OutputToMultipleFile = true;
              CurrentPDFPath = "Data/myFiles/pdfconvimg.jpg";
  
              //this call is what actually converts the pdf to jpeg files
              pp.Convert(CurrentHeadPath, CurrentPDFPath);
  
              //this just loads the first image
              if (File.Exists("Data/myFiles/pdfconvimg" + 1 + ".jpg"))
              {
                  //reads in the jpeg file by bytes
                  fileData = File.ReadAllBytes("Data/myFiles/pdfconvimg" + 1 + ".jpg");
                  tex = new Texture2D(2, 2);
                  tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
  
                  //Read Texture into RawImage component
                  PdfObject.GetComponent&lt;RawImage&gt;().texture = tex;
                  PdfObject.GetComponent&lt;RawImage&gt;().rectTransform.sizeDelta = new Vector2(288, 400);
                  PdfObject.GetComponent&lt;RawImage&gt;().enabled = true;
              }
  
              else
              {
                  Debug.Log("reached eof");
              }
          }
  </code></pre>
  
  <p>The convert function is from a script called <a href="https://pastebin.com/92uJ7pdk" rel="nofollow noreferrer">PDFConvert</a> which I obtained from code project. Specifically <a href="https://www.codeproject.com/Articles/32274/How-To-Convert-PDF-to-Image-Using-Ghostscript-API" rel="nofollow noreferrer">How To Convert PDF to Image Using Ghostscript API</a>.</p>