开发者

Printing from Adobe with Citrix

Greetings,

I've attempted to shrink the code down as much as I can. Basically we use the Adobe Acrobat standard 6 Com libraries to print. It works as well as any batch pdf print solution that I've seen, but I can't seem to make it work with Citrix. Citrix appears to remap the netowrk printing locations and I can't seem to make it work with out existing solution. All the code runs on Citirix it just doesn't print anything. When it runs locally it runs and prints just fine.

Any help would be greatly appreciated,

Thank you, Brian

private void btnTest_Click(object sender, EventArgs e)
{
    try
    {
        Cursor.Current = Cursors.WaitCursor;

        PrintDialog PrintDialog1 = new Print开发者_JAVA百科Dialog();
        PrintDialog1.ShowDialog();

        CAcroAVDoc acroDoc = null;

        const string fileName = @"SomeFile.pdf";

        var acroApp = instantiateAcrobat();
        acroDoc = GetAcrobatAVDoc();

        acroDoc.Open(fileName, "");

        CAcroPDDoc pdDoc = (CAcroPDDoc)acroDoc.GetPDDoc();
        int numPages = pdDoc.GetNumPages();

        UnManagedMethods.SetDefaultPrinter(PrintDialog1.PrinterSettings.PrinterName);

        acroDoc.PrintPagesSilent(0, numPages - 1, 2, 1, 0);

        MessageBox.Show("Printed!!");
    }
    catch (Exception ex) 
    {
        MessageBox.Show(ex.Message);
    }
}

private static CAcroAVDoc GetAcrobatAVDoc()
{
    Type acroApp = Type.GetTypeFromProgID("AcroExch.AVDoc", true);
    return (CAcroAVDoc)Activator.CreateInstance(acroApp);
}

private static CAcroApp instantiateAcrobat()
{
    killAllAcrobatProcesses();
    Type acroApp = Type.GetTypeFromProgID("AcroExch.App", true);
    return (CAcroApp)Activator.CreateInstance(acroApp);
}

private static void killAllAcrobatProcesses()
{
    Process[] acrobatProcesses = Process.GetProcessesByName("Acrobat");
    if (acrobatProcesses.Length > 0)
    {
        foreach (Process process in acrobatProcesses)
        {
            process.Kill();
        }
    }
    Process[] acroRd32Processes = Process.GetProcessesByName("AcroRd32");
    if (acroRd32Processes.Length > 0)
    {
        foreach (Process process in acroRd32Processes)
        {
            process.Kill();
        }
    }
}


If anyone is interested this was fixed by installing the printer on the citrix box outside of Citrix. The trick was to remote desktop into the citrix box install the printer get the application working so it will print. Then when you log on through citrix printing worked just fine. It seems very obvious in retrospect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜