Search This Blog

Thursday, February 16, 2012

Print Image from AX using X++



The sample prints an image (in this case a TIFF image) to your default printer without prompting first.
Before writing code please add the reference to ax to System.Printing 

static void krishh_PrintImage(Args _args)
{
    System.Printing.PrintServer         localPrintServer    = new     
    System.Printing.LocalPrintServer();
    System.Printing.PrintQueue          printQueue          =   
    System.Printing.LocalPrintServer::GetDefaultPrintQueue();
    System.Diagnostics.Process          printProcess        = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo processStartInfo;
    str                                 arguments;
    Filename                            fileName            = @'C:\krishhPic.TIF';
    ;

    processStartInfo = printProcess.get_StartInfo();
    processStartInfo.set_Verb("Print Image");
    processStartInfo.set_FileName(@"C:\WINDOWS\System32\rundll32.exe");
    arguments  = @'C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt ';
    arguments += @'"';
    arguments += filename;
    arguments += @'" ';
    arguments += @'"';
    arguments += ClrInterop::getAnyTypeForObject(localPrintServer.get_Name()) + @'\' + ClrInterop::getAnyTypeForObject(printQueue.get_Name());
    arguments += @'" ';
    arguments += @'"%3" "%4"';
    processStartInfo.set_Arguments(arguments);
    processStartInfo.set_UseShellExecute(false);
    printProcess.Start();
    printProcess.Close();
}

No comments:

Post a Comment

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.