MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / exportNotePdf

Function exportNotePdf

apps/desktop/src/main/index.ts:1493–1576  ·  view source on GitHub ↗
(
  relPath: string,
  parentWindow: BrowserWindow | null | undefined
)

Source from the content-addressed store, hash-verified

1491}
1492
1493async function exportNotePdf(
1494 relPath: string,
1495 parentWindow: BrowserWindow | null | undefined
1496): Promise<string | null> {
1497 const current =
1498 parentWindow && !parentWindow.isDestroyed()
1499 ? windowVaults.vaultForWindow(parentWindow.id)
1500 : currentVault ?? (isRemoteWorkspaceActive() ? await requireRemoteWorkspaceClient().getCurrentVault() : null)
1501 if (!current) {
1502 throw new Error('No active vault is available for PDF export.')
1503 }
1504
1505 const suggestedName = `${sanitizePdfFilename(noteTitleFromRelPath(relPath))}.pdf`
1506 const saveDialogOptions = {
1507 title: 'Export Note as PDF',
1508 defaultPath: path.join(app.getPath('documents'), suggestedName),
1509 buttonLabel: 'Export PDF',
1510 filters: [{ name: 'PDF', extensions: ['pdf'] }]
1511 }
1512 const result = parentWindow
1513 ? await dialog.showSaveDialog(parentWindow, saveDialogOptions)
1514 : await dialog.showSaveDialog(saveDialogOptions)
1515 if (result.canceled || !result.filePath) return null
1516
1517 const targetPath = ensurePdfExtension(result.filePath)
1518 const mac = isMac()
1519 const exportWindow = new BrowserWindow({
1520 width: 1024,
1521 height: 1400,
1522 show: false,
1523 autoHideMenuBar: true,
1524 titleBarStyle: mac ? 'hiddenInset' : 'hidden',
1525 trafficLightPosition: { x: 12, y: 12 },
1526 ...(mac
1527 ? {
1528 backgroundColor: '#ffffff'
1529 }
1530 : {
1531 backgroundColor: '#ffffff',
1532 icon: windowIconPath()
1533 }),
1534 webPreferences: {
1535 preload: path.join(__dirname, '../preload/index.js'),
1536 sandbox: false,
1537 contextIsolation: true,
1538 nodeIntegration: false
1539 }
1540 })
1541
1542 try {
1543 if (parentWindow && !parentWindow.isDestroyed()) {
1544 inheritWindowWorkspaceSession(parentWindow, exportWindow)
1545 }
1546 installNavigationGuards(exportWindow)
1547 applyZoomFactor(exportWindow, currentZoomFactor)
1548 const params = `?exportNote=${encodeURIComponent(relPath)}`
1549 const devServerUrl = process.env['ELECTRON_RENDERER_URL']
1550 if (devServerUrl) {

Callers 1

registerIpcFunction · 0.70

Calls 15

isRemoteWorkspaceActiveFunction · 0.85
sanitizePdfFilenameFunction · 0.85
noteTitleFromRelPathFunction · 0.85
ensurePdfExtensionFunction · 0.85
isMacFunction · 0.85
windowIconPathFunction · 0.85
installNavigationGuardsFunction · 0.85
applyZoomFactorFunction · 0.85
waitForExportWindowStateFunction · 0.85
vaultForWindowMethod · 0.80

Tested by

no test coverage detected