Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Inconsistent Behavior between windows and linux. #40

Open
Amatsugu opened this issue Sep 30, 2020 · 5 comments
Open

Inconsistent Behavior between windows and linux. #40

Amatsugu opened this issue Sep 30, 2020 · 5 comments

Comments

@Amatsugu
Copy link

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?

@gurustron
Copy link
Contributor

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
});

@Amatsugu
Copy link
Author

Amatsugu commented Oct 2, 2020

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

@Amatsugu
Copy link
Author

Amatsugu commented Oct 2, 2020

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: $@Model.GeneralPrice</center>
			@if (!string.IsNullOrWhiteSpace(Model.MSRP))
			{
				<center>MSRP: $@Model.MSRP</center>
			}
		</div>
	</div>
</body>
</html>

@gurustron
Copy link
Contributor

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

@Amatsugu
Copy link
Author

Amatsugu commented Oct 2, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants