Fix PDF export font embedding and improve sync reliability
- Replace data URL loading with temporary HTML file to avoid URL length limits - Embed font files as data URLs in print document CSS for offline rendering - Add font asset registry for Merriweather, Crimson Pro, Roboto Serif, and Average - Implement font file caching and blob-to-data-URL conversion - Clean up temporary HTML file after PDF generation - Fix sync to refresh notes after favorite status sync completes
This commit is contained in:
@@ -121,6 +121,11 @@ ipcMain.handle('desktop:export-pdf', async (event, payload) => {
|
||||
return { canceled: true };
|
||||
}
|
||||
|
||||
const tempHtmlPath = path.join(
|
||||
app.getPath('temp'),
|
||||
`nextcloud-notes-export-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.html`
|
||||
);
|
||||
|
||||
const pdfWindow = new BrowserWindow({
|
||||
width: 960,
|
||||
height: 1100,
|
||||
@@ -135,9 +140,8 @@ ipcMain.handle('desktop:export-pdf', async (event, payload) => {
|
||||
});
|
||||
|
||||
try {
|
||||
await pdfWindow.loadURL(
|
||||
`data:text/html;charset=utf-8,${encodeURIComponent(payload.documentHtml)}`
|
||||
);
|
||||
await fs.writeFile(tempHtmlPath, payload.documentHtml, 'utf8');
|
||||
await pdfWindow.loadFile(tempHtmlPath);
|
||||
await pdfWindow.webContents.executeJavaScript(waitForPrintDocument(), true);
|
||||
|
||||
const pdfData = await pdfWindow.webContents.printToPDF({
|
||||
@@ -152,6 +156,7 @@ ipcMain.handle('desktop:export-pdf', async (event, payload) => {
|
||||
filePath: saveResult.filePath,
|
||||
};
|
||||
} finally {
|
||||
await fs.unlink(tempHtmlPath).catch(() => undefined);
|
||||
if (!pdfWindow.isDestroyed()) {
|
||||
pdfWindow.destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user