Is there a way to have my console app open my PDF file (in my default application for PDFs) given a byte array?
Asked
Active
Viewed 6,131 times
4
-
1Can you be more precise what "open" means? Do you want to open the PDF in the default application for .pdf files, e.g. open it in Adobe Reader? – Dirk Vollmar Oct 21 '10 at 17:27
-
... And if that is the case, the easiest way would probably be to save it, then use Process.Start to execute the users default PDF reader. – driis Oct 21 '10 at 17:28
1 Answers
13
If you want to open the PDF in the default application you will have to save it first to a temporary location:
byte[] buffer = GetPdfData();
// save to temp file
string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()+".pdf");
File.WriteAllBytes(path, buffer);
// open in default PDF application
Process process = Process.Start(path);
process.WaitForExit();
// clean up temp file
File.Delete(path);

Dirk Vollmar
- 172,527
- 53
- 255
- 316
-
nice answer, would you need to save the file with a .PDF extension for it to work? – Aaron Anodide Oct 21 '10 at 17:33
-
@Gabriel: Good point, I already fixed it while you wrote your comment. – Dirk Vollmar Oct 21 '10 at 17:35