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

    • Post Options:
    • Link

    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

  • Posted 16 June 2025, 6:51 am EST

    Hello,

    Apologies for the oversight.

    For your use case, we believe it would be better to implement Blob storage that retrieves a blob PDF file or a customized PDF document as a stream from an API or controller.

    Please refer to the attached sample for implementation. (see BlobPdfProvider.zip)

    Regards,

    Uttkarsh.

  • Posted 24 June 2025, 7:31 am EST

    Hello Uttkarsh,

    I have reviewed the sample project and successfully adapted it to my own project (ASP.NET MVC + Web API) – thank you for that!

    However, I noticed that a large number of NuGet packages are included (a total of about 500 MB). As a result, the project’s startup time is significantly longer.

    My questions are:

    *Are all the included DLLs or packages really necessary?

    *Is there a way to run the project with a minimal configuration?

    *Is there any documentation or overview of which dependencies are specifically required for Blob Storage – and at the same time a technical explanation of what functionalities are actually added “under the hood”?

    Thank you in advance for your support!

  • Posted 25 June 2025, 5:12 am EST

    Hello,

    We’re sorry, but all the C1 packages included are necessary for the functionality, and the sample is already a minimal project.

    These packages tend to be large because they contain assemblies for different .NET versions along with other metadata. However, when you build the application, only the required DLLs are used (you can check this in the bin/Debug folder), which reduces the size. It gets even smaller when you publish the application.

    For example, in this sample, the C1 packages take up around 290 MB, but the published output is less than 97 MB.

    → Is there any documentation or overview of which dependencies are specifically required for Blob Storage – and at the same time a technical explanation of what functionalities are actually added “under the hood”?

    We’re sorry, but there isn’t any official documentation available for this, as the use case is specific to your requirement and involves a custom implementation of a StorageProvider to host the PDF.

    C1.Web.Api provides a storage service that allows hosting a custom “blob” storage to expose the PDF.

    Regards,

    Uttkarsh.

  • Posted 25 June 2025, 9:56 am EST

    Hi Uttkarsh,

    Thanks again for your previous response! However, I still have the following question:

    In the Web API Explorer (under this link: https://developer.mescius.com/componentone/demos/aspnet/webapiexplorer ), I found the endpoint:

    GET /api/pdf/{pdf path}/$pdf.

    This returns a JSON object of the IExecutionInfo interface. Here is the link to the detailed documentation for IExecutionInfo:

    https://developer.mescius.com/componentone/docs/webapi/online-webapi/C1.Web.Api.Document~C1.Web.Api.Document.Models.ExecutionInfo~ExpiredDateTime.html.

    The issue is that the cache duration seems to be set to 10 minutes by default, and that’s not ideal for my use case. The expiration time is indicated in the ExpiredDateTime field of the ExecutionInfo JSON object.

    Is there a way to configure or adjust the cache duration on the PDF service side? Any help would be much appreciated!

  • Posted 26 June 2025, 8:30 am EST

    Hello,

    We have shared your concerns with the development team. [Internal Tracking ID: C1WEB-30039]

    Rest assured, we’ll update you once we have more information.

    However, could you please share your use case for configuring the ExpiredDateTime and let us know what issues you’re facing because of it?

    Regards,

    Uttkarsh.

  • Posted 26 June 2025, 10:58 am EST

    Hi Uttkarsh,

    Use Case:

    User B opens Example1.pdf and notices incorrect content.

    User B informs User A, who is responsible for updating the underlying data.

    User A updates the data and refreshes Example1.pdf in the database.

    User A notifies User B that the updated PDF is ready.

    User B reopens the PDF – but still sees the outdated version, as the document is cached (current cache duration is 10 minutes, according to the ExpiredDateTime variable which can be retrieved via the API endpoint).

    Problem:

    Especially when changes need to be reviewed or processed immediately, this delay causes confusion and workflow issues.

    Best regards from germany

  • Posted 4 July 2025, 12:23 am EST

    Hello,

    As per the team, the caching can be disabled like this:

    @(Html.C1().PdfViewer()
      .Id("PdfViewer")
      .Width("100%")
      .RequestHeaders(new Dictionary<string, object> { { "disable_cache", "true" } })
      .FilePath("Blob/dummy.pdf"))

    Please let us know if you face any issues by reverting with details or creating a new ticket if the concern differs.

    Regards,

    Uttkarsh.

  • Posted 4 July 2025, 3:55 am EST

    Perfect!

    Thanks for helping!

Need extra support?

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

Learn More

Forum Channels