4

Is there a way to have my console app open my PDF file (in my default application for PDFs) given a byte array?

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
Rod
  • 14,529
  • 31
  • 118
  • 230
  • 1
    Can 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 Answers1

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