public HttpResponseMessage exportPDF(ExportInvoiceRequest objRequest) { byte[] invoicePdf = invoice.exportPDF(objRequest); HttpResponseMessage result = null; result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new ByteArrayContent(invoicePdf); result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = "invoice_DuThao" + ".pdf"; return(result); }
/// <summary> /// service export pdf dự thảo hóa đơn /// </summary> /// <param name="exportObj"></param> /// <returns></returns> public byte[] exportPDF(ExportInvoiceRequest exportObj) { try { SearchInvoiceDA da = new SearchInvoiceDA(); GenerateXMLInvoice xMLInvoice = new GenerateXMLInvoice(); searchInvoiceResponse response = new searchInvoiceResponse(); //lay hoa don PVOILInvoice invoice = da.selectItemInvoiceByFKey(exportObj.FKey); InvoicesModel invoiceModel = ModelBase.mapperStatic <PVOILInvoice, InvoicesModel>().Map <PVOILInvoice, InvoicesModel>(invoice); searchInvoiceModel tmp = new searchInvoiceModel(); //tmp.invoice = invoiceModel; ////lay san pham //tmp.invoice.products = da.selectProductByInvoice(invoiceModel.id); //InvTemplate_GetTemplateInvoice_Result template = da.InvTemplate_GetTemplateInvoice(invoice.Pattern, invoice.ComTaxCode); ////Tạo data XML từ invoice và product //String xml = xMLInvoice.GetXMLData(tmp.invoice, tmp.invoice.products, template.TemplateName); //Tạo data html từ xml //String html = xMLInvoice.GetHtml(xMLInvoice.GetData(xml), template); //Tạo pdf html từ html var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter(); htmlToPdf.Zoom = 1.6f; htmlToPdf.Size = NReco.PdfGenerator.PageSize.A4; htmlToPdf.Margins = new PageMargins { Left = 20 }; //byte[] pdfBytes = htmlToPdf.GeneratePdf(html); //return pdfBytes; return(null); } catch (Exception ex) { throw ex; } }