This is a migrated thread and some comments may be shown as answers.

Printing and security context issues?

5 Answers 38 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rob Ainscough
Top achievements
Rank 1
Rob Ainscough asked on 20 Jul 2015, 05:03 PM

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.

5 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 23 Jul 2015, 03:13 PM
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
0
Rob Ainscough
Top achievements
Rank 1
answered on 23 Jul 2015, 04:00 PM

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.

 

0
Petya
Telerik team
answered on 24 Jul 2015, 12:53 PM
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
0
Rob Ainscough
Top achievements
Rank 1
answered on 03 Aug 2015, 04:28 PM

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.

0
Boby
Telerik team
answered on 06 Aug 2015, 08:03 AM
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
Tags
RichTextBox
Asked by
Rob Ainscough
Top achievements
Rank 1
Answers by
Petya
Telerik team
Rob Ainscough
Top achievements
Rank 1
Boby
Telerik team
Share this question
or