I am working on a Blazor Server project. One of the requirements is to display records on a popup and then print them as a PDF document. If the records are too many to fit on one page, the PDF saves only as a single page. I mean only the couple of records that fit on the first-page display on the PDF. How can I make the PDF display all of the records? Is it due to CSS?
Here is the modal:
C#
@page "/dialogcard/{Order}"
@using IMS.CoreBusiness
@using IMS.UseCases.Interfaces.OrderDetail
@using System.Globalization
@inject IViewOrderDetailsByOrderIdUseCase ViewOrderDetailsByOrderIdUseCase
@inject DialogService DialogService
@inject IJSRuntime JsRuntime
.rz-dialog-wrapper {
left:0;
}
/*.rz-card{
margin-top: -1.9rem !important;
}*/
.rz-dialog-content {
margin-top: -55px;
}
@if (orderDetails != null)
{
Order Date: @Order.OrderDateTime
@{
var detailVendorId = 0;
}
@foreach (var detail in orderDetails)
{
@if (detailVendorId != detail.VendorId)
{
Contact
Company
Vorlance
Responsible
@detail.Order.DoneBy
Vendor
@detail?.Vendor.Name
Delivery Information
Company Name
@switch (detail.Warehouse)
{
case "Shenzhen Warehouse":
@string.Format(new CultureInfo("en-US"), "test")
Address
@string.Format(new CultureInfo("en-US"), "test")
Contact Name
@string.Format(new CultureInfo("en-US"), "test")
Email
@string.Format(new CultureInfo("en-US"), "test")
Phone
@string.Format(new CultureInfo("en-US"), "+1233455")
break;
case "USA Warehouse":
@string.Format(new CultureInfo("en-US"), "Company Name: TRADING LLC")
Address
@string.Format(new CultureInfo("en-US"), "1243445,Coconut Creek, FL, ZIP Code: 33073")
Contact Name
@string.Format(new CultureInfo("en-US"), "Test")
Email
@string.Format(new CultureInfo("en-US"), "[email protected]")
Phone
@string.Format(new CultureInfo("en-US"), "+123242422")
break;
case "Private Shipping":
@string.Format(new CultureInfo("en-US"), "ELEKTRONIK SANAYI VE TICARET LTD. STI.")
Address
@string.Format(new CultureInfo("en-US"), "test")
Contact Name
@string.Format(new CultureInfo("en-US"), "Test")
Email
@string.Format(new CultureInfo("en-US"), "[email protected]")
Phone
@string.Format(new CultureInfo("en-US"), "111122")
break;
}
@* Address
@(detail?.Warehouse)
*@
x.VendorId == detail.VendorId)" TItem="OrderDetail" Class="mt-3" Style="height:190px">
@string.Format(new CultureInfo("tr-TR"), "{0:G}", orderDetails?.Where(x => x.VendorId == detail.VendorId).Sum(o => o.Quantity))
@switch (detail.Currency)
{
case "USD":
@string.Format(new CultureInfo("en-US"), "{0}{1:0.#####}",new CultureInfo("en-US").NumberFormat.CurrencySymbol, detail.BuyUnitPrice)
break;
case "EURO":
@string.Format(new CultureInfo("en-FR"), "{0}{1:0.#####}",new CultureInfo("en-FR").NumberFormat.CurrencySymbol, detail.BuyUnitPrice)
break;
default:
@string.Format(new CultureInfo("tr-TR"), "{0}{1:0.#####}",new CultureInfo("tr-TR").NumberFormat.CurrencySymbol, detail.BuyUnitPrice)
break;
}
@switch (detail.Currency)
{
case "USD":
@string.Format(new CultureInfo("en-US"), "{0}{1:0.#####}",new CultureInfo("en-US").NumberFormat.CurrencySymbol, detail.TotalBuyPrice)
break;
case "EURO":
@string.Format(new CultureInfo("en-FR"), "{0}{1:0.#####}",new CultureInfo("en-FR").NumberFormat.CurrencySymbol, detail.TotalBuyPrice)
break;
default:
@string.Format(new CultureInfo("tr-TR"), "{0}{1:0.#####}",new CultureInfo("tr-TR").NumberFormat.CurrencySymbol, detail.TotalBuyPrice)
break;
}
@switch (detail.Currency)
{
case "USD":
@string.Format(new CultureInfo("en-US"), "{0:N2}", orderDetails?.Where(x => x.VendorId == detail.VendorId).Sum(o => o.TotalBuyPrice))
break;
case "EURO":
@string.Format(new CultureInfo("en-FR"), "{0:N2}", orderDetails?.Where(x => x.VendorId == detail.VendorId).Sum(o => o.TotalBuyPrice))
break;
default:
@string.Format(new CultureInfo("tr-TR"), "{0:N2}", orderDetails?.Where(x => x.VendorId == detail.VendorId).Sum(o => o.TotalBuyPrice))
break;
}
}
detailVendorId = detail.VendorId;
}
}
DialogService.Close(false))" ButtonStyle="ButtonStyle.Secondary" Text="Close" Style="width: 120px" Class="mr-1"/>
@*Print*@
@code {
[Parameter] public ReportViewModel Order { get; set; }
IEnumerable orderDetails;
protected override async Task OnInitializedAsync()
{
orderDetails = await ViewOrderDetailsByOrderIdUseCase.ExecuteAsync(Order.OrderId);
}
private void PrintDocument()
{
JsRuntime.InvokeVoidAsync("print");
}
}Here is the screenshot of the modal:

Here is the print preview:

Here is the related CSS:
CSS
@media print {
body * {
visibility: hidden;
}
#printarea1, #printarea1 *{
visibility: visible;
}
#printarea, #printarea * {
visibility: visible;
}
.rz-tabview-nav li:not(.rz-tabview-selected) {
display: none;
}
#printarea1 {
position: fixed;
left: 0;
top: 170px;
}
#printarea {
position: fixed;
left: 15px;
top: 0;
}
button[type=button], input[type=text] {
display: none;
}
.rz-data-grid {
height: unset!important;
}
}
Vishal JoshiRank #377 · 6.7K reputationPosted Dec 3, 2022, 12:15 PM EST
Hello,
There are several ways to achieve this requirement.
Thank you