Wkhtmltopdf.NetCore-deprecated icon indicating copy to clipboard operation
Wkhtmltopdf.NetCore-deprecated copied to clipboard

Inconsistent Behavior between windows and linux.

Open Amatsugu opened this issue 4 years ago • 5 comments

When generating the pdf on linux it seems to ignore css and images. Left was generated on linux, right was on windows RmtdVMy7S0+7NLyqnWgpKg Convert Options

generate.SetConvertOptions(new ConvertOptions
{
	PageSize = Wkhtmltopdf.NetCore.Options.Size.A7,
	PageOrientation = Wkhtmltopdf.NetCore.Options.Orientation.Landscape,
	PageMargins = new Wkhtmltopdf.NetCore.Options.Margins(0,0,0,0),
	IsLowQuality = false,
});

I'm using the binaries provided in the repo. Is this just a limitation of the linux version or is there a configuration issue?

Amatsugu avatar Sep 30 '20 21:09 Amatsugu

Can you please add your view? Also try adding "--enable-local-file-access" flag like this:

    public class CustomConvertOptions : ConvertOptions
    {
        [OptionFlag("--enable-local-file-access")]
        public bool EnableLocalFileAccess { get; set; }
    }
}
generate.SetConvertOptions(new ConvertOptions
{
	PageSize = Wkhtmltopdf.NetCore.Options.Size.A7,
	PageOrientation = Wkhtmltopdf.NetCore.Options.Orientation.Landscape,
	PageMargins = new Wkhtmltopdf.NetCore.Options.Margins(0,0,0,0),
	IsLowQuality = false,
        EnableLocalFileAccess  = true
});

gurustron avatar Oct 02 '20 13:10 gurustron

the files are not linked locally. They are full absolute URL (https://domain/file.png)

Amatsugu avatar Oct 02 '20 13:10 Amatsugu

Here is the full view. The commented out lines are a workaround using base64 data uri to encode the image/css

@*
	For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@inject Microsoft.Extensions.Configuration.IConfiguration config
@using Flurl;
@{
	Layout = null;
	var hostname = config["SiteInfo:Hostname"];
	string img = $"data:image/jpeg;base64,{ViewData["img64"] as string}";
	string css = $"data:text/css;base64,{ViewData["css64"] as string}";
}
@model ProductModel
<html>
<head>
	<style>

		* {
			box-sizing: border-box;
		}

		html {
			margin: auto;
		}

		body {
			margin: auto;
			font-family: 'Mulish', sans-serif !important;
			text-align: center;
			display: flex;
			justify-content: center;
		}

		.card {
			height: 100%;
			width: 100%;
			display: block;
			padding: 10px;
			display: grid;
			grid-template-columns: 50% 50%;
			grid-template-rows: 10fr 1fr;
			font-size: small;
		}

		h4 {
			margin-bottom: 0;
			padding-bottom: 0;
		}

		.logo {
			height: 100px;
			width: 100px;
			align-self: center;
			margin-left: auto;
			margin-right: auto;
			background-position: center;
			background-repeat: no-repeat;
			background-size: contain;
		}
	</style>
	<base href="@hostname">
	@*<link rel="stylesheet" href="@css" />*@
	<link rel="stylesheet" href="@hostname.AppendPathSegments("css","certStyle.css").ToString()" />
	<link href="https://fonts.googleapis.com/css2?family=Mulish:ital,wght@0,200;0,300;0,400;0,500;0,600;1,400&display=swap" rel="stylesheet">
</head>
<body>
	<div class="card">
		<div class="image">
			@*<img src="@img" height="100" />*@
			<div class="logo" style="background:url(@hostname.AppendPathSegments("i",Model.Thumbnail).ToString())"></div>
		</div>
		<div class="info">
			<h4>@Model.Name</h4>
			<center>Issue Date: @DateTime.Now.ToShortDateString()</center>
			@foreach (var item in Model.GetDescriptionStrings())
			{
				<center>@item</center>
			}
			<center>SKU: @Model.SKU</center>
			<center>Value: [email protected]</center>
			@if (!string.IsNullOrWhiteSpace(Model.MSRP))
			{
				<center>MSRP: [email protected]</center>
			}
		</div>
	</div>
</body>
</html>

Amatsugu avatar Oct 02 '20 15:10 Amatsugu

How is app deployed on Linux? Is it inside docker?

gurustron avatar Oct 02 '20 15:10 gurustron

no, running on the native dotnet runtime, behind nginx. All the assets are publicly accessible on the web

Amatsugu avatar Oct 02 '20 15:10 Amatsugu