Documents/Pdf: allow double-sided pages to be printed
This commit is contained in:
@ -9,6 +9,16 @@
|
|||||||
<meta charset="UTF-8"/>
|
<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.css"/>
|
||||||
<link rel="stylesheet" href="file:///@Raw(Model.DataPath)\resources\style-page.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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@if (Model.ShowFoldMarks) {
|
@if (Model.ShowFoldMarks) {
|
||||||
@ -27,6 +37,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<footer>@Raw(Model.Footer)</footer>
|
<footer>@Raw(Model.Footer)</footer>
|
||||||
</div>
|
</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>
|
<header>@Raw(Model.Header)</header>
|
||||||
<div class="spacing"></div>
|
<div class="spacing"></div>
|
||||||
<div class="main-wrapper">
|
<div class="main-wrapper">
|
||||||
|
@ -11,6 +11,7 @@ namespace Elwig.Documents {
|
|||||||
private TempFile? _pdfFile = null;
|
private TempFile? _pdfFile = null;
|
||||||
|
|
||||||
public bool ShowFoldMarks = App.Config.Debug;
|
public bool ShowFoldMarks = App.Config.Debug;
|
||||||
|
public bool DoubleSided = false;
|
||||||
|
|
||||||
public string DataPath;
|
public string DataPath;
|
||||||
public int CurrentNextSeason;
|
public int CurrentNextSeason;
|
||||||
@ -90,7 +91,7 @@ namespace Elwig.Documents {
|
|||||||
progress?.Report(50.0 * i / n);
|
progress?.Report(50.0 * i / n);
|
||||||
}
|
}
|
||||||
progress?.Report(50.0);
|
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) {
|
foreach (var tmp in tmpHtmls) {
|
||||||
tmp.Dispose();
|
tmp.Dispose();
|
||||||
}
|
}
|
||||||
@ -100,7 +101,7 @@ namespace Elwig.Documents {
|
|||||||
using (var tmpHtml = new TempFile("html")) {
|
using (var tmpHtml = new TempFile("html")) {
|
||||||
await File.WriteAllTextAsync(tmpHtml.FilePath, await Render(), Utils.UTF8);
|
await File.WriteAllTextAsync(tmpHtml.FilePath, await Render(), Utils.UTF8);
|
||||||
progress?.Report(50.0);
|
progress?.Report(50.0);
|
||||||
await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath);
|
await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath, DoubleSided);
|
||||||
}
|
}
|
||||||
_pdfFile = pdf;
|
_pdfFile = pdf;
|
||||||
}
|
}
|
||||||
|
@ -21,25 +21,30 @@ namespace Elwig.Documents {
|
|||||||
public static async Task Init(Action evtHandler) {
|
public static async Task Init(Action evtHandler) {
|
||||||
var p = new Process() { StartInfo = new() {
|
var p = new Process() { StartInfo = new() {
|
||||||
FileName = WinziPrint,
|
FileName = WinziPrint,
|
||||||
Arguments = $"-p -e utf-8 -d \"{App.TempPath}\" -",
|
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardInput = true,
|
RedirectStandardInput = true,
|
||||||
RedirectStandardOutput = 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();
|
p.Start();
|
||||||
WinziPrintProc = p;
|
WinziPrintProc = p;
|
||||||
evtHandler();
|
evtHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<IEnumerable<int>> Convert(string htmlPath, string pdfPath, IProgress<double>? progress = null) {
|
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, progress);
|
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");
|
if (WinziPrintProc == null) throw new InvalidOperationException("The WinziPrint process has not been initialized yet");
|
||||||
progress?.Report(0.0);
|
progress?.Report(0.0);
|
||||||
await WinziPrintProc.StandardInput.WriteLineAsync($"{string.Join(';', htmlPath)};{pdfPath}");
|
await WinziPrintProc.StandardInput.WriteLineAsync((doubleSided ? "-2;" : "") + $"{string.Join(';', htmlPath)};{pdfPath}");
|
||||||
while (true) {
|
while (true) {
|
||||||
var line = await WinziPrintProc.StandardOutput.ReadLineAsync() ?? throw new IOException("Invalid response from WinziPrint");
|
var line = await WinziPrintProc.StandardOutput.ReadLineAsync() ?? throw new IOException("Invalid response from WinziPrint");
|
||||||
if (line.StartsWith("error:")) {
|
if (line.StartsWith("error:")) {
|
||||||
|
@ -20,9 +20,6 @@
|
|||||||
hr.page-break {
|
hr.page-break {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.document-break {
|
|
||||||
break-before: page;
|
|
||||||
}
|
|
||||||
|
|
||||||
@page {
|
@page {
|
||||||
size: A4;
|
size: A4;
|
||||||
|
@ -57,6 +57,12 @@ header .type {
|
|||||||
.footer-wrapper {
|
.footer-wrapper {
|
||||||
position: running(page-footer);
|
position: running(page-footer);
|
||||||
width: 165mm;
|
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 {
|
.pre-footer {
|
||||||
@ -69,16 +75,16 @@ header .type {
|
|||||||
width: 33%;
|
width: 33%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pre-footer .date {
|
.pre-footer > *:first-child {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pre-footer .doc-id {
|
.pre-footer > *:nth-child(2) {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pre-footer .page {
|
.pre-footer > *:last-child {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,12 @@ namespace Elwig.Dialogs {
|
|||||||
""")
|
""")
|
||||||
.ToListAsync();
|
.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 => {
|
await doc.Generate(new Progress<double>(v => {
|
||||||
ProgressBar.Value = v;
|
ProgressBar.Value = v;
|
||||||
}));
|
}));
|
||||||
|
Reference in New Issue
Block a user