Unimake.Wkhtmltopdf 20221005.1536.42

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Unimake.Wkhtmltopdf --version 20221005.1536.42
NuGet\Install-Package Unimake.Wkhtmltopdf -Version 20221005.1536.42
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="Unimake.Wkhtmltopdf" Version="20221005.1536.42" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Unimake.Wkhtmltopdf --version 20221005.1536.42
#r "nuget: Unimake.Wkhtmltopdf, 20221005.1536.42"
#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 Unimake.Wkhtmltopdf as a Cake Addin
#addin nuget:?package=Unimake.Wkhtmltopdf&version=20221005.1536.42

// Install Unimake.Wkhtmltopdf as a Cake Tool
#tool nuget:?package=Unimake.Wkhtmltopdf&version=20221005.1536.42

Unimake.Wkhtmltopdf

Este projeto implementa uma versão mais simplificada da biblioteca https://github.com/fpanaccia/Wkhtmltopdf.NetCore para converter html em pdf, apenas para windows.<br/> Obrigado fpanaccia por compartilhar a versão completa para .NET<br/> Utiliza o projeto https://wkhtmltopdf.org/ para a conversão.

Como utilizar

Instale o pacote https://www.nuget.org/packages/Unimake.Wkhtmltopdf

Os arquivos da biblioteca Wkhtmltopdf devem estar disponibilizados no seu projeto na seguinte estrutura

    ├── Example.sln
    |   ├── Example.csproj
    |   ├──── Wkhtmltox
    |   |     ├── win-x64 <<-- Este diretório é obrigatório
    |   |     |   ├── wkhtmltopdf.exe
    |   |     |   └── wkhtmltox.dll

Para baixar as versões utilizadas na biblioteca, baixe em:<br/> wkhtmltopdf.exe <br/> wkhtmltox.dll

Para baixar versões mais atuais: https://wkhtmltopdf.org/downloads.html

Estes arquivos devem ser incluídos na sua solução e marcados como "Copy Always" para serem copiados para o diretório de build.<br/> Se publicados em um servidor web, os mesmos deverão ser enviados juntamente com o pacote de distribuição. <br/> O diretório "win-x64" é obrigatório

Esta estrutrura de arquivos, é a estrutrua padrão desta biblioteca, caso queira mudar, passe a configuração através das opções definidas em ConvertOptions.WkhtmltoxPath

Exemplo de código com biblioteca e diretórios alterados

var html = "<p>This is a paragraph.</p>";
var options = new ConvertOptions
{
	WkhtmltoxPath = "libs\\MyLibFolder"
};

var bytes = new HtmlToPdfConverter(options).GetPDFAsByteArray(html);
Assert.NotNull(bytes);

Recuperando um array de bytes e salvando em um arquivo .pdf

[Fact]
public void GetPDFAsByteArray()
{
	var html = "<p>This is a paragraph.</p>";
	var bytes = new HtmlToPdfConverter().GetPDFAsByteArray(html);
	Assert.NotNull(bytes);

	var fi = new FileInfo("test.pdf");

	if(fi.Exists)
	{
		fi.Delete();
	}

	File.WriteAllBytes(fi.FullName, bytes);

	//Open pdf file
	_ = Process.Start(new ProcessStartInfo
	{
		UseShellExecute = true,
		FileName = fi.FullName
	});
}

Recuperando uma string padrão Base64

[Fact]
public void GetPDFAsBase64()
{
	var html = "<p>This is a paragraph.</p>";
	var pdf = new HtmlToPdfConverter().GetPDFAsBase64(html);
	Assert.NotNull(pdf);

	//save to file
	var bytes = Convert.FromBase64String(pdf);
	Assert.NotNull(bytes);

	var fi = new FileInfo("test.pdf");

	if(fi.Exists)
	{
		fi.Delete();
	}

	File.WriteAllBytes(fi.FullName, bytes);

	//Open pdf file
	_ = Process.Start(new ProcessStartInfo
	{
		UseShellExecute = true,
		FileName = fi.FullName
	});
}

Veja outros exemplos de uso em Unimake.Wkhtmltopdf.Test

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
20231005.144.37 268 10/5/2023
20221005.1536.42 368 10/5/2022