'Save Document' Dialog

Discussions concerning general integration topics.

Moderator: Phil Barton

muhsmann
Posts: 54
Joined: Thu Jan 15, 2009 5:41 pm

'Save Document' Dialog

Post by muhsmann »

Is there a way to eliminate the 'Save Document' dialog that is presented to the user after they hit the Save button on the Documents page of the Order?
Mark McKenna

Re: 'Save Document' Dialog

Post by Mark McKenna »

You could replace our print job handler with your own. Our default handler combines all the PDF documents into one file, asks the user where to save it, and then saves it there. If you replace our handler with your own, you could redefine what it means to "save" a document job.

To avoid replacing our handler, you could also opt to inject your own that will execute before ours, and then return ContinueNextStage from the OnProcess method to effectively skip ours and move directly to the next stage (post processing). You can get fancy and optionally run both handlers if necessary, too (for example, your handler could execute so as to take care of things itself and skip our handler, or it may decide to do nothing and defer to our default behavior).

Print job handlers are classes that derive from SoftPro.Select.Shell.Printing.PrintJobHandler. They are registered and configured as part of a package's deployment.
muhsmann
Posts: 54
Joined: Thu Jan 15, 2009 5:41 pm

Re: 'Save Document' Dialog

Post by muhsmann »

Mark,
I have the a package built that supplies the implementation for IPrintJobHandler - it's very simple at this point. I used the SoftPro Select Package project template to get started. I don't encouter any errors or issues during the build and registering of the package. But my package is never called on 'initialized'.I have the ShellPackage1 sample that builds a package to dispaly a new ribbon - and that works fine.
I'm a novice building packages - what am I missing?
Mark McKenna

Re: 'Save Document' Dialog

Post by Mark McKenna »

When implementing print job handlers, there are two additional steps necessary to associate and register your handlers from the package class.
1. Your package class needs a SoftPro.Select.Shell.Registration.ProvidePrintJobHandler attribute on it. This is likely missing because Select uses it to associate your handler with the package.
2. Inside OnInitialize, create an instance of your handler class and register it with the runtime via base.RegisterPrintJobHandler( ).

There is a sample project included with the SDK that implements a basic print job handler. You might want to look at that to see some best practices with registering handlers and associating them with packages.

If you've done this already, would you mind posting the package class code so we can try and help further?
muhsmann
Posts: 54
Joined: Thu Jan 15, 2009 5:41 pm

Re: 'Save Document' Dialog

Post by muhsmann »

Mark I was unaware of the sample - must be a new one! I defineately have not decorated the class w/ the ProvidePrintJobHandler attribute. Let me have a look at the sample. However, I include my classes:
Package class

Code: Select all

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using SoftPro.Select.Shell;
using SoftPro.Select.Shell.Registration;

namespace PrintHandlerPackage
{
    /// <summary>
    /// Summary description for MyPackage.
    /// </summary>
    [RegisterPackage("Government Technology Solutions", "Print Handler", "1.0", "")]
    [RegisterProduct("Government Technology Solutions", "Print Handler", "1.0", "Print Handler Package.", "")]
    [ProvideCommandTable("PrintHandlerPackage.PrintHandler.cto")]
    //[ProvideToolWindow("MyToolWindow", typeof(MyToolWindow), "", WindowLocation.Left, Visible = false, Transient = true, Style = WindowStyle.None)]
    [Guid(PrintHandler.PackageGuidString)]
    partial class PrintHandler : Package
    {
        protected override void OnInitialize()
        {
            //TODO: Provide package initialization logic here.
            //base.RegisterHandler(PrintHandler.RibbonButton1, this.RibbonButton1_Invoked);
            base.RegisterPrintJobHandler(new PrintJobHandlerGTS());
        }
        /*
        private void RibbonButton1_Invoked(object sender, EventArgs e)
        {
            IShell shell = GetService<IShell>();
            shell.OpenToolWindow(typeof(MyToolWindow));
        }
         * */
    }
}

And the handler class:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


using SoftPro.Select.Shell;
using SoftPro.Select.Shell.Printing;


namespace PrintHandlerPackage
{
    class PrintJobHandlerGTS : IPrintJobHandler
    {
        public PrintJobHandlerGTS() { }
        public void Initialize(IServiceProvider serviceProvider) { }
        public PrintJobHandlerResult Process(IPrintJob printJob)
        {
            return PrintJobHandlerResult.ContinueNextStage;
        }
    }
}
I realize these don't do 'anything' yet but I just need to get started
Mark McKenna

Re: 'Save Document' Dialog

Post by Mark McKenna »

One other thing to note is that we generally recommend that you subclass SoftPro.Select.Shell.Printing.PrintJobHandler instead of implementing the IPrintJobHandler interface. We take care of a few details for you and let your handler concentrate on the important stuff. As our base class may expose additional functionality in the future, you'd be in good position to leverage any improvements for "free". I guess in this case it's probably not overly helpful but it is generally the pattern you'll see as you work with the SDK.

At any rate, I think you should be in good shape after adding the attribute...
muhsmann
Posts: 54
Joined: Thu Jan 15, 2009 5:41 pm

Re: 'Save Document' Dialog

Post by muhsmann »

Mark,
I'm encouter an issue that I wasn't expecting. I have written the package for the PrintJobHandler. I got the license file from SoftPro and registered the dll all seems to work well. But now my PrintJobHandler is getting called during the Publish phase - which was not happeing during development.
Is there are information in IPrintJob parameter passed to the OnProcess method override I have implemented to determine if the SP user has requested a Publish instead of Save? I can't find any descriptions of definitions for IPrintJob.Items, IPrintJob.Properties, etc.
Mark McKenna

Re: 'Save Document' Dialog

Post by Mark McKenna »

Sorry for the delay in responding. There is a "Targets" key in the Properties for the print job that tells your handler what destinations the job was assigned when dispatched. Generally, there is only one target, although the data type (List<String>) will support multiple destinations. Typically, the first line of a handler will have something like this:

Code: Select all

protected override PrintJobHandlerResult OnProcess( IPrintJob printJob )
{
    if ( ( printJob.Properties[PrintJobProperty.Targets] as List<String> ).Contains( Enum.GetName( typeof( PrintJobTarget ), PrintJobTarget.Publish ) ) )
    {
        ... do stuff
    }
}
This is the same thing as saying "if one of the targets equals Publish, do something of interest".

All of the Select enums and types shown in the example are defined in the SoftPro.Select.Shell.Printing namespace.
Shevy
Posts: 48
Joined: Tue Dec 23, 2008 12:21 pm

Re: 'Save Document' Dialog

Post by Shevy »

I have added my own print handler code. How do I tell it not to open the publish window after it is done? I have put in this code
Dim a As IBusinessObjectList
a = order.DocumentImage().Last
which worked, but if the user tries to email after publishing they receive an error
"failed to send email, the given key was not present in the dictionary"

is there any other code i can add that will not show the publishing window but also wont give this error?
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: 'Save Document' Dialog

Post by BobRichards »

Which version software are you using?
Bob Richards, Senior Software Developer, SoftPro
Post Reply