The None
The None

Reputation: 97

'The specified executable is not a valid application for this OS platform

I want to print a PDF file from C# code without user interaction.

I tried this accepted answer but it is not working for me.

This is the code I tried:

Process p = new Process();
p.StartInfo = new ProcessStartInfo()
{
     CreateNoWindow = true,
     Verb = "print",
     FileName = @"G:\Visual Studio Projects\PrintWithoutGUI\PrintWithoutGUI\Courses.pdf" //put the correct path here
};
p.Start();

I get this exception :

System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'`

Upvotes: 8

Views: 23596

Answers (2)

bigtheo
bigtheo

Reputation: 662

try this by add UseShellExecute=true it will print to default printer but if you want to print to a specific print change the verb print to verb printTo by spefiying the name of the printer Arguments proprety.

 private static void PrintByProcess()
    {
        using (Process p = new Process())
        {
            p.StartInfo = new ProcessStartInfo()
            {
                CreateNoWindow = true,
                UseShellExecute=true,
                Verb = "print",
                FileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\doc.pdf"
            };

            p.Start();
        }

Upvotes: 9

Mostafa Mahmoud
Mostafa Mahmoud

Reputation: 190

this is the correct way to write your code

Process p = new Process();
p.StartInfo = new ProcessStartInfo()
{
    CreateNoWindow = true,
    Verb = "print",
    FileName = "PDfReader.exe", //put the path to the pdf reading software e.g. Adobe Acrobat
    Arguments = "PdfFile.pdf" // put the path of the pdf file you want to print
};
p.Start();

Upvotes: 2

Related Questions