ExcelToPdf 6.0.4

dotnet add package ExcelToPdf --version 6.0.4
NuGet\Install-Package ExcelToPdf -Version 6.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ExcelToPdf" Version="6.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ExcelToPdf --version 6.0.4
#r "nuget: ExcelToPdf, 6.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ExcelToPdf as a Cake Addin
#addin nuget:?package=ExcelToPdf&version=6.0.4

// Install ExcelToPdf as a Cake Tool
#tool nuget:?package=ExcelToPdf&version=6.0.4

ExcelToPdf

中文版 | English

This is a simple project to export Excel to PDF.

It consists of two steps:

  1. Use NpoiExcelHelper. ExcelToHtml method will excel export to HTML
  2. Use Pdfhelper.HtmlToPdf to convert HTML to PDF

Npoi and WkHtmlToPdf did almost all the work, and because of that, please go to these two projects to view the relevant documents, thank them very much

This project also provides a simple encapsulation of customizations, see the customization section of the documentation.

Install

Install-Package ExcelToPdf

Sample

For details, please refer to ExcelToPdfSample project.

Dependency Injection

// in StartUp.cs
services.AddExcelToPdf("temp");

Export

private readonly ILogger<IndexModel> _logger;
private readonly ExcelToPdfService _excelToPdfService;

// inject ExcelToPdfService from controller
public IndexModel(ILogger<IndexModel> logger, ExcelToPdfService excelToPdfService)
{
	_logger = logger;
	_excelToPdfService = excelToPdfService;
}

// export to pdf
public void OnPostSimpleExport()
{
	FileInfo excelFileInfo, htmlFileInfo, pdfFileInfo;
	SetupSample(out excelFileInfo, out htmlFileInfo, out pdfFileInfo);

	// export pdf
	_excelToPdfService.ExportToPdf(excelFileInfo.FullName, pdfFileInfo.FullName);

	this.Message = $"Export Success, Pdf file save to: {pdfFileInfo.FullName}";
}

Custom

Custom excel export to html

With the NpoiExcelHelper.ExcelToHtml method, can use the configOptions parameters to HTML do custom processing for export, specific definition refer to:Npoi ExcelToHtmlConverter

Custom pdf convert

With the ExportToPdf method, can use configGlobalSettings parameter to custom pdf:

// ... other code ...
// export pdf
_excelToPdfService.ExportToPdf(excelFileInfo.FullName, pdfFileInfo.FullName, configPdfGlobalSettings: config =>
{
	config.Orientation = Orientation.Landscape;
	config.ColorMode = ColorMode.Grayscale;
	config.Margins.Left = 150;
	config.Margins.Top = 50;
});
// ... other code ...

GlobalSettings Commonly used attributes:

parameter comment default note
Orientation he orientation of the output document portrait Portrait, Landscape
ColorMode Should the output be printed in color or gray scale color
UseCompression Should we use loss less compression when creating the pdf file. true
DPI What dpi should we use when printing 96
DocumentTitle The title of the PDF document empty
ImageDPI The maximal DPI to use for images in the pdf document 600
imageQuality The jpeg compression factor to use when producing the pdf document 94
PaperSize Size of output paper
PaperWidth The height of the output document
PaperHeight The width of the output document
MarginLeft Size of the left margin
MarginRight Size of the right margin
MarginTop Size of the top margin
MarginBottom Size of the bottom margin

Docker and linux

How-to-use-NPOI-on-Linux

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.4 960 8/16/2023
6.0.3 136 8/8/2023
6.0.2 143 7/27/2023
6.0.1 3,058 1/26/2022
6.0.0 623 1/24/2022