Currently the chromium-render-service renders PDFs in A4 and Letter sizes without mobile print styles. In order to test the service against mobile styles we need to make the following to changes:
- Allow the service to render PDFs in Legal size (per @Nirzar at T181513#3793601);
- Add an option in the service to load mobile print styles before rendering.
Design requirement
We have two intents for producing PDFs and we have two platforms for doing so. That can be put into a 2x2 for number of styles we need.
out of the 4 required styles,
- We can safely dismiss the use case to create hard copies from small screens
- We can use the same styles for soft and hard copy on large screens, as the visual scale of large screen matches printing on paper. i.e. font size equivalent to 10pt, and 10-15 words per line
- for soft copy on small screens, we need larger visual scale. i.e. font size equivalent of 16pt and around ~5 words per line. this will mimic the regular article view
Developer notes
The below are suggestions. Maybe you'll find a better way of accomplishing the task while working on it.
Acceptance criteria
- Nirzar to explain the different types of PDF
@phuedx: Done in T181680#3890789.
- Before coding anything having a meeting to discuss and agree what the change will look like. Meeting creator should be driving the change and have a strawman proposal of what to do. Should discuss how clients will determine what PDF mode to use.
- Should be possible to generate 2 types of PDFs via 2 different URLs
- Ensure that the headless Chromium UA is sending a well-known, fixed header (see T181680#3946988)
Adding a new page size:
- Allow the PDF end point to accept legal here.
Applying mobile print styles
- puppeteer allows adding style tags to the page that's being rendered. Use it to add the mobile print styles to the the page object before rendering the PDF;
- The mobile print styles is part of the "skins.minerva.base.styles" module and can be seen here.
- Since we don't want to hard-code URLs, we'll have to create a config variable that points to the module URL. Something similar to this.
QA Steps
Please verify that both desktop and mobile rendered PDFs match our print styles.
To test that:
- go to the article and print it to the PDF using system print (CTRL+P, or Print from browser menu), save the PDF
- build an URL to retrieve the PDF from chromium-renderer [explained below] and save the PDF generated by our service
- compare that PDF generated by chromium-renderer looks the same as the PDF generated by the browser using print method. PDF don't have to be identical (different browsers can handle styles differently) but the WMF look&feel has to be present. If unsure please refer to the PDF generated by browser print method.
Please verify that for both desktop and mobile articles. Pay attention to the images and graphics in the PDF generated by the chromium-renderer service, things like images, math/chemistry formulas has to be present.
Please verify that artices from non english wikipedia (preferably non-latin charsets) and RTL languages are generated correctly on mobile PDFs.
How to generate URL to the chromium service
URL schema is http://chromium-pdf.wmflabs.org/{wiki}/v1/pdf/{article}/{size}/{format}
Where:
- {wiki} -> wiki domain, ex 'en.wikipedia.pl`
- {article} -> Title of article we want to generate pdf for, ex: Poland
- {size} -> PDF size, accepted sizes are letter, a4, legal
- {format} -> optional paramter, PDF format, available formats are desktop and mobile. If {format}is not specified system will generate desktop version of PDF
Examples:
Poland article from english wikipedia, desktop version, a4 size
http://chromium-pdf.wmflabs.org/en.wikipedia.org/v1/pdf/Poland/a4
or
http://chromium-pdf.wmflabs.org/en.wikipedia.org/v1/pdf/Poland/a4/desktop
Both URLs are valid as {format} parameter is optional.
Planet article from english wikipedia, mobile version, legal size
http://chromium-pdf.wmflabs.org/en.wikipedia.org/v1/pdf/Planet/legal/mobile