Articles in this section
Category / Section

How to use the PDF viewer control in WinForms platform?

3 mins read

We do not have support for the WinForms PDF viewer control in the ASP.NET(Classic). However, as a workaround we can use the ejPdfViewer control as in the below code snippet.


Default.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" type="text/javascript"></script>
    <link href="http://cdn.syncfusion.com/13.4.0.53/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet" />
    <script type="text/javascript" src="http://cdn.syncfusion.com/13.4.0.53/js/web/ej.web.all.min.js "></script>
</head>
<body>
    <div>
    <!-- Creating a div tag which will act as a container for ejPdfViewer widget.-->
    <div id="viewer" style="height: 650px;width: 950px;min-height:404px;" ></div>
    <!-- initializing ejPdfViewer widget.-->
<script type="text/javascript">
    $(function () {
        $("#viewer").ejPdfViewer({
            serviceUrl: "/api/PdfViewerAPI"
        });
    });
    </script>
</div>
 
</body>
</html>

 

PdfViewerAPIController.cs

public class PdfViewerAPIController : ApiController

{

    public object PostViewerAction(Dictionary<string, string> jsonResult)

    {

        PdfViewerHelper helper = new PdfViewerHelper();

        helper.Load(Helper.GetFilePath("Barcode.pdf"));

 

        object output = helper.ProcessPdf(jsonResult);

        string response = JsonConvert.SerializeObject(output);

        return response;

    }

}

 

public class Helper

{

    public static string GetFilePath(string path)

    {

        string _dataPath = GetCommonFolder(new DirectoryInfo(HttpContext.Current.Request.PhysicalApplicationPath));

        _dataPath += @"\" + path;

        return _dataPath;

    }

 

    static string GetCommonFolder(DirectoryInfo dtInfo)

    {

        var _folderNames = dtInfo.GetDirectories("Data");

        if (_folderNames.Length > 0)

        {

            return _folderNames[0].FullName;

        }

 

        return dtInfo.Parent != null ? GetCommonFolder(dtInfo.Parent) : string.Empty;

    }

}

 

 Sample:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfViewerASP1580520605


Conclusion

I hope you enjoyed learning how to use the PDF viewer control in WinForms platform.

You can refer to our WinForms PdfViewer feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PdfViewer example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied