Skip to content

Commit 90b8b7b

Browse files
authored
Add tagged (accessible) PDFs option (#2347)
* Add tagged (accessible) PDFs option * Navigate to page and bump browser
1 parent 41e8c2a commit 90b8b7b

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>PDF</title>
7+
</head>
8+
<body>
9+
<div>PDF Content</div>
10+
</body>
11+
</html>

lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,40 @@ public async Task CanPrintToPDFAndStreamTheResult()
7272
fileInfo.Delete();
7373
}
7474
await Page.PdfAsync(outputFile);
75-
75+
7676
var stream = await Page.PdfStreamAsync();
7777

7878
// Firefox in Linux might generate and of by one result here.
7979
// If the difference is less than 2 bytes is good
8080
Assert.True(Math.Abs(new FileInfo(outputFile).Length - stream.Length) < 2);
8181
}
8282

83+
[PuppeteerTest("page.spec.ts", "printing to PDF", "can print to PDF with accessible")]
84+
[Skip(SkipAttribute.Targets.Firefox)]
85+
public async Task CanPrintToPdfWithAccessible()
86+
{
87+
// We test this differently compared to puppeteer.
88+
// We will compare that we can get to the same file using both PDF methods
89+
var outputFile = Path.Combine(BaseDirectory, "output.pdf");
90+
var fileInfo = new FileInfo(outputFile);
91+
if (fileInfo.Exists)
92+
{
93+
fileInfo.Delete();
94+
}
95+
96+
var accessibleOutputFile = Path.Combine(BaseDirectory, "output-accessible.pdf");
97+
fileInfo = new FileInfo(accessibleOutputFile);
98+
if (fileInfo.Exists)
99+
{
100+
fileInfo.Delete();
101+
}
102+
await Page.GoToAsync(TestConstants.ServerUrl + "/pdf.html");
103+
await Page.PdfAsync(outputFile);
104+
await Page.PdfAsync(accessibleOutputFile, new PdfOptions { Tagged = true });
105+
106+
Assert.Greater(new FileInfo(accessibleOutputFile).Length, new FileInfo(outputFile).Length);
107+
}
108+
83109
[PuppeteerTimeout]
84110
public void PdfOptionsShouldBeSerializable()
85111
{

lib/PuppeteerSharp/BrowserData/Chrome.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class Chrome
1313
/// <summary>
1414
/// Default chrome build.
1515
/// </summary>
16-
public static string DefaultBuildId => "117.0.5938.149";
16+
public static string DefaultBuildId => "118.0.5993.70";
1717

1818
internal static async Task<string> ResolveBuildIdAsync(ChromeReleaseChannel channel)
1919
=> (await GetLastKnownGoodReleaseForChannel(channel).ConfigureAwait(false)).Version;

lib/PuppeteerSharp/Messaging/PagePrintToPDFRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ internal class PagePrintToPDFRequest
3131
public bool PreferCSSPageSize { get; set; }
3232

3333
public string TransferMode { get; set; }
34+
35+
public bool GenerateTaggedPDF { get; set; }
3436
}
3537
}

lib/PuppeteerSharp/Page.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ internal async Task<byte[]> PdfInternalAsync(string file, PdfOptions options)
11861186
MarginRight = marginRight,
11871187
PageRanges = options.PageRanges,
11881188
PreferCSSPageSize = options.PreferCSSPageSize,
1189+
GenerateTaggedPDF = options.Tagged,
11891190
}).ConfigureAwait(false);
11901191

11911192
if (options.OmitBackground)

lib/PuppeteerSharp/PdfOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public PdfOptions()
9292
/// </summary>
9393
public bool OmitBackground { get; set; }
9494

95+
/// <summary>
96+
/// Generate tagged (accessible) PDF.
97+
/// </summary>
98+
public bool Tagged { get; set; }
99+
95100
/// <summary>Overriding == operator for <see cref="PdfOptions"/>.</summary>
96101
/// <param name="left">the value to compare against <paramref name="right" />.</param>
97102
/// <param name="right">the value to compare against <paramref name="left" />.</param>

0 commit comments

Comments
 (0)