Home Generate PDF then Print C#
Reply: 0

Generate PDF then Print C#

user2782 Published in April 22, 2018, 10:03 pm

After calling API to get data, I need to generate the PDF file to PRINT using the default available. Currently, Im able to get the data but then PDF not generated or downloaded.

AJAX codes to call controller to process request.

$(document).on('click', '#RePrint', function (event) {
        var checkedVals = $('.ExportOrder:checkbox:checked').map(function () {
            var orderId = this.value;
            var status = document.getElementById(orderId).innerText;
            if (status != "Received")
                return this.value;
        if (checkedVals.length > 0) {
                url: '/Orders/RePrintLabel',
                type: 'POST',
                data: { ExportOrder: checkedVals },
                dataType: "json",
                async: true


public ActionResult RePrintLabel(string[] ExportOrder)
            var orders = ExtractOrders(ExportOrder, "Reprint");
            if (orders.Count() > 0)
                foreach (var item in orders)
                    var label = _orderMgr.RePrintLabel(item);

                    //Generate PDF For Label
                    if (label != null)
                        if (label.success)
                            byte[] byteContent = label.labels[0];
                            MemoryStream pdf = new MemoryStream(byteContent);
                            Response.ContentType = "application/pdf";

                            string pdfName = label.order_number;
                            Response.AddHeader("Content-Disposition", "attachment; filename=" + pdfName + ".pdf");
                            Response.ContentType = "application/pdf";
                            Response.Buffer = true;

            return RedirectToAction("Export");

The data is successfully returned and able to execute until this code Response.Close(); pdf was not downloaded or displayed to print.

Is there a way that I could automatically print the PDF file right after it is generated or the data is returned successfully using a default printer?

Thank you in advance for your help. Really appreciated.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30748 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO