Printing and security context issues?

6 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    172 posts
    Member since:
    Jan 2010

    Posted 20 Jul 2015 Link to this post

    I've ran into a major issue around printing via RichTextBox.  I have a batch of letters (based on RichTextBox) that need to get printed by the end user, each letter is unique to the end users's customers.  It appears that the ONLY way to print a "single" letter is via user initiated trigger from a UI element (button).  Any other attempt results in a security violation and nothing prints.

    Obviously this will be a problem for end users since they can't sit there and hit the print button 250 times for each "letter".  Any attempts to loop thru "letters" to be printed results in security violation.

    If we have to resort to using standard "Applications" (either a Windows Forms app, or Windows Service) then that defeats the entire reason/justification to go with a web application.

    Perhaps I'm just missing something, but would appreciate any input on how to accomplish batch printing of letters (RichTextBox) and still be a web only application?

    Cheers, Rob.

  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 23 Jul 2015 Link to this post

    Hello Rob,

    The issue is rather unfortunate but comes directly from the Silverlight framework, so there aren't many viable solutions. 

    Basically, in Silverlight applications silent printing is only available when running the app with elevated trust (out-of-browser). Otherwise, the PrintDialog needs to be shown and all dialogs in Silverlight can only be in result of a user action, thus the security exceptions you are seeing.

    One possible solution would be to find a way to print from the web application. You could send the RadDocument in HTML format to the server and print it from there. The recommended approaches for doing this I found online, however, seem to include showing the print dialog too.

    Another option, if applicable for you, is to merge all documents in a single one. This will allow to only show the dialog to the end users once and avoid the constant prompts. If this sounds reasonable to you, take a look at the MergeDocuments SDK example to see how you can merge several RadDocument instances into one. 

    I hope this is useful.

    Regards,
    Petya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Rob Ainscough
    Rob Ainscough avatar
    172 posts
    Member since:
    Jan 2010

    Posted 23 Jul 2015 in reply to Petya Link to this post

    Hi Petya,

    I'm not aware of any other web based framework/technology that doesn't have the same restrictions?  HTML5, ASPX, etc. all seem to have this same restriction, in fact HTML5 is even more restricted.  Do you have HTML5 based sample that suggests otherwise?

    I am running in OOB mode with elevated trust, but your RadRichText box still requires an end user trigger the print event each and every time ... I've tried "batch" printing with just one user initiated event trigger (click print button) but that results in print just 1 of the 100 batched letters.

    Can't print from a server, the end user needs the hard copy at their computer/location and servers are remote location with no printer connections and would be of no use to end user.

    Thanks for the MergeDocuments SDK example, I'll look into that.

     

  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 24 Jul 2015 Link to this post

    Hello Rob,

    Actually, when running with elevated trust you should be able to print silently with the Print() overload accepting settings by specifying the UseDefaultPrinter property. Is that option not working for you? I tried it out on my end and am not experiencing issues.

    Regards,
    Petya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Rob Ainscough
    Rob Ainscough avatar
    172 posts
    Member since:
    Jan 2010

    Posted 03 Aug 2015 in reply to Petya Link to this post

    Hi Petya,

     

    Silent printing will work but ONCE only ... I can't call multiple prints under the single context and that's a big issue.

     

    Cheers, Rob.

  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 06 Aug 2015 Link to this post

    Hi Rob,

    The problem is that the Print method is asynchronous, thus the consequent calls can interfere as they all use the same UI in the main thread. You can synchronize calls using RadRichTextBox.PrintCompleted event:
    public partial class MainPage : UserControl
    {
        int i = 1;
     
        public MainPage()
        {
            InitializeComponent();
        }
     
        private void button_Click(object sender, RoutedEventArgs e)
        {
            this.radRichTextBox.PrintCompleted += RadRichTextBox_PrintCompleted;
            PrintNextDocument();
        }
     
        private void PrintNextDocument()
        {
            if (i > 5)
            {
                return;
            }
     
            var document = new TxtFormatProvider().Import("test" + this.i.ToString());
            this.radRichTextBox.Document = document;
     
            PrintSettings settings = new PrintSettings()
            {
                DocumentName = "My document" + i,
                PrintMode = PrintMode.Native,
                UseDefaultPrinter = true,
                ForceVector = true,
            };
     
            this.radRichTextBox.Print(settings);
            i++;
        }
     
        private void RadRichTextBox_PrintCompleted(object sender, PrintCompletedEventArgs e)
        {
            this.PrintNextDocument();
        }
    }


    Regards,
    Boby
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner