This project has moved and is read-only. For the latest updates, please go here.

Convert PDF Bytes to PNG Bytes

Nov 13, 2015 at 7:10 PM
Edited Nov 13, 2015 at 7:12 PM
Hello
Is it possible to convert the bytes from a pdf file to a png? And how can i manage this?

I tried an example with the memorystream. The png get created. But when i want to open the png file, the windows photo viewer says it 'is damaged, corrupted or too large'.

My pdf file is stored as bytes in the database and i do not want to create a temp file on the filesystem, only for the converting.

Thanks for your response!
Nov 13, 2015 at 8:20 PM
I don't want to ruin the surprise but your file gets saved on disk first. Magick.NET uses Ghostscript to convert PDF files to other image formats and Ghostscript requires a file on disk. But reading it from a memorystream should work. Do you flush your writer and reset the position to zero?
Nov 16, 2015 at 3:55 PM
Thanks for your answer.
But I found the problem and also the solution.
The problem was the writing section. You have to set the Format from the MagickImage to PNG before calling the Write(MemoryStream)-method.
Now I am able to read the PDF bytes and get the PNG bytes.