Issues with C1 MVC PdfViewer and Loading a PDF from an API Controller in ASP.NE

Posted by: sebastian-jn.k on 3 June 2025, 11:00 am EST

  • Posted 3 June 2025, 11:00 am EST

    Hi everyone,

    I’m having an issue with using the C1 MVC PdfViewer in an ASP.NET MVC 4.8 application and I hope someone here can help me out.

    My goal is to display a PDF document in the PdfViewer that is delivered by an API controller. The PDF is provided via an API that returns the PDF as a byte array.

    Current Setup:

    *I’ve successfully embedded the C1 MVC PdfViewer in my Razor View, and it’s visible.

    *I can access the PdfViewer via JavaScript using wijmo.viewer.pdfViewer.getControl(‘#pdfViewerPlaceholder’), and this works as expected.

    *There are two relevant properties, serviceUrl and filePath, that I am setting, but so far the PDF doesn’t show up in the viewer.

    My API Endpoint:

    I have an API controller that returns the PDF by ID. The endpoint looks something like this:

    'api/Files/{id}'

    The return in the controller looks something like this:

    var msg  =new HttpResponseMessage()
    {
        Content = new StreamContent(pdfBytes)
    }
    msg...ContentType = new ....("application/pdf");
    msg...ContentDisposition = new ...("attachment")
    msg...ContentDisposition.FileName = "testID*.pdf"

    The Problem:

    Although the endpoint returns the PDF correctly as application/pdf, the PDF is not being displayed in the PdfViewer.

    My Question:

    How should I properly set the serviceUrl and filePath so that the PDF is displayed in the PdfViewer? Or is there another configuration I need to consider?

    Thanks in advance!

  • Posted 4 June 2025, 8:34 am EST

    Hello,

    If your URL looks something like the following: http://{host}/api/pdf/PdfRoot/{PDF File Name}/$pdf

    Then ServiceUrl = http://{host}/api/pdf/

    and FilePath = PdfRoot/{PDF File Name}/

    Please refer to PDF Services(https://developer.mescius.com/componentone/docs/webapi/online-webapicore/PDFServices.html) and PdfViewer documentations (https://developer.mescius.com/componentone/docs/mvc/online-mvc/PDFViewerQuickStart.html) for more information.

    You can also refer to our product samples located at *.\Documents\ComponentOne Samples\ASP.NET MVC\v4.8\MVC\CS* and .\Documents\ComponentOne Samples\Web Api\v4.8\CS on your machine if you have installed samples while installing C1Web Suite using ComponentOneControlPanel.

    Alternatively, you can find them on GitHub at:

    Please let us know if you still face any issues at your end.

    Regards,

    Uttkarsh.

  • Posted 4 June 2025, 10:57 am EST

    Hi,

    thanks for your response.

    I’m currently using a standard .NET ApiController. As previously mentioned, it’s returning a PDF file like this:

    
    var msg = new HttpResponseMessage()
    {
        Content = new StreamContent(pdfBytes)
    };
    msg.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");


    So basically, a byte stream.

    My question is:

    Is it possible to continue using my existing API setup, or do I have to use the Web API provided by ComponentOne?

    We’re using the Enterprise version of ComponentOne, and I believe the Web API is included – is that correct?

    Greetings from Germany!

  • Posted 5 June 2025, 1:40 am EST

    Hello,

    We’re sorry, but it’s not possible to display a PDF directly from a standard Web API. You’ll need to use the ComponentOne PDF Web API Service for that functionality.

    > We’re using the Enterprise version of ComponentOne, and I believe the Web API is included – is that correct?

    Yes, Web API is included with the Enterprise version of ComponentOne.

    Regards,

    Uttkarsh.

  • Posted 11 June 2025, 10:05 am EST

    Hello,

    I’m trying to get the C1.Web.Api.Pdf service working in a classic ASP.NET application:

    :wrench: Setup:

    *.NET Framework 4.8

    *Project structure: ASP.NET MVC 5 + Web API 2

    *Installed NuGet packages:

    **C1.Web.Api

    **C1.Web.Api.Document

    **C1.Web.Api.Pdf

    What confuses me is that the NuGet descriptions say “ASP.NET Core MVC Edition,” although the dependencies clearly target .NET 4.x – so I assume it should work with classic ASP.NET as well.

    :question: What I’m trying to achieve:

    I want to serve ready-to-use PDF files stored in a database through the API, so they can be displayed in a

    C1.Web.Mvc.FlexViewer.

    In the sample project attached to this post, I’ve created a test

    PdfViewerController 
    that inherits from PdfController – this is how I imagined the setup might work. The structure exactly matches my real application (ASP.NET MVC 5 + Web API 2).

    However, this is just an experimental approach, and I’m not sure whether it’s correct or what else might be required to get the PDF service working properly.

    :jigsaw: Problem:

    Despite many attempts, I just can’t get the PDF service to work.

    I also tried running the official ComponentOne example from MESCIUS, but couldn’t get it running – several DLLs couldn’t be resolved and NuGet failed to restore them.

    **Just for reference: **The sample I’m referring to is this one on GitHub:

    https://github.com/GrapeCity/ComponentOne-Web-API-Samples/tree/master/WebApi

    Unfortunately, the sample is far too complex for my needs, as it includes the full C1 Web API implementation and is built as a pure Web API project. Since my app combines MVC and Web API, I couldn’t extract anything directly useful from it.

    I’ve also spent hours reading blog posts, documentation, and forum threads, but nothing I found matches my project structure or helps me solve the issue.

    :pray: My request:

    Could you please provide a minimal, working example based on the attached project structure?

    That would be the most practical way for me to understand how to correctly integrate the PDF service into my application.

    Any help is very much appreciated!

    Best regards from germany

    WebApplication1.zip

  • Posted 12 June 2025, 8:12 am EST

    Hello,

    We’re working on your requirement and will update you once we are done with it.

    Regards,

    Uttkarsh.

  • Posted 13 June 2025, 7:11 am EST

    Hello,

    What confuses me is that the NuGet descriptions say “ASP.NET Core MVC Edition,” although the dependencies clearly target .NET 4.x – so I assume it should work with classic ASP.NET as well.

    Sorry for the confusion; yes, these NuGet packages are for classic ASP.NET.

    We have created a simple sample displaying a PDF located in the RootPdf folder in C1WebAPI. You can download the sample at https://drive.mescius.io/download?file=ExternalShare/WinForms/PdfViewer_Sample.zip.

    Please let us know if it helps.

    Regards,

    Uttkarsh.

  • Posted 13 June 2025, 8:27 am EST

    Hello Uttkarsh,

    thank you very much for your quick reply and for providing the sample project – I truly appreciate your support.

    I’ve downloaded and reviewed the sample. While it’s a helpful starting point, I’d like to clarify a few important points regarding my specific setup:

    First of all, I already have the

    C1.Web.Mvc.FlexViewer
    successfully integrated and working on my page. The viewer itself is rendering correctly – that part is not an issue.

    Also, I am not working with two separate projects. My application is a single ASP.NET MVC 5 project that includes Web API 2.0 – it’s a hybrid structure. This setup is exactly reflected in the sample project I attached in my last post, which mirrors the structure of my real-world application.

    What I’m trying to achieve is slightly different from what your sample demonstrates. Your example serves a static PDF from the file system in a pure Web API project. In contrast, my goal is to:

    Stream PDF files directly from a database, in the correct format expected by the FlexViewer

    Implement this in a controller within my MVC/Web API application – for example, something like a PdfExampleController that inherits from C1.Web.Api.Pdf.PdfController

    Ensure that the response works seamlessly with the existing FlexViewer setup on the frontend

    My current application is already capable of loading PDF files from the database as byte arrays or memory streams. What I need help with is:

    How to properly extend or use PdfController to return a stream from in-memory data instead of a file path

    How to register or configure this in the Web API setup of an MVC 5 + Web API 2 application (e.g. WebApiConfig, routes, service registration)

    Any specifics I need to be aware of when integrating C1.Web.Api.Pdf into a hybrid project like mine

    Would it be possible to get a minimal example or some guidance on how to correctly implement this?

    Thanks again for your help – it’s very much appreciated, and your support is helping me move closer to a working solution.

    Best regards from Germany

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels