This project is read-only.

opening pdf from server

Mar 14, 2013 at 4:13 PM
I am unable to run the loading strategies example from the sample project. I need to be able to open a pdf from the server and display it to the user. I thought i could use the Web All-In-Once but can't seem to get it working. Can someone please help me or provide me sample code to open a pdf document from the server and display to user in silverlight client.
Mar 14, 2013 at 4:19 PM
You'll need to download the PDF document using a WebClient and then create a PdfDocumentReader like so:
var webClient = new WebClient();
webClient.OpenReadCompleted += (o, e) => {
  if (e.Error != null) {
    // TODO: handle error
  }
  else if (!e.Cancelled) {
    // create new package reader
    this.DataSource.PackageReader = new PdfDocumentReader(e.Result);
  }
};

// start the download
webClient.OpenReadAsync(new Uri("[url-to-pdf-doc]", UriKind.Absolute));
Mar 14, 2013 at 6:00 PM
I added the code and was able to open the pdf, but when setting it to the datasource i received an error that says "could not read the XPS package. Either the package is not valid XPS or the package reader does not support the ZIP format of the package.
Mar 14, 2013 at 7:44 PM
Make sure you use the PdfDocumentReader, not some other package reader.
Mar 14, 2013 at 10:42 PM
Got it working. thanks for all your help