Skip to content

Commit 4c47e4e

Browse files
committed
feat: 增加 PaperFormat 等配置项
1 parent af1fb78 commit 4c47e4e

1 file changed

Lines changed: 66 additions & 1 deletion

File tree

src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,75 @@ private static PuppeteerSharp.PdfOptions GetOptions(PdfOptions? options)
9797
{
9898
return options == null ? new PuppeteerSharp.PdfOptions() : new PuppeteerSharp.PdfOptions
9999
{
100-
Landscape = options.Landscape
100+
Landscape = options.Landscape,
101+
PrintBackground = options.PrintBackground,
102+
Format = GetFormat(options.Format),
103+
MarginOptions = GetMarginOptions(options.MarginOptions),
104+
DisplayHeaderFooter = options.DisplayHeaderFooter,
105+
Scale = options.Scale
101106
};
102107
}
103108

109+
private static PuppeteerSharp.Media.MarginOptions? GetMarginOptions(MarginOptions options) => new PuppeteerSharp.Media.MarginOptions
110+
{
111+
Top = options.Top,
112+
Bottom = options.Bottom,
113+
Left = options.Left,
114+
Right = options.Right
115+
};
116+
117+
private static PuppeteerSharp.Media.PaperFormat GetFormat(PaperFormat format)
118+
{
119+
if (format == PaperFormat.A0)
120+
{
121+
return PuppeteerSharp.Media.PaperFormat.A0;
122+
}
123+
else if (format == PaperFormat.A1)
124+
{
125+
return PuppeteerSharp.Media.PaperFormat.A1;
126+
}
127+
else if (format == PaperFormat.A2)
128+
{
129+
return PuppeteerSharp.Media.PaperFormat.A2;
130+
}
131+
else if (format == PaperFormat.A3)
132+
{
133+
return PuppeteerSharp.Media.PaperFormat.A3;
134+
}
135+
else if (format == PaperFormat.A4)
136+
{
137+
return PuppeteerSharp.Media.PaperFormat.A4;
138+
}
139+
else if (format == PaperFormat.A5)
140+
{
141+
return PuppeteerSharp.Media.PaperFormat.A5;
142+
}
143+
else if (format == PaperFormat.A6)
144+
{
145+
return PuppeteerSharp.Media.PaperFormat.A6;
146+
}
147+
else if (format == PaperFormat.Letter)
148+
{
149+
return PuppeteerSharp.Media.PaperFormat.Letter;
150+
}
151+
else if (format == PaperFormat.Legal)
152+
{
153+
return PuppeteerSharp.Media.PaperFormat.Legal;
154+
}
155+
else if (format == PaperFormat.Tabloid)
156+
{
157+
return PuppeteerSharp.Media.PaperFormat.Tabloid;
158+
}
159+
else if (format == PaperFormat.Ledger)
160+
{
161+
return PuppeteerSharp.Media.PaperFormat.Ledger;
162+
}
163+
else
164+
{
165+
return new PuppeteerSharp.Media.PaperFormat(format.Width, format.Height);
166+
}
167+
}
168+
104169
private static async Task AddStyleTagAsync(IPage page, IEnumerable<string>? links = null)
105170
{
106171
var styles = new List<string>();

0 commit comments

Comments
 (0)