Documents/Pdf: allow double-sided pages to be printed

This commit is contained in:
2023-10-23 22:25:32 +02:00
parent d5102c9cd7
commit 8792404e0d
6 changed files with 48 additions and 14 deletions

View File

@ -9,6 +9,16 @@
<meta charset="UTF-8"/>
<link rel="stylesheet" href="file:///@Raw(Model.DataPath)\resources\style.css"/>
<link rel="stylesheet" href="file:///@Raw(Model.DataPath)\resources\style-page.css"/>
@if (Model.DoubleSided) {
<style>
@@page :left {
margin: 25mm 25mm 35mm 20mm;
@@bottom-center {
content: element(page-footer-left);
}
}
</style>
}
</head>
<body>
@if (Model.ShowFoldMarks) {
@ -27,6 +37,16 @@
</div>
<footer>@Raw(Model.Footer)</footer>
</div>
@if (Model.DoubleSided) {
<div class="footer-wrapper left">
<div class="pre-footer">
<span class="page"></span>
<span class="doc-id">@Model.DocumentId</span>
<span class="date">@($"{Model.Date:dddd, d. MMMM yyyy}")</span>
</div>
<footer>@Raw(Model.Footer)</footer>
</div>
}
<header>@Raw(Model.Header)</header>
<div class="spacing"></div>
<div class="main-wrapper">

View File

@ -11,6 +11,7 @@ namespace Elwig.Documents {
private TempFile? _pdfFile = null;
public bool ShowFoldMarks = App.Config.Debug;
public bool DoubleSided = false;
public string DataPath;
public int CurrentNextSeason;
@ -90,7 +91,7 @@ namespace Elwig.Documents {
progress?.Report(50.0 * i / n);
}
progress?.Report(50.0);
await Pdf.Convert(tmpHtmls.Select(f => f.FileName), pdf.FileName, new Progress<double>(v => progress?.Report(50.0 + v / 2)));
await Pdf.Convert(tmpHtmls.Select(f => f.FileName), pdf.FileName, DoubleSided, new Progress<double>(v => progress?.Report(50.0 + v / 2)));
foreach (var tmp in tmpHtmls) {
tmp.Dispose();
}
@ -100,7 +101,7 @@ namespace Elwig.Documents {
using (var tmpHtml = new TempFile("html")) {
await File.WriteAllTextAsync(tmpHtml.FilePath, await Render(), Utils.UTF8);
progress?.Report(50.0);
await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath);
await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath, DoubleSided);
}
_pdfFile = pdf;
}

View File

@ -21,25 +21,30 @@ namespace Elwig.Documents {
public static async Task Init(Action evtHandler) {
var p = new Process() { StartInfo = new() {
FileName = WinziPrint,
Arguments = $"-p -e utf-8 -d \"{App.TempPath}\" -",
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true
} };
p.StartInfo.ArgumentList.Add("-p");
p.StartInfo.ArgumentList.Add("-e");
p.StartInfo.ArgumentList.Add("utf-8");
p.StartInfo.ArgumentList.Add("-d");
p.StartInfo.ArgumentList.Add(App.TempPath);
p.StartInfo.ArgumentList.Add("-");
p.Start();
WinziPrintProc = p;
evtHandler();
}
public static async Task<IEnumerable<int>> Convert(string htmlPath, string pdfPath, IProgress<double>? progress = null) {
return await Convert(new string[] { htmlPath }, pdfPath, progress);
public static async Task<IEnumerable<int>> Convert(string htmlPath, string pdfPath, bool doubleSided = false, IProgress<double>? progress = null) {
return await Convert(new string[] { htmlPath }, pdfPath, doubleSided, progress);
}
public static async Task<IEnumerable<int>> Convert(IEnumerable<string> htmlPath, string pdfPath, IProgress<double>? progress = null) {
public static async Task<IEnumerable<int>> Convert(IEnumerable<string> htmlPath, string pdfPath, bool doubleSided = false, IProgress<double>? progress = null) {
if (WinziPrintProc == null) throw new InvalidOperationException("The WinziPrint process has not been initialized yet");
progress?.Report(0.0);
await WinziPrintProc.StandardInput.WriteLineAsync($"{string.Join(';', htmlPath)};{pdfPath}");
await WinziPrintProc.StandardInput.WriteLineAsync((doubleSided ? "-2;" : "") + $"{string.Join(';', htmlPath)};{pdfPath}");
while (true) {
var line = await WinziPrintProc.StandardOutput.ReadLineAsync() ?? throw new IOException("Invalid response from WinziPrint");
if (line.StartsWith("error:")) {

View File

@ -20,9 +20,6 @@
hr.page-break {
display: none;
}
.document-break {
break-before: page;
}
@page {
size: A4;

View File

@ -57,6 +57,12 @@ header .type {
.footer-wrapper {
position: running(page-footer);
width: 165mm;
/* for some reason the position without the following statement changes on the second page */
border: 0.5pt solid #00000000;
}
.footer-wrapper.left {
position: running(page-footer-left);
}
.pre-footer {
@ -69,16 +75,16 @@ header .type {
width: 33%;
}
.pre-footer .date {
.pre-footer > *:first-child {
text-align: left;
}
.pre-footer .doc-id {
.pre-footer > *:nth-child(2) {
text-align: center;
font-style: italic;
}
.pre-footer .page {
.pre-footer > *:last-child {
text-align: right;
float: right;
}

View File

@ -95,7 +95,12 @@ namespace Elwig.Dialogs {
""")
.ToListAsync();
using var doc = Document.Merge(list.Select(m => new DeliveryConfirmation(Context, Year, m, deliveries.Where(d => d.Delivery.MgNr == m.MgNr).ToList()))); ;
using var doc = Document.Merge(list.Select(m =>
new DeliveryConfirmation(Context, Year, m, deliveries.Where(d => d.Delivery.MgNr == m.MgNr).ToList()) {
DoubleSided = true
}
));
doc.DoubleSided = true;
await doc.Generate(new Progress<double>(v => {
ProgressBar.Value = v;
}));