I used GhostscriptWrapper for convert pdf to image
but how can convert pdf to image in memorystream instead save it
i need to design pdf viewer and need to convert pdf to image in memory stream
GhostscriptSettings gs = new GhostscriptSettings();
gs.Device = GhostscriptDevices.png16m;
gs.Page = new GhostscriptPages { Start = page, End = page };
gs.Resolution = new Size { Height = 150, Width = 150 };
gs.Size = new GhostscriptPageSize { Native = GhostscriptPageSizes.a4 };
GhostscriptWrapper.GenerateOutput("C:\\PDFViewer\\my\\test.pdf", "C:\\PDFViewer\\my\\test.png", gs);
GhostScript.net has support for memory streams (non physical files).
However, I am not sure if you could do this in real time, since GS takes a nice "chunk" of CPU and processing to convert a PDF to an image, and this is especially for larger PDF's. And in some cases, even for a one page PDF, if it is a larger page, then again, it can take a few seconds for that PDF to be converted to a raw byte image.
The above thus suggests that you may well want to process the PDF files BEFORE you attempt to display such preview images on your site. I do this for PDF thumbnails, and save the image (raw byte jpeg image) to a database.
If just one image to be displayed on the page, then I suppose it becomes practical to do this in real time. For multiple images on a page, then I suggest preprocessing the PDF to image previews.
However, let's assume a PDF file, and then we want to display the PDF (1st page) as an image, and do so WITHOUT CREATING an image file on disk.
So, we have this markup:
So, a simple button and image on the web page.
So, for a given pdf file, let's display a thumbnail (image), and do so without creating a file (memory stream).
So, code behind is this:
And the result is thus this:
So, above shows proof of concept of how a PDF image preview can be created, and created 100% in memory.
I should also point out that except for rather small preview images, you don't want to use the above base64 string and send that directly to the web page. While this is easy, such images are not cached, and worse they will post-back to the server, and that can result in REALLY slow pages if you have a lot of such images on one page. So, say for 1-5 small preview images, then the above base64 string being directly sent to the image control is fine. However, if you have more images, then I suggest you create a generic web handler, and this will allow the browser to cache such images.