这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: 18.17.1
node-version: 20.18.1
- name: Setup configs
run: |
cp config/common.json.example config/common.json \
Expand Down
15 changes: 11 additions & 4 deletions workers/loc.api/generate-report-file/pdf-writer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class PdfWriter {
this.i18next = i18next

this.isElectronjsEnv = false
this.shouldZoomBeAdjusted = (
process.platform !== 'win32' &&
!this.isElectronjsEnv
)

this.addTemplates()
this.compileTemplate()
Expand Down Expand Up @@ -101,7 +105,10 @@ class PdfWriter {
apiData,
opts
)
const buffer = await this.createPDFBuffer({ template })
const buffer = await this.createPDFBuffer({
template,
language: opts?.language
})

return buffer
}
Expand Down Expand Up @@ -171,7 +178,7 @@ class PdfWriter {
const reportColumns = jobData?.columnsPdf ?? jobData?.columnsCsv

const html = template({
isElectronjsEnv: this.isElectronjsEnv,
shouldZoomBeAdjusted: this.shouldZoomBeAdjusted,
apiData,
jobData,
reportColumns,
Expand All @@ -192,7 +199,7 @@ class PdfWriter {
return html
}

#getTranslator (language) {
getTranslator (language) {
return getTranslator(
{ i18next: this.i18next },
{
Expand Down Expand Up @@ -248,7 +255,7 @@ class PdfWriter {
const languages = this.#getAvailableLanguages()

for (const language of languages) {
const translate = this.#getTranslator(language)
const translate = this.getTranslator(language)

for (const [templateFileName, templatePath] of this.#templatePaths) {
const fn = pug.compileFile(templatePath, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ html(lang=language)
//- https://github.com/marcbachmann/node-html-pdf/issues/619
//- https://github.com/marcbachmann/node-html-pdf/issues/525
//- ratio for rendering: 72dpi (pdf) / 96dpi (browser), 72/96 = 0.75
if process.platform !== 'win32' && !isElectronjsEnv
if shouldZoomBeAdjusted
style @media print { html { zoom: 0.75; } }
style @media print { .header, .footer { zoom: 1; } }
else
Expand Down