I would like to develop an app for printing service in Windows Phone 7. In the app, the users can select file to print out. Is there any way to open docx, xlsx, etc. in WP7 programmatically? I know in iPhone the WebView supports to view many file types. Is there anything similar in WP7?
If you are looking to open the document in Office, try using the WebBrowserTask to navigate to the document. There's a good chance it will open with Office.
If you want to render the document yourself, you are very much out of luck. You could try navigating to the document in a WebBrowser control, but I don't think it's supported.
Besides, there are no printing APIs so there would be no way to print it. If this is an enterprise application (ie. internal to your company), you might consider writing a web service on a local server that can accept DOCX files and print them. You could then call that service from your app to print the docs.
You will not be able to open these types of files from the isolated storage. There is no way for third-party applications to launch the external application required for viewing these file types. All of the files which you have listed in your question are XML-based open source file formats. Depending on how much time you want to spend on this, you could write your own parser or possibly utilize an open-source or commercial one.
Related
I am working on an asp.net mvc project. How can I open doc.file to print it from page? The only thing I can do now is downloading, however, I'd like to open it as print friendly file in sort of window.print()
Normally you just supply correct content type. Then user can view the file inside the browser and print it.
However, if the browser doesn't have appropriate plugin, then user can only download the file.
public ActionResult Download()
{
return File("~/MyDocument.doc", "application/vnd.ms-word", "MyDocument.doc");
}
.doc files are designed to be opened with MS Word (and at one point there was a Word Viewer presumably designed for this sort of thing). There are also other apps (e.g. OpenOffice / LibreOffice) which will allow you to read & write MS Word documents with varying degrees of success.
So one option -- as #Win points out -- is to require that users have some compatible application installed. You frequently see this with PDF files, the site will typically contain a link to download Adobe (Acrobat) Reader. The external app will be used to display the file; if the app can run as a plugin the content will be displayed "inside" the browser.
If the app is primarily intended for users internal to your business, and they all have Office installed, then that's a perfectly acceptable solution.
If you want the content to be available people who don't have Office (and/or don't run Windows) it gets much more difficult. You'd need to either:
write an MVC view that will parse/render .doc files (not for the faint of heart)
convert the content to some other format (PDF or HTML) that's more easily "consumed".
I am developing a ASP .NET MVC application where users are able to upload files to a repository. Those files could be pdf, doc, any type of image and so on.
When the user select a file to be imported I would like to display this file in the browser so they can review its contents before the upload.
I know I could use some sort of IFrame to display pdf but I am looking for some specific class or .net libraries to implement this feature.
I just need a north.
This is an extremely difficult problem. There are some libraries that can help. For instance PDF files might be rendered to images with ghostscript. Word and Excel files might be converted to PDF or image with a number of libraries. None of them, AFAIK, are very good at it so I can not recommend one.
You could automate MSO to perform the conversion to PDF, but that is decidedly not safe for server code. Another possibility is convert source documents to SWF files (like flexpaper) and display in flash. There are some great libraries out there, but it will limit your supported clients. Sharepoint has support for providing some of this capability as well. Others have used OpenOffice to convert MSO documents but also at a loss of quality.
I can't really advise any specific direction as it is highly dependent on what you/your company is willing to spend and the desired results. Good luck.
You could try to rely on Windows and the explorer thumbnails for it, like here, but then you'd have to make sure that:
You can abuse the server in the most elaborate way (install stuff, talk to the shell from ASP.NET)
You have a thumbnail provider installed on the server for every type that you want to preview. I guess from the moment you can see the thumbnail in explorer, you're set. So for pdf, you might need to install PDF Reader from Adobe.
Docx files should be saved with thumbnail checked (see link). There seems to be no other easy, free way to convert a docx to a thumbnail. The "best" solution I came across, was saving it automatically again somehow, and making sure the thumbnail option is checked.
I don't want to say that's impossible, but it can't be done with finite effort.
What you are asking for is a browser-based solution, because you want the user to be able to "review" the document before uploading.
Therefore you cannot use a server side solution, which is essentially what is being asked by referring to a ".Net library".
.Net libraries are dependent on an installed version of .Net, which does not exist in all versions for all operating systems for which graphical browsers exist.
Next, recent changes in browser security do not allow to read the full client-side file name of the selected file in the input field.
You'd have to rely on HTML5 and its FileReader to access the file's byte stream, but even then you can only retrieve image from image files. (see sample)
Excluding browser-based solutions in Flash, ActiveX, Java, due to browser and platform support, this leaves JavaScript as the only "reasonable" solution: you'd need a library for each supported format to either convert a file into an image in an image format supported by browsers, or extract the text(+image) representation of a file.
Great awnsers... Just want to share the result of my research and I found a nice client-based solution supported by Mozilla Labs. This is a framework based on HTML5 and Javascript with no native code needed.
Here the project website:
https://github.com/mozilla/pdf.js
This is what you are capable of:
http://mozilla.github.com/pdf.js/web/viewer.html
And for the last a great video explaning how everthing works
http://www.youtube.com/watch?v=Iv15UY-4Fg8&noredirect=1
Reguarding my question we are going to converter every possible file to PDF on the server and then render this PDF using this framework.
I have come to the stage in my app where I need to download a pdf file from a certain URL, save it to disk (on the phone that is), and then as soon as it's saved try and open the document in whatever application is installed on the phone to handle PDFs (Adobe reader).
I have a rather limited understanding of how to save to disk and launch a certain file with another application.
Can someone point me in the right direction or give me some tips on how to accomplish this?
My understanding of windows phone is quite limited and I need to quickly add this feature on the app.
In Windows Phone 7, it is not possible to programmatically start the PDF viewer (it's possible in Windows Phone 8 though). So the best I can suggest is using the WebBrowserTask to open the web browser directly at the PDF's URL, then let the user open the file.
It's definitely not a great user experience, but I've been unable to find any other way (even using a WebBrowser control directly in the app doesn't seem to work).
var task = new WebBrowserTask();
task.Uri = new Uri("http://www.education.gov.yk.ca/pdf/pdf-test.pdf");
task.Show();
Where you saved the PDF in Isolated Storage?
You directly opened the Online PDF file in WebBrowser.
Follow these steps:
1) Download the from URI
2) Save to the Isolation Storage
3) Launch it using the launcher.
Note: 1) If you are downloading the pdf file than use .pdf extension while storing in Isolation Storage.
2)Make sure you have the related software installed in your phone like Adobe for PDF etc.
I need to get some contact detail and print it to PDF. Is there any way to do this in Windows Phone 7?
Even if you create a PDF in your application, it will not be accessible by other apps or your computer. The solution is emailing that file. Thus, you should send the details to a server and get it converted to a PDF then download it on the phone or, the server may email it for you.
There are many web services which will do this for you. See this: http://blog.nitropdf.com/2008/01/free-online-web-services-to-create-view-share-and-edit-pdf-files/
There's a branch of the SharpPDF project called PdfSharp for WP7. It states that it is not fully featured. It may/may not provide you with enough functionality for what you need. I haven't personally looked at the library, so you may wish to download it and see what features it provides.
Other than that, one of the most common ways to generate a PDF document using C# is iTextSharp. This most likely uses advanced features in the .NET framework and probably won't recompile for the Windows Phone. You could code up your own converter service that could also dispatch the newly created PDF via email once done. The app would usually be hosted somewhere (on a server or in the cloud) and would be accessible via WCF.
With C#, how can I print a PDF document (without any dialog boxes in the background) to an indicated printer?
I have used the following PDF library in the past to perform batch printing of PDF documents from a C# Windows Service.
http://www.quickpdflibrary.com/
It's a pretty decent library and if I remember correctly it only took a few lines of code to print the document. It worked very well and saved me a consider amount of time.
Also, the recommended link that discusses using DDE to launch a desktop application on a server to perform the printing is a bad idea. Adobe Reader probably doesn't support this and since it is a desktop application running in a windowless session you may run into problems with message boxes and dialog boxes. That solution just doesn't scale in my humble opinion.
here we go
Disclaimer: I work for Atalasoft
If you don't want to depend on Acrobat being on the server, you need to rasterize the PDF pages yourself and send them to the printer using the normal .NET printing API. We have a product that can rasterize PDF that uses the Foxit engine underneath. It deploys as a normal .NET assembly and doesn't require any other software to be installed.