Silverlight and XtraReports - opening generated PDF report in new tab in browser - silverlight

I'm trying to send a PDF file from a WCF to silverlight client. PDF is generated by DevExpress XtraReports (in method XtraReport CreateReport(string reportTypeName, RootGenericReportParameterContainer reportInformation)).
Acually PDF is saved somewhere on clients computer after choosing save path in file save dialog - DevExpress takes care of everything - but I don't have a clue how to open the PDF in new tab in browser.
And here is another problem. Silverlight 4 has no access to local file system right? So information about local PDF location is useless. Maybe it would be better to save the PDF in WCF and send a link to it to the client - but how?

I would first question why you need to send the file to the Silverlight client. Get rid of that requirement and the solution becomes much simpler. Silverlight can provide a link that opens a new browser tab. That link would be handled by the web domain, processing it as an HttpHandler, generating the PDF file for the browser. Your PDF url doesn't have to reference a physical file, you can still generate it on request, handle querystring values, etc... Lots of different ways to do this.

Seems that the question isn't really about DevExpress or Silverlight - you're just looking to open a [document of some kind] in a new tab. Each browser natively handles things differently, and users can change tab handling to whatever they want. And (as you mentioned) once the user has downloaded the file, you no longer control it.
Your best bet (and the way I do it) is probably to have a link pointing to a handler/file using "target='_blank' " in the anchor tag on the webpage. From the server side, you would want to set the "Content-Disposition" header to "Inline" to indicate to the browser that the document should be displayed in place instead of downloaded ("Attachment").

Related

How to open a generated file on Vaadin Flow?

On my app I want to open a generated PDF with PdfBox on a new tab, I have seen a couple of documentations but they are for old version of Vaadin or won't work in my case. I don't want to save it on the server or attach the file to any link or button, I want to write a method to automatically open it on a new tab.
PdfBox gives an option to save the file on an OutputStream, is there any way to open that OutputStream file on a new tab? Or at least download it without attaching it to an Anchor widget like Flow Viritin does?
The problem lies in the fact that because you don't want to save the file on the server, you cannot then have a direct url of said file to link to. You also cannot pass the pdf file as parameter to another View.
The solution is to store the pdf in the VaadinSession (as byte[] is probably easiest), and when the user then opens another tab by clicking a certain anchor/routerlink, that view will read the pdf from the VaadinSession and add the it to the view. (How to display pdf with Vaadin 14). Please remember to remove the pdf again from the VaadinSession :)

Access Specific PDF Page in WPF WebBrowser Control

I have a webbrowser control in my application that is used to display pdf files that have been created in iTextSharp and are stored locally on the hard drive.
I would like to be able to navigate the file (next, previous, first, last, toc) from my application rather than using the inbuilt nav of the reader in the browser.
I have seen that you can navigate to specific pages by using
Browser.Navigate("filename.pdf#page=?);
This works the first time but when trying to navigate to a different page, it makes the browser disappear completely with no errors. However, I can reload the file without problem if I don't have the #page=? suffix on the file url though. Any ideas on this?
Alternatively, is there anyway in iTextSharp of adding something to the file to allow for it to be navigated from an external command?
All the official parameters that can be used to navigate through a PDF using parameters in the query string after the ? character are listed in a document published by Adobe: Parameters for Opening PDF Files
You already mentioned the page parameter. Another option could be using named destinations: nameddest=destination. In this case, you need to add the anchor with name destination to the file using iTextSharp.
Note that not all viewers implement these parameters. Adobe supports them in Adobe Reader and in the Adobe Reader plug-in, but there is no guarantee that they will work in pdf.js (Firefox), Pdfium (Google Chrome),... If your browser disappears when using an open parameter, you may have hit a bug in the browser or the viewer plug-in that causes the browser to crash. iTextSharp nor iText can crash a browser ;-)
There are no other ways you can navigate a PDF from an external application. The only thing you can do, is to add JavaScript to the PDF so that it always opens at the same page. This is done using an open action. I don't think this solves your problem as it would mean that you have to change the PDF file every time you want it to open at a different page.

Silverlight 4: Read in file from local system without being OOB?

Any tips/tricks on how to read a file from the local system dynamically in silverlight 4 without having to be out of browser?
Impersonation? Toggling app elevated trust on/off programmatically?
Or is this simply impossible to do without being out of browser?
As it stands I have a Pegasus ImageGear PDF viewer that I feed a "LoadDocument" method a stream of a PDF file.
This of course works fine if the file is an application resource and compiled with the application.
StreamResourceInfo resource = Application.GetResourceStream(new Uri("/TestRIA;component/SampleData/test.pdf", UriKind.Relative));
docViewer.LoadDocument(resource.Stream);
This silverlight application will be hosted through a website deployed on a server. This server has a partition specifically for repositories of files. These files in the "D:" partition are currently accessed by an ASPX web application and displayed in a PDF viewer. We're moving to silverlight, so as the user selects the grid row representation of that file in the repository, I know the "NAME" of the file. The repository's location is a string held in the database configured in another application. I simply concatenate the file name to that repository path and have the filepath.
Again, the 3rd party viewer's "LoadDocument" method has two overloads. One that accepts a stream of the PDF and one that accepts the filename of the PDF.
For example I have a click event that feeds the name of the document, and I already have the root path to concatenate it to:
void testButton_Click(object sender, EventArgs e)
{
string docName = myListBox.SelectedItem.Content.ToString();
docViewer.LoadDocument(repositoryPath + docName);
//OR using stream
Stream s = new FileStream(repositoryPath + docName, FileMode.Open);
docViewer.LoadDocument(s);
}
You cannot programatically interact with an arbitrary file in SL4. Period. There's your section of isolated storage you can read from and write to files, but that isn't what you're looking for. You can read and write files through the file open dialog, but again I think that's not what you want.
The only way out of the Silverlight sandbox is the network. You have to have to talk to a non-sandboxed service to do this. SL has OK support for Web Services, Http, and even sockets. This seems doable for you since you're talking about the file being somewhere on a "server".
I remember reading that this will work without elevated trust only if the code is initiated with a user action such as button click.
http://msdn.microsoft.com/en-us/library/ff382752%28v=vs.95%29.aspx
For security purposes, if a Silverlight application is a sandboxed
application, file and print dialog boxes must be user-initiated. This
means you must show them from a user-initiated action, such as the
click event handler for a button.
As a possible workaround, if your Silverlight app is backed by a service, you could make the reading/writing of the file be handled by the service, assuming it has access to the location(s) and sufficient rights in the destination folder(s).
Create an OpenFileDialog box and you can return stream(s) to the selected file(s).

What is the best way to let users upload pictures to my WPF application

I have a WPF intranet app running in Trusted mode (local only).
I would like the users to be able to upload an image and attach it to an article on my newsletters section. I am having trouble deciding where these images will be stored.
Please provide me with your opinions.
At present I have a few ideas myself;
I could have an aspx page that runs parallel to this app, and run this inside a browser(I-frame). This page could then handle the upload and display of the image.
I could also, have the users copy directly to a network share.
It seems that there should be a more elegant sollution that I am not aware of.
Any ideas?
Don't force the solution towards ASPX just because you know how to do it there. It's unnatural to build a page, host browser to show that page etc, just so you could upload an image.
It's actually quite simpler to do it in a desktop client than on web page. You have a "Load File Dialog" - use that to get to the filepath the user wants to upload, and when you have that you can either:
copy it (inside your application) to your share,
or if you have a service - send it through some method call,
or you can even store it inside a database (recommended if the files are small)
There's really lots of options here... it depends if your client has connection to db, do you have service in between, etc...

silverlight in html EMAIL body

I have a news letter which i did in silverlight, is there a way to send it in email. like as you include html tags, is there a way to include silverlight xap package in it.
Probably better to reference a webpage containing your silverlight content.
Technically, you could put the path to the .xap hosted on a website into an HTML email body, but nearly all mail clients will not display this - most even prevent images from loading by default.
Most email systems will prevent you from embedding active content like SilverLight, as it presents a security risk. Your only option probably is to put your SilverLight app on the web, and just email a link to it.
Don't if you want your newsletter to be read by anyone. See this article for a good list of do's and don'ts when sending emails.
Don't listen to those guys, they're probably FlashHeads... ;)
Besides that they give up too easily. More power to ya!
I assume this newsletter is for an audence that specifically desires your content: i.e a club or similar organization that doesn't have a windows based webserver.
What you do is attach the file in such a way that they drag a zip containing the files that would normally be served from a website to the hard drive - right click - extract all then they run it by clicking on an HTML file with .htm extension that hosts the silverlight plugin instead of an aspx file.
One note that probably won't matter to you is that without a server backing this up the content can't really send you back any info but it CAN get dynamic info that comes from say RSS feeds or WCF services hosted on the web.

Resources