Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7683171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:44:04+00:00 2026-05-31T18:44:04+00:00

I am accessing an existing WCF web service (which returns a PDF as a

  • 0

I am accessing an existing WCF web service (which returns a PDF as a byte stream) using jquery’s ajax methods.

When the call to the service completes, I end up with a javascript variable containing a PDF (the variable has the binary data in, starting “%PDF-1.4…”).

I’d like to display this PDF in a new browser window, but I’m having difficulty achieving this.

My research so far shows that I might be able to achieve what I want using a data: uri, so my code that’s called when the ajax call completes is as follows:

function GotPDF(data)
{
    // Here, data contains "%PDF-1.4 ..." etc.
    var datauri = 'data:application/pdf;base64,' + Base64.encode(data);
    var win = window.open("", "Your PDF", "width=1024,height=768,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");
    win.document.location.href = datauri;
}

This causes a new browser window to open, but the contents are blank.

Interestingly, if I point my browser (IE9) at an existing file on my local disk by using a file: uri, such as file://c:/tmp/example.pdf, then I get the same result, i.e. a blank window.

Is there any way I can display this PDF data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:44:05+00:00Added an answer on May 31, 2026 at 6:44 pm

    Code you wrote does not display anything, simply open a blank window (location.href is an hash for browsing history, not the content of the page).

    To display a PDF you have, at least, following options:

    × Embed the PDF viewer inside an object tag. It may not be as straightforward as you may imagine, take a look to this post for sample code. In short it should be something like this:

    <object data="your_url_to_pdf" type="application/pdf">
        <div>No PDF viewer available</div>
    </object>
    

    That’s basic code but I suggest to follow what I say in the linked post if you need higher cross-browser compatibility (it also contains a few examples about how you might try to detect support for a PDF viewer).

    × Download the file to local computer (simply add the full URL of your web service method that produces the file, do not forget to add the proper Content-Disposition in the header).

    × Open the file into a new browser window. Create a normal a tag as you point to a PDF file on-line that you want to display in a new window. Change the href to javascript:functionName and in that function produce the URI you’ll use to call the web service method.

    Whatever you’ll do, do not forget to set the proper MIME type in your response moreover you method shouldn’t return a byte stream (even if encoded) but a valid response for your web browser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing database, which I have been happily accessing using LINQtoSQL. Armed
I am working on an application where i am using a wcf service. I
when accessing foo() of base using derived class's object. #include <iostream> class base {
I am having trouble accessing the data field. I receive the error: Databinding methods
I have a question on accessing already existing paired bluetooth connections... How can a
I'm trying migrating an existing web application to use RavenDB. I currently have pages
I'm using accessing thorough DBUS from some process. The trouble is that it runs
I'd like to be able to give some existing Users a custom permission which
I'm writing an small software that will be part of an existing application which
I’m converting an existing piece of code using Redemption (an MS Exchange library) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.