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 9248309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:55:01+00:00 2026-06-18T09:55:01+00:00

I’m trying to follow this article here: https://web.archive.org/web/20211020001758/https://www.4guysfromrolla.com/articles/030911-1.aspx I have this method in Services.asmx:

  • 0

I’m trying to follow this article here: https://web.archive.org/web/20211020001758/https://www.4guysfromrolla.com/articles/030911-1.aspx

I have this method in Services.asmx:

[WebMethod]
public void CreatePdf()
{
    // Create a Document object
    var document = new Document(PageSize.A4, 50, 50, 25, 25);

    // Create a new PdfWriter object, specifying the output stream
    var output = new MemoryStream();
    var writer = PdfWriter.GetInstance(document, output);

    // Open the Document for writing
    document.Open();

    // Create a new Paragraph object with the text, "Hello, World!"
    var welcomeParagraph = new Paragraph("Hello, World!");

    // Add the Paragraph object to the document
    document.Add(welcomeParagraph);

    // Close the Document - this saves the document contents to the output stream
    document.Close();

    HttpContext.Current.Response.ContentType = "application/pdf";
    HttpContext.Current.Response.AddHeader("Content-Disposition",
        "attachment;filename=file.pdf");
    HttpContext.Current.Response.BinaryWrite(output.ToArray());        
}

And this jQuery code on my page:

$('a.download').click(function () {

    $.ajax({
        type: "POST",
        url: "/Services.asmx/CreatePdf",
        data: '{}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            alert(result.d);
        }
    });
});

This is supposed to create a pdf and stream it to the user’s browser.

When I click on a link with the class download, my web method gets hit and the code runs. It just doesn’t stream the pdf to the browser.

If I look in Firebug, it posts to my method with status 200, and I get this Response:

%PDF-1.4
%����
2 0 obj
<>stream
x�+�r
�25P�04WI�2P�5��1���BҸ4>>>/Contents 2 0 R/Parent 3 0 R>>
endobj
1 0 obj
<>
endobj
3 0 obj
<>
endobj
5 0 obj
<>
endobj
6 0 obj
<>
endobj
xref
0 7
0000000000 65535 f
0000000304 00000 n
0000000015 00000 n
0000000392 00000 n
0000000147 00000 n
0000000443 00000 n
0000000488 00000 n
trailer
<<21ba8d519bb56a2d0ec514bcb9c47169>]>>
%iText-5.3.5
startxref
646
%%EOF
{“d”:null}

Am I doing something wrong here?

  • 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-06-18T09:55:02+00:00Added an answer on June 18, 2026 at 9:55 am

    Marc B is correct. You need to have your server-side code respond with the pdf output stream.

    So, point your download link to a new file, say PDFDownload.aspx, and place the code from your CreatePdf function in the PageLoad of PDFDownload.aspx.cs.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.