Skip to content

Commit

Permalink
Warn about incompatible renderings on first PDF conversion with Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 24, 2024
1 parent 833cab5 commit a7338f2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ const stripBOM = (s: string) => (s.charCodeAt(0) === 0xfeff ? s.slice(1) : s)
export class Converter {
readonly options: ConverterOption

private _firefoxPDFConversionWarning = false

constructor(opts: ConverterOption) {
this.options = opts
}
Expand Down Expand Up @@ -252,7 +254,7 @@ export class Converter {
if (opts.onConverted) opts.onConverted({ file, newFile, template })
}

// #convertFile must return a single file to serve in server
// convertFile must return a single file to serve in server
return { file, template, newFile: files[0] }
} else {
// Try conversion with specific template to scan using resources
Expand Down Expand Up @@ -301,6 +303,17 @@ export class Converter {

const ret = file.convert(this.options.output, { extension: 'pdf' })

// Generate PDF
const browser = await browserManager.browserForConversion()

if (browser.kind === 'firefox' && !this._firefoxPDFConversionWarning) {
this._firefoxPDFConversionWarning = true

warn(
'Using Firefox to convert Markdown to PDF: The output may include some incompatible renderings compared to the PDF generated by Chrome.'
)
}

let outlineData: OutlineData | undefined

ret.buffer = Buffer.from(
Expand Down

0 comments on commit a7338f2

Please sign in to comment.