We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Create PDF From Word Doc and View In PDF viewer without saving

Thread ID:





144769 May 21,2019 07:34 PM UTC May 23,2019 06:57 AM UTC ASP.NET Core - EJ 2 3
Tags: PDF Viewer
Matthew Souder
Asked On May 21, 2019 07:34 PM UTC

I have successfully saved a PDF created from a word doc template utilizing mail merge events in an asp.net core razor application

I would prefer not to save the file locally and upon rendering the PDF from the word file, view it on my webpage to give the user the ability to view the details in the pdf and print if necessary.  I'm stuck on returning the pdf to the Viewer and loading it after creating it.  Worst case, i would like to save over previously created pdf's


the method in my controller:Details.cshtml.cs

public async Task<IActionResult> OnPostGeneratePDFAsync()
    Box = await _context.Box
            .Include(b => b.Location)
            .Include(b => b.Part).FirstOrDefaultAsync(m => m.BoxId == 75);

    string dataPath = _hostingEnvironment.WebRootPath + @"/images/";
    FileStream docStream = new FileStream(dataPath + "TTTT.docx", FileMode.Open, FileAccess.Read);
    WordDocument document = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic);

    string[] fieldNames = new string[] { "loadNumber", "loadDate" };
    string[] fieldValues = new string[] { "test load", "test/date" };

    document.MailMerge.Execute(fieldNames, fieldValues);

    MemoryStream stream = new MemoryStream();
    document.Save(stream, FormatType.Docx);
    stream.Position = 0;

    // Creates a new instance of DocIORenderer class.
    DocIORenderer render = new DocIORenderer();
    // Converts Word document into PDF document.
    PdfDocument pdf = render.ConvertToPDF(document);
    MemoryStream memoryStream = new MemoryStream();
    // Save the PDF document.
    memoryStream.Position = 0;

    return File(memoryStream, "application/pdf", "WordToPDF.pdf");



@page "{id}"
@model Summit.Pages.BackOffice.Boxes.DetailsModel

    ViewData["Title"] = "Details";
<div class="container">
    <form id="pdfCreate" method="post" asp-page-handler="GeneratePDF" style="display:inline"><h2 style="display:inline">Box @Html.DisplayFor(model => model.Box.BoxId) Details:</h2><input type="submit" class="btn btn-primary btn-xs" value="Box Label" /></form>

@section ControlsSection{
    <div class="control-section">
        <ejs-pdfviewer id="pdfviewer" style="height:641px;"></ejs-pdfviewer>

    <script type="text/javascript">
    window.onload = function () {
        var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
        pdfViewer.serviceUrl = window.baseurl + 'api/PdfViewer';
        pdfViewer.load("PDF Succinctly.pdf", null);

Ramya Thirugnanam [Syncfusion]
Replied On May 22, 2019 07:04 AM UTC

Hi Matthew, 
Thank you for contacting Syncfusion support. 
We can load the PDF document as base64 string in the PDF Viewer control. So we can convert the PDF document(converted from Word document) into base64 string and load it in the PDF Viewer control using documentPath property or load() method. We have created a simple sample for converting the Word document to PDF document and loading the same to the PDF Viewer control as base64 string. It can be downloaded from the following link. 
In the above sample, we have provided a button “Load PDF document as Base64String”. When this button is clicked, a request will be sent to the web service with “GetDocument” action method. In this method, we will convert the Word document into PDF document and return the base64 string to the client. In the client, when the request completed, the base64 string in the response will be loaded in the PDF Viewer control with documentPath property. 
Please find the below documentation link for more details. 
Ramya T 

Matthew Souder
Replied On May 22, 2019 01:25 PM UTC

Thanks Ramya-

I've got it up and running in my application.  The only issue i'm having is when i go to print the pdf from the viewer.  It spools like it is going to print but nother ever happens.  All other PDF Viewer functionality works.


Ramya Thirugnanam [Syncfusion]
Replied On May 23, 2019 06:57 AM UTC

Hi Matthew, 
Sorry for the inconvenience caused, 
We have missed to include the PrintImages action method in the PDF viewer controller class and it causes the issue. However, now we have included the PrintImages action method in the controller and share the sample in the following link. 
Ramya T 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon