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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:57:03+00:00 2026-06-09T12:57:03+00:00

What I need to do is; Get a pdf from sharepoint Get a single

  • 0

What I need to do is;

  1. Get a pdf from sharepoint
  2. Get a single page, using PDFSharp
  3. Return that to the view and display that page

What I have thus far is;

        context.Response.ClearHeaders();
        context.Response.ContentType = "application/pdf";            
        context.Response.AddHeader("content-disposition", "inline; filename=Something.pdf");

        // Get a fresh copy of the sample PDF file from Sharepoint later on
        string filename = @"book.pdf";

        // Open the file
        PdfDocument inputDocument = CompatiblePdfReader.Open(filename, PdfDocumentOpenMode.Import);

        PdfDocument outputDocument = new PdfDocument();
        outputDocument.Version = inputDocument.Version;
        outputDocument.Info.Title = "Pages 1 to 30";
        outputDocument.Info.Author = "Slappy";

        outputDocument.AddPage(inputDocument.Pages[1]);

        MemoryStream ms = new MemoryStream();
        outputDocument.Save(ms, false);

        ms.WriteTo(context.Response.OutputStream);

What I can’t figure out is how to then display that within the web page.

I have this;

<script src="../../Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.media.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.metadata.js" type="text/javascript"></script>

<script>
    $(function () {
        $.ajax({ url: '/GetBookPage.ashx',
            success: function (result) {
                $("a.media").attr('href', result);
                $('a.media').media({ width: 800, height: 600 });
            },
            async: false
        });
    });
</script>

<a class="media">PDF File</a>

The above works if I save the pdf to the filesystem and then point the href at that file.

  • 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-09T12:57:04+00:00Added an answer on June 9, 2026 at 12:57 pm

    With the following handler:

    public class GetBookPage : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                string filePath = @"c:\somepath\test.pdf";
                context.Response.ContentType = "application/pdf";
                context.Response.AddHeader("content-disposition", "inline; filename=test.pdf");
                context.Response.WriteFile(filePath);
                context.Response.End(); 
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    

    I was able to get the PDF to display inline if you do the following:

    <script type="text/javascript">
       $(function () {
            $('a.media').media({ width: 800, height: 600 });
        });
    </script>
    
    <a class="media" href="/GetBookPage.ashx?.pdf">PDF File</a>
    

    The plugin is using the url (or more accurately the extension) to build the proper media container on the page. If you don’t have “.pdf” it won’t work as expected.

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

Sidebar

Related Questions

I have to create a pdf report from several classes that are going to
I need to validate a particular content from the PDF using QTP . How
Never worked with Sharepoint, but need to add a WebPart to display a PDF
I need to extract the text from a PDF that has already been transformed
I'm trying to get a PDF page that is within the context of my
I need to extract text from pdf files using iText. The problem is: some
I have 1000s and 1000s of PDF articles from which I need to extract
I need to generate a PDF file with some information i get from a
I need get all items these have no categories int? categoryId = null; var
I have linq request. I need get item.Title in select. how do this? var

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.