feat!: generate accessible PDFs by default (#11778)

This commit is contained in:
Alex Rudenko 2024-02-02 13:17:06 +01:00 committed by GitHub
parent b3bfdd2024
commit 4fc14026e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 3 deletions

View File

@ -30,6 +30,6 @@ export interface PDFOptions
| preferCSSPageSize | <code>optional</code> | boolean | Give any CSS <code>@page</code> size declared in the page priority over what is declared in the <code>width</code> or <code>height</code> or <code>format</code> option. | <code>false</code>, which will scale the content to fit the paper size. | | preferCSSPageSize | <code>optional</code> | boolean | Give any CSS <code>@page</code> size declared in the page priority over what is declared in the <code>width</code> or <code>height</code> or <code>format</code> option. | <code>false</code>, which will scale the content to fit the paper size. |
| printBackground | <code>optional</code> | boolean | Set to <code>true</code> to print background graphics. | <code>false</code> | | printBackground | <code>optional</code> | boolean | Set to <code>true</code> to print background graphics. | <code>false</code> |
| scale | <code>optional</code> | number | Scales the rendering of the web page. Amount must be between <code>0.1</code> and <code>2</code>. | <code>1</code> | | scale | <code>optional</code> | number | Scales the rendering of the web page. Amount must be between <code>0.1</code> and <code>2</code>. | <code>1</code> |
| tagged | <code>optional</code> | boolean | Generate tagged (accessible) PDF. | <code>false</code> | | tagged | <code>optional</code> | boolean | Generate tagged (accessible) PDF. | <code>true</code> |
| timeout | <code>optional</code> | number | Timeout in milliseconds. Pass <code>0</code> to disable timeout. | <code>30_000</code> | | timeout | <code>optional</code> | number | Timeout in milliseconds. Pass <code>0</code> to disable timeout. | <code>30_000</code> |
| width | <code>optional</code> | string \| number | Sets the width of paper. You can pass in a number or a string with a unit. | | | width | <code>optional</code> | string \| number | Sets the width of paper. You can pass in a number or a string with a unit. | |

View File

@ -158,7 +158,7 @@ export interface PDFOptions {
omitBackground?: boolean; omitBackground?: boolean;
/** /**
* Generate tagged (accessible) PDF. * Generate tagged (accessible) PDF.
* @defaultValue `false` * @defaultValue `true`
* @experimental * @experimental
*/ */
tagged?: boolean; tagged?: boolean;

View File

@ -349,8 +349,8 @@ export function parsePDFOptions(
pageRanges: '', pageRanges: '',
preferCSSPageSize: false, preferCSSPageSize: false,
omitBackground: false, omitBackground: false,
tagged: false,
outline: false, outline: false,
tagged: true,
}; };
let width = 8.5; let width = 8.5;

View File

@ -955,6 +955,12 @@
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[page.spec] Page Page.pdf can print to PDF without accessible tags",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["SKIP"]
},
{ {
"testIdPattern": "[page.spec] Page Page.pdf should respect timeout", "testIdPattern": "[page.spec] Page Page.pdf should respect timeout",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -3094,6 +3100,12 @@
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[page.spec] Page Page.pdf can print to PDF without accessible tags",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"]
},
{ {
"testIdPattern": "[page.spec] Page Page.removeExposedFunction should work", "testIdPattern": "[page.spec] Page Page.removeExposedFunction should work",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],

View File

@ -1940,6 +1940,25 @@ describe('Page', function () {
} }
}); });
it('can print to PDF without accessible tags', async () => {
const {page, server} = await getTestState();
const outputFile = __dirname + '/../assets/output.pdf';
const outputFileAccessible =
__dirname + '/../assets/output-accessible.pdf';
await page.goto(server.PREFIX + '/pdf.html');
await page.pdf({path: outputFile});
await page.pdf({path: outputFileAccessible, tagged: false});
try {
expect(fs.readFileSync(outputFileAccessible).byteLength).toBeLessThan(
fs.readFileSync(outputFile).byteLength
);
} finally {
fs.unlinkSync(outputFileAccessible);
fs.unlinkSync(outputFile);
}
});
it('can print to PDF and stream the result', async () => { it('can print to PDF and stream the result', async () => {
const {page} = await getTestState(); const {page} = await getTestState();