Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 10657

Open and close PDF reader from code

$
0
0
Here is an example of how you can open Adobe PDF Reader (or another PDF reader) with a particular PDF document, and close the reader again.
static void pager_FindWindow(Args _args)
{
Filename pdfFileName = 'MyDocumentFile.pdf';
FilePath pdfFilePath = @'C:\XYZ\';
str adobeExe;

System.Diagnostics.Process process;
System.Diagnostics.ProcessStartInfo processStartInfo;

// Let Windows figure out the standard program and location for the PDF reader
adobeExe = WinAPI::findExecutable(pdfFilePath + pdfFileName);

// Start the reader process
new InteropPermission(InteropKind::ClrInterop).assert();

process = new System.Diagnostics.Process();

processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.set_FileName(adobeExe);
processStartInfo.set_Arguments(pdfFilePath + pdfFileName);

process.set_StartInfo(processStartInfo);

process.Start();


// Wait 5 secs. before closing the window
sleep (5000);

// Close the window
process.Kill();
}

Viewing all articles
Browse latest Browse all 10657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>