Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Feature/wkhtml-remove (#275)

Krzysztof Pajak48c732fd7021
diff --git a/src/Business/Grand.Business.Common/Grand.Business.Common.csproj b/src/Business/Grand.Business.Common/Grand.Business.Common.csproj
index c0011cb1e..5ee026d38 100644
--- a/src/Business/Grand.Business.Common/Grand.Business.Common.csproj
+++ b/src/Business/Grand.Business.Common/Grand.Business.Common.csproj
@@ -1,5 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\Build\Grand.Common.props" />
+ <ItemGroup>
+ <PackageReference Include="HtmlRendererCore.PdfSharp" Version="1.0.5" />
+ </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Grand.Domain\Grand.Domain.csproj" />
<ProjectReference Include="..\..\Core\Grand.Infrastructure\Grand.Infrastructure.csproj" />
diff --git a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs b/src/Business/Grand.Business.Common/Services/Pdf/HtmlToPdfService.cs
similarity index 78%
rename from src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs
rename to src/Business/Grand.Business.Common/Services/Pdf/HtmlToPdfService.cs
index af20fdc9f..ee05745dd 100644
--- a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs
+++ b/src/Business/Grand.Business.Common/Services/Pdf/HtmlToPdfService.cs
@@ -5,35 +5,42 @@ using Grand.Domain.Media;
using Grand.Domain.Orders;
using Grand.Domain.Shipping;
using Grand.SharedKernel.Extensions;
-using Wkhtmltopdf.NetCore;
+using HtmlRendererCore.PdfSharp;
namespace Grand.Business.Common.Services.Pdf
{
/// <summary>
/// Generate invoice, shipment as pdf (from html template to pdf)
/// </summary>
- public class WkPdfService : IPdfService
+ public class HtmlToPdfService : IPdfService
{
private const string _orderTemaplate = "~/Views/PdfTemplates/OrderPdfTemplate.cshtml";
private const string _shipmentsTemaplate = "~/Views/PdfTemplates/ShipmentPdfTemplate.cshtml";
- private const string _paginationFooter = "assets/pdf/pagination.html";
- private readonly IGeneratePdf _generatePdf;
private readonly IViewRenderService _viewRenderService;
private readonly ILanguageService _languageService;
private readonly IRepository<Download> _downloadRepository;
private readonly IStoreFilesContext _storeFilesContext;
- public WkPdfService(IGeneratePdf generatePdf, IViewRenderService viewRenderService, IRepository<Download> downloadRepository,
+ public HtmlToPdfService(IViewRenderService viewRenderService, IRepository<Download> downloadRepository,
ILanguageService languageService, IStoreFilesContext storeFilesContext)
{
- _generatePdf = generatePdf;
_viewRenderService = viewRenderService;
_languageService = languageService;
_downloadRepository = downloadRepository;
_storeFilesContext = storeFilesContext;
}
+ protected PdfGenerateConfig PdfConfig()
+ {
+ var config = new PdfGenerateConfig {
+ PageSize = PdfSharpCore.PageSize.A4
+ };
+ config.SetMargins(20);
+ config.PageOrientation = PdfSharpCore.PageOrientation.Portrait;
+ return config;
+ }
+
public async Task PrintOrdersToPdf(Stream stream, IList<Order> orders, string languageId = "", string vendorId = "")
{
if (stream == null)
@@ -42,15 +49,9 @@ namespace Grand.Business.Common.Services.Pdf
if (orders == null)
throw new ArgumentNullException(nameof(orders));
- _generatePdf.SetConvertOptions(new ConvertOptions() {
- PageSize = Wkhtmltopdf.NetCore.Options.Size.A4,
- PageMargins = new Wkhtmltopdf.NetCore.Options.Margins() { Bottom = 10, Left = 10, Right = 10, Top = 10 },
- FooterHtml = CommonPath.WebHostMapPath(_paginationFooter)
- });
-
var html = await _viewRenderService.RenderToStringAsync<(IList<Order>, string)>(_orderTemaplate, new(orders, vendorId));
- var pdfBytes = _generatePdf.GetPDF(html);
- stream.Write(pdfBytes);
+ var pdf = PdfGenerator.GeneratePdf(html, PdfConfig());
+ pdf.Save(stream);
}
public async Task<string> PrintOrderToPdf(Order order, string languageId, string vendorId = "")
@@ -90,16 +91,9 @@ namespace Grand.Business.Common.Services.Pdf
if (lang == null)
throw new ArgumentException(string.Format("Cannot load language. ID={0}", languageId));
- _generatePdf.SetConvertOptions(new ConvertOptions() {
- PageSize = Wkhtmltopdf.NetCore.Options.Size.A4,
- PageMargins = new Wkhtmltopdf.NetCore.Options.Margins() { Bottom = 10, Left = 10, Right = 10, Top = 10 },
- FooterHtml = CommonPath.WebHostMapPath(_paginationFooter)
- });
-
var html = await _viewRenderService.RenderToStringAsync<IList<Shipment>>(_shipmentsTemaplate, shipments);
- var pdfBytes = _generatePdf.GetPDF(html);
- stream.Write(pdfBytes);
-
+ var pdf = PdfGenerator.GeneratePdf(html, PdfConfig());
+ pdf.Save(stream);
}
public async Task<string> SaveOrderToBinary(Order order, string languageId, string vendorId = "")
diff --git a/src/Business/Grand.Business.Common/Startup/StartupApplication.cs b/src/Business/Grand.Business.Common/Startup/StartupApplication.cs
index 23eda25a8..91319f3f7 100644
--- a/src/Business/Grand.Business.Common/Startup/StartupApplication.cs
+++ b/src/Business/Grand.Business.Common/Startup/StartupApplication.cs
@@ -50,8 +50,7 @@ namespace Grand.Business.Common.Startup
serviceCollection.AddScoped<IAddressAttributeService, AddressAttributeService>();
serviceCollection.AddScoped<IUserFieldService, UserFieldService>();
serviceCollection.AddScoped<IHistoryService, HistoryService>();
- serviceCollection.AddScoped<IPdfService, WkPdfService>();
- serviceCollection.AddScoped<IViewRenderService, ViewRenderService>();
+ serviceCollection.AddScoped<IPdfService, HtmlToPdfService>();
}
private void RegisterDirectoryService(IServiceCollection serviceCollection)
diff --git a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
index 73c1d997a..8acfac586 100644
--- a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
+++ b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
@@ -19,7 +19,6 @@
<PackageReference Include="StackExchange.Redis" Version="2.5.61" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.4.0" />
- <PackageReference Include="Wkhtmltopdf.NetCore" Version="3.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Grand.Domain\Grand.Domain.csproj" />
diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.cs
index 59250ac3f..3ee9545a7 100644
--- a/src/Core/Grand.Infrastructure/StartupBase.cs
+++ b/src/Core/Grand.Infrastructure/StartupBase.cs
@@ -17,7 +17,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Wkhtmltopdf.NetCore;
namespace Grand.Infrastructure
{
@@ -178,9 +177,6 @@ namespace Grand.Infrastructure
{
//add accessor to HttpContext
services.AddHttpContextAccessor();
- //add wkhtmltopdf
- services.AddWkhtmltopdf();
-
//add AppConfig configuration parameters
services.StartupConfig<AppConfig>(configuration.GetSection("Application"));
var performanceConfig = services.StartupConfig<PerformanceConfig>(configuration.GetSection("Performance"));
diff --git a/src/Web/Grand.Web.Common/Grand.Web.Common.csproj b/src/Web/Grand.Web.Common/Grand.Web.Common.csproj
index 0b655a376..b4cd9780a 100644
--- a/src/Web/Grand.Web.Common/Grand.Web.Common.csproj
+++ b/src/Web/Grand.Web.Common/Grand.Web.Common.csproj
@@ -22,5 +22,4 @@
<ProjectReference Include="..\..\Core\Grand.Infrastructure\Grand.Infrastructure.csproj" />
<ProjectReference Include="..\..\Core\Grand.SharedKernel\Grand.SharedKernel.csproj" />
</ItemGroup>
-
</Project>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index 34551adc8..9e64cf7ec 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -205,8 +205,6 @@ namespace Grand.Web.Common.Infrastructure
//add view localization
mvcBuilder.AddViewLocalization();
- //add razor runtime compilation
- mvcBuilder.AddRazorRuntimeCompilation();
var securityConfig = new SecurityConfig();
configuration.GetSection("Security").Bind(securityConfig);
diff --git a/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.cs b/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.cs
index 9d24cbe12..9a7dc7a1e 100644
--- a/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.cs
+++ b/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.cs
@@ -46,7 +46,7 @@ namespace Grand.Web.Common.Startup
//add MiniProfiler
application.UseProfiler();
- //MVC endpoint routing
+ //endpoint routing
application.UseGrandEndpoints();
//save log application started
diff --git a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
index 136f469a7..b31b0948b 100644
--- a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
+++ b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
@@ -1,4 +1,5 @@
using FluentValidation;
+using Grand.Business.Core.Interfaces.Common.Pdf;
using Grand.Domain.Data;
using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
@@ -15,6 +16,7 @@ using Grand.Web.Common.Routing;
using Grand.Web.Common.Security.Captcha;
using Grand.Web.Common.TagHelpers;
using Grand.Web.Common.Themes;
+using Grand.Web.Common.ViewRender;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
@@ -141,6 +143,8 @@ namespace Grand.Web.Common.Startup
//request reCAPTCHA service
serviceCollection.AddHttpClient<GoogleReCaptchaValidator>();
+
+ serviceCollection.AddScoped<IViewRenderService, ViewRenderService>();
}
}
diff --git a/src/Business/Grand.Business.Common/Services/Pdf/ViewRenderService.cs b/src/Web/Grand.Web.Common/ViewRender/ViewRenderService.cs
similarity index 98%
rename from src/Business/Grand.Business.Common/Services/Pdf/ViewRenderService.cs
rename to src/Web/Grand.Web.Common/ViewRender/ViewRenderService.cs
index d2b7eed0c..773c80c57 100644
--- a/src/Business/Grand.Business.Common/Services/Pdf/ViewRenderService.cs
+++ b/src/Web/Grand.Web.Common/ViewRender/ViewRenderService.cs
@@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
-namespace Grand.Business.Common.Services.Pdf
+namespace Grand.Web.Common.ViewRender
{
/// <summary>
/// Allow to get Rezor page content as string
diff --git a/src/Web/Grand.Web/Grand.Web.csproj b/src/Web/Grand.Web/Grand.Web.csproj
index 12b224178..f3d66d0d9 100644
--- a/src/Web/Grand.Web/Grand.Web.csproj
+++ b/src/Web/Grand.Web/Grand.Web.csproj
@@ -60,16 +60,5 @@
<Content Update="Plugins\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
- </ItemGroup>
- <ItemGroup>
- <None Update="Rotativa\Linux\wkhtmltopdf">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Update="Rotativa\Mac\wkhtmltopdf">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Update="Rotativa\Windows\wkhtmltopdf.exe">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- </ItemGroup>
+ </ItemGroup>
</Project>
diff --git a/src/Web/Grand.Web/Rotativa/Linux/wkhtmltopdf b/src/Web/Grand.Web/Rotativa/Linux/wkhtmltopdf
deleted file mode 100644
index dd7525fa7..000000000
Binary files a/src/Web/Grand.Web/Rotativa/Linux/wkhtmltopdf and /dev/null differ
diff --git a/src/Web/Grand.Web/Rotativa/Mac/wkhtmltopdf b/src/Web/Grand.Web/Rotativa/Mac/wkhtmltopdf
deleted file mode 100644
index b9698e55b..000000000
Binary files a/src/Web/Grand.Web/Rotativa/Mac/wkhtmltopdf and /dev/null differ
diff --git a/src/Web/Grand.Web/Rotativa/Windows/wkhtmltopdf.exe b/src/Web/Grand.Web/Rotativa/Windows/wkhtmltopdf.exe
deleted file mode 100644
index 0e23ed278..000000000
Binary files a/src/Web/Grand.Web/Rotativa/Windows/wkhtmltopdf.exe and /dev/null differ
diff --git a/src/Web/Grand.Web/Views/PdfTemplates/OrderPdfTemplate.cshtml b/src/Web/Grand.Web/Views/PdfTemplates/OrderPdfTemplate.cshtml
index 7b6c7e8e8..d121d76d8 100644
--- a/src/Web/Grand.Web/Views/PdfTemplates/OrderPdfTemplate.cshtml
+++ b/src/Web/Grand.Web/Views/PdfTemplates/OrderPdfTemplate.cshtml
@@ -14,143 +14,99 @@
var logoExists = logoPicture != null;
var limitbyVendor = !string.IsNullOrEmpty(Model.Item2);
}
-<style>
- html {
- font-size: 18px;
- }
-
- .column {
- display: flex;
- flex-direction: column;
- flex-basis: 100%;
- flex: 1;
- }
-
- .col-container {
- display: table;
- width: 100%;
- margin-top: 15px;
- }
-
- .col-container .column {
- display: table-cell;
- }
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title></title>
+ <style>
- .col-container .right.column img {
- margin-top: 25px;
+ .orderItems {
+ width: 100%;
+ border: 1px solid black;
}
- ul {
- list-style: none;
- padding: 0;
- margin: 0;
- }
-
- .addresses .billing {
- width: 50%;
- float: left;
- }
-
- .addresses .shipping {
- width: 50%;
- float: right;
- }
+ .orderItems tr th {
+ background-color: #f5f5f5;
+ text-align: left;
+ padding: 0 5px 0 5px;
+ }
- .orderItems {
- width: 100%;
- border: 1px solid black;
- }
+ .orderItems tr,
+ .orderItems tr td,
+ .orderItems tr th {
+ border: 1px solid black;
+ padding: 0 5px 0 5px;
+ }
- .orderItems tr th {
- background-color: #f5f5f5;
- text-align: left;
- padding: 0 5px 0 5px;
+ .summary {
+ margin-top: 20px;
}
- .orderItems tr,
- .orderItems tr td,
- .orderItems tr th {
- border: 1px solid black;
- padding: 0 5px 0 5px;
+ .footer {
+ position: fixed;
+ bottom: 0;
+ width: 100%;
}
-
- .summary {
- margin-top: 20px;
- }
-
- .right {
- float: right;
- }
-
- .footer {
- position: absolute;
- bottom: 0;
- width: 100%;
- }
-</style>
-
-
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title></title>
+ </style>
</head>
<body>
- @{ var i = 0; }
+ @{
+ var i = 0;
+ }
@foreach (var order in Model.Item1)
{
var store = await _storeService.GetStoreById(order.StoreId);
-
+ var url = logoExists ? await _pictureService.GetPictureUrl(logoPicture, 0, false, store.Url) : "";
if (!string.IsNullOrEmpty(_pdfSettings.InvoiceHeaderText))
{
<div>@_pdfSettings.InvoiceHeaderText</div>
}
- <div class="col-container">
- <div class="left column"><h2>@store.CompanyName</h2></div>
- <div class="right column"><img src="@(logoExists ? await _pictureService.GetPictureUrl(logoPicture, 0, false, store.Url) : "" )" /></div>
- </div>
- <h2>@(string.Format(_translationService.GetResource("PDFInvoice.Order#", order.CustomerLanguageId), order.OrderNumber))</h2>
- <div class="addresses">
- @if (order.BillingAddress != null)
- {
- <div class="billing column">
- <h3>@(_translationService.GetResource("PDFInvoice.BillingInformation", order.CustomerLanguageId))</h3>
- <ul>
- @if (!string.IsNullOrEmpty(order.BillingAddress.Company))
- {
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Company", order.CustomerLanguageId), order.BillingAddress.Company))</li>
- }
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Name", order.CustomerLanguageId), order.BillingAddress.FirstName + " " + order.BillingAddress.LastName))</li>
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Phone", order.CustomerLanguageId), order.BillingAddress.PhoneNumber))</li>
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Address", order.CustomerLanguageId), order.BillingAddress.Address1))</li>
- <li>@(order.BillingAddress.City + ", " + order.BillingAddress.ZipPostalCode)</li>
- <li>@((await _countryService.GetCountryById(order.BillingAddress.CountryId))?.Name)</li>
- @{
- var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName);
- string paymentMethodStr = paymentMethod != null ? paymentMethod.FriendlyName : order.PaymentMethodSystemName;
- }
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.PaymentMethod", order.CustomerLanguageId), paymentMethodStr))</li>
- </ul>
- </div>
- }
- @if (order.ShippingAddress != null)
- {
- <div class="shipping column">
- <h3>@(_translationService.GetResource("PDFInvoice.ShippingInformation", order.CustomerLanguageId))</h3>
- <ul>
- @if (!string.IsNullOrEmpty(order.ShippingAddress.Company))
- {
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Company", order.CustomerLanguageId), order.ShippingAddress.Company))</li>
- }
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Name", order.CustomerLanguageId), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName))</li>
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Phone", order.CustomerLanguageId), order.ShippingAddress.PhoneNumber))</li>
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.Address", order.CustomerLanguageId), order.ShippingAddress.Address1))</li>
- <li>@(order.ShippingAddress.City + ", " + order.ShippingAddress.ZipPostalCode)</li>
- <li>@((await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.Name)</li>
- <li>@(string.Format(_translationService.GetResource("PDFInvoice.ShippingMethod", order.CustomerLanguageId), order.ShippingMethod))</li>
- </ul>
- </div>
- }
- </div>
+ <h2>@store.CompanyName</h2>
+ <div><img src="@(logoExists ? url:"")" alt="logo" title="logo" /></div>
+ <h3>@(string.Format(_translationService.GetResource("PDFInvoice.Order#", order.CustomerLanguageId), order.OrderNumber))</h3>
+ <table>
+ <tr>
+ <td style="border-style: none; width:50%;">
+ @if (order.BillingAddress != null)
+ {
+ <ul style="list-style-type:none">
+ <li><b>@(_translationService.GetResource("PDFInvoice.BillingInformation", order.CustomerLanguageId))</b></li>
+ @if (!string.IsNullOrEmpty(order.BillingAddress.Company))
+ {
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Company", order.CustomerLanguageId), order.BillingAddress.Company))</li>
+ }
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Name", order.CustomerLanguageId), order.BillingAddress.FirstName + " " + order.BillingAddress.LastName))</li>
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Phone", order.CustomerLanguageId), order.BillingAddress.PhoneNumber))</li>
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Address", order.CustomerLanguageId), order.BillingAddress.Address1))</li>
+ <li>@(order.BillingAddress.City + ", " + order.BillingAddress.ZipPostalCode)</li>
+ <li>@((await _countryService.GetCountryById(order.BillingAddress.CountryId))?.Name)</li>
+ @{
+ var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName);
+ string paymentMethodStr = paymentMethod != null ? paymentMethod.FriendlyName : order.PaymentMethodSystemName;
+ }
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.PaymentMethod", order.CustomerLanguageId), paymentMethodStr))</li>
+ </ul>
+ }
+ </td>
+ <td style="border-style: none; width:50%;">
+ @if (order.ShippingAddress != null)
+ {
+ <ul style="list-style-type:none">
+ <li><b>@(_translationService.GetResource("PDFInvoice.ShippingInformation", order.CustomerLanguageId))</b></li>
+ @if (!string.IsNullOrEmpty(order.ShippingAddress.Company))
+ {
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Company", order.CustomerLanguageId), order.ShippingAddress.Company))</li>
+ }
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Name", order.CustomerLanguageId), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName))</li>
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Phone", order.CustomerLanguageId), order.ShippingAddress.PhoneNumber))</li>
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.Address", order.CustomerLanguageId), order.ShippingAddress.Address1))</li>
+ <li>@(order.ShippingAddress.City + ", " + order.ShippingAddress.ZipPostalCode)</li>
+ <li>@((await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.Name)</li>
+ <li>@(string.Format(_translationService.GetResource("PDFInvoice.ShippingMethod", order.CustomerLanguageId), order.ShippingMethod))</li>
+ </ul>
+ }
+ </td>
+ </tr>
+ </table>
<div style="display:block; clear:both;"></div>
<div class="summary">
@@ -163,7 +119,7 @@
<th>@(_translationService.GetResource("PDFInvoice.ProductQuantity", order.CustomerLanguageId))</th>
<th>@(_translationService.GetResource("PDFInvoice.ProductTotal", order.CustomerLanguageId))</th>
</tr>
- @foreach (var item in order.OrderItems.Where(x=> x.VendorId == Model.Item2 || !limitbyVendor).ToList())
+ @foreach (var item in order.OrderItems.Where(x => x.VendorId == Model.Item2 || !limitbyVendor).ToList())
{
<tr>
<td>
@@ -185,7 +141,7 @@
<div class="summary">
<hr />
<div class="right">
- <ul>
+ <ul style="list-style-type:none">
<li>@(_translationService.GetResource("PDFInvoice.Sub-Total", order.CustomerLanguageId)) @order.OrderSubtotalInclTax @order.CustomerCurrencyCode</li>
@if (order.OrderSubTotalDiscountInclTax > 0)
{
diff --git a/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml b/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
index fe2904095..fe5a3fa68 100644
--- a/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
+++ b/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
@@ -1,6 +1,6 @@
-@using Grand.Domain.Shipping
+@using Grand.Domain.Shipping
@model IList<Shipment>
-@inject Grand.Business.Core.Interfaces.Checkout.Orders.IOrderService _orderService
+@inject Grand.Business.Core.Interfaces.Checkout.Orders.IOrderService _orderService
@inject Grand.Business.Core.Interfaces.Checkout.Shipping.IShipmentService _shipmentService
@inject Grand.Business.Core.Interfaces.Common.Directory.ICountryService _cournyService
@inject Grand.Business.Core.Interfaces.Catalog.Products.IProductService _productService
@@ -16,157 +16,109 @@
@inject Grand.Business.Core.Interfaces.Checkout.GiftVouchers.IGiftVoucherService _giftVoucherService
@{
- var logoPicture = await _pictureService.GetPictureById(_pdfSettings.LogoPictureId);
- var logoExists = logoPicture != null;
var companyName = _workContext.CurrentStore.CompanyName;
var limitbyVendor = _workContext.CurrentVendor != null;
}
-<style>
- html {
- font-size: 18px;
- }
- .column {
- display: flex;
- flex-direction: column;
- flex-basis: 100%;
- flex: 1;
- }
- .col-container {
- display: table;
- width: 100%;
- margin-top: 15px;
- }
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title></title>
+ <style>
- .col-container .column {
- display: table-cell;
- }
- .col-container .right.column {
- margin-top: 15px;
+ .orderItems {
+ width: 100%;
+ border: 1px solid black;
}
- ul {
- list-style: none;
- padding: 0;
- margin: 0;
- }
-
- .addresses .shipping {
- width: 50%;
- float: left;
- }
-
- .addresses .logo {
- width: 50%;
- float: right;
- text-align: right;
- }
+ .orderItems tr th {
+ background-color: #f5f5f5;
+ text-align: left;
+ padding: 0 5px 0 5px;
+ }
- .orderItems {
- width: 100%;
- border: 1px solid black;
- }
+ .orderItems tr,
+ .orderItems tr td,
+ .orderItems tr th {
+ border: 1px solid black;
+ padding: 0 5px 0 5px;
+ }
- .orderItems tr th {
- background-color: #f5f5f5;
- text-align: left;
- padding: 0 5px 0 5px;
+ .summary {
+ margin-top: 20px;
}
- .orderItems tr,
- .orderItems tr td,
- .orderItems tr th {
- border: 1px solid black;
- padding: 0 5px 0 5px;
+ .right {
+ float: right;
}
-
- .summary {
- margin-top: 20px;
- }
-
- .right {
- float: right;
- }
-</style>
-
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title></title>
+ </style>
</head>
<body>
@for (int i = 0; i < Model.Count; i++)
{
var order = await _orderService.GetOrderById(Model[i].OrderId);
var shipment = Model[i];
- <div class="col-container">
- <div class="left column">
- <h2>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Shipment", order.CustomerLanguageId), shipment.ShipmentNumber))</h2>
- </div>
- <div class="right column"><h2>@companyName</h2></div>
+ <div>
+ <h2>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Shipment", order.CustomerLanguageId), shipment.ShipmentNumber))</h2>
+ <div>@companyName</div>
+ </div>
+ @if (order.ShippingAddress != null)
+ {
+ <div>
+ <h3>@(_translationService.GetResource("PDFInvoice.ShippingInformation", order.CustomerLanguageId))</h3>
+ <ul style="list-style-type:none">
+ @if (!string.IsNullOrEmpty(order.ShippingAddress.Company))
+ {
+ <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Company", order.CustomerLanguageId), order.ShippingAddress.Company))</li>
+ }
+ <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Name", order.CustomerLanguageId), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName))</li>
+ <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Phone", order.CustomerLanguageId), order.ShippingAddress.PhoneNumber))</li>
+ <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Address", order.CustomerLanguageId), order.ShippingAddress.Address1))</li>
+ <li>@(order.ShippingAddress.City + ", " + order.ShippingAddress.ZipPostalCode)</li>
+ <li>@((await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.Name)</li>
+ </ul>
</div>
-
-
- @if (order.ShippingAddress != null)
+ }
+ <div style="display:block; clear:both;"></div>
+ <h5>@(string.Format(_translationService.GetResource("PDFPackagingSlip.ShippingMethod", order.CustomerLanguageId), order.ShippingMethod))</h5>
+ <div class="summary">
+ <h3>@(_translationService.GetResource("PDFInvoice.Product(s)", order.CustomerLanguageId))</h3>
+ </div>
+ <table class="orderItems">
+ <tr>
+ <th>@(_translationService.GetResource("PDFPackagingSlip.ProductName", order.CustomerLanguageId))</th>
+ <th>@(_translationService.GetResource("PDFPackagingSlip.SKU", order.CustomerLanguageId))</th>
+ <th>@(_translationService.GetResource("PDFPackagingSlip.QTY", order.CustomerLanguageId))</th>
+ </tr>
+ @foreach (var item in shipment.ShipmentItems)
{
- <div class="addresses">
- <div class="shipping column">
- <h3>@(_translationService.GetResource("PDFInvoice.ShippingInformation", order.CustomerLanguageId))</h3>
- <ul>
- @if (!string.IsNullOrEmpty(order.ShippingAddress.Company))
+ var orderItem = order.OrderItems.Where(x => x.Id == item.OrderItemId).FirstOrDefault();
+ if (orderItem != null && (orderItem.VendorId == _workContext.CurrentVendor?.Id || !limitbyVendor))
+ {
+ <tr>
+ <td>
+ @((await _productService.GetProductByIdIncludeArch(item.ProductId)).Name)
+ @if (!string.IsNullOrEmpty(orderItem.AttributeDescription))
{
- <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Company", order.CustomerLanguageId), order.ShippingAddress.Company))</li>
+ <br />
+ <small>@(Html.Raw(orderItem.AttributeDescription))</small>
}
- <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Name", order.CustomerLanguageId), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName))</li>
- <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Phone", order.CustomerLanguageId), order.ShippingAddress.PhoneNumber))</li>
- <li>@(string.Format(_translationService.GetResource("PDFPackagingSlip.Address", order.CustomerLanguageId), order.ShippingAddress.Address1))</li>
- <li>@(order.ShippingAddress.City + ", " + order.ShippingAddress.ZipPostalCode)</li>
- <li>@((await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.Name)</li>
- </ul>
- </div>
- <div class="logo column"><img src="@(logoExists ? await _pictureService.GetThumbPhysicalPath(logoPicture, 0, false) : "" )" /></div>
- </div>
- }
- <div style="display:block; clear:both;"></div>
- <h5>@(string.Format(_translationService.GetResource("PDFPackagingSlip.ShippingMethod", order.CustomerLanguageId), order.ShippingMethod))</h5>
- <div class="summary">
- <h3>@(_translationService.GetResource("PDFInvoice.Product(s)", order.CustomerLanguageId))</h3>
- </div>
- <table class="orderItems">
- <tr>
- <th>@(_translationService.GetResource("PDFPackagingSlip.ProductName", order.CustomerLanguageId))</th>
- <th>@(_translationService.GetResource("PDFPackagingSlip.SKU", order.CustomerLanguageId))</th>
- <th>@(_translationService.GetResource("PDFPackagingSlip.QTY", order.CustomerLanguageId))</th>
- </tr>
- @foreach (var item in shipment.ShipmentItems)
- {
- var orderItem = order.OrderItems.Where(x => x.Id == item.OrderItemId).FirstOrDefault();
- if (orderItem != null && (orderItem.VendorId == _workContext.CurrentVendor?.Id || !limitbyVendor))
- {
- <tr>
- <td>
- @((await _productService.GetProductByIdIncludeArch(item.ProductId)).Name)
- @if (!string.IsNullOrEmpty(orderItem.AttributeDescription))
- {
- <br />
- <small>@(Html.Raw(orderItem.AttributeDescription))</small>
- }
- </td>
+ </td>
- <td>@((await _productService.GetProductByIdIncludeArch(item.ProductId)).Sku)</td>
- <td>@item.Quantity</td>
- </tr>
- }
+ <td>@((await _productService.GetProductByIdIncludeArch(item.ProductId)).Sku)</td>
+ <td>@item.Quantity</td>
+ </tr>
}
- </table>
+ }
+ </table>
- if (Model.Count - 1 > i)
- {
+ if (Model.Count - 1 > i)
+ {
- <div style="display:block; clear:both; page-break-after:always;"></div>
- }
+ <div style="display:block; clear:both; page-break-after:always;"></div>
+ }
}
</body>
</html>
\ No newline at end of file
diff --git a/src/Web/Grand.Web/wwwroot/assets/pdf/pagination.html b/src/Web/Grand.Web/wwwroot/assets/pdf/pagination.html
deleted file mode 100644
index 2ee310c58..000000000
--- a/src/Web/Grand.Web/wwwroot/assets/pdf/pagination.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<!doctype html>
-<html>
-<head>
- <meta charset="utf-8">
- <script>
- function pagination()
- {
- var vars = {};
- var x = document.location.search.substring(1).split('&');
-
- for (var i in x)
- {
- var z = x[i].split('=', 2);
- vars[z[0]] = unescape(z[1]);
- }
-
- var x = ['frompage','topage','page','webpage','section','subsection','subsubsection'];
-
- for (var i in x)
- {
- var y = document.getElementsByClassName(x[i]);
-
- for (var j = 0; j < y.length; ++j)
- {
- y[j].textContent = vars[x[i]];
- }
- }
- }
- </script>
-</head>
-
-<body id="pdf-footer" onload="pagination()">
- <span class="copyright">
- © Copyright Grandnode. All rights reserved.
- </span>
- <span class="page" style="float:right"></span>
-</body>
-</html>
\ No newline at end of file