getFileData() with option { downloadType: 'pdf' } fails to generate pdf for office documents

Product: Webviewer

Product Version: 11.6.1

documentViewer.getDocument().getFileData() fails when I attempt to get the raw file data of an office document, even when downloadType: 'pdf' was specified.

I have a custom print handler defined so:

    const handlePrint = useCallback(async () => {
        if (!webviewerInstance.current) return;
        const { documentViewer, PDFNet, annotationManager } = webviewerInstance.current.Core;
        await PDFNet.initialize();

        const xfdfString = await annotationManager.exportAnnotations();
        const document = documentViewer.getDocument();

        const fileData = await documentViewer.getDocument().getFileData({
            xfdfString,
            flatten: true,
            downloadType: 'pdf',
        });

        const blob = new Blob([fileData], { type: 'application/pdf' });
        const blobUrl = URL.createObjectURL(blob);

        const printWindow = window.open(blobUrl, '_blank');
        if (printWindow) {
            printWindow.onload = () => {
                printWindow.focus();
                printWindow.print();
            };
        }
    }, []);

I get:

webviewer-core.min.js:1391 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'password')
    at ma.<anonymous> (webviewer-core.min.js:1391:264)
    at a (webviewer-core.min.js:66:50)
    at Object.next (webviewer-core.min.js:64:323)
    at w (webviewer-core.min.js:64:92)

The document is not password-protected.

I would greatly appreciate any inputs on this.

1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


It seems that you’re encountering an issue when trying to generate a PDF from an office document using the getFileData method with downloadType: 'pdf'. This error might occur due to how office documents are being handled or a misconfiguration in your setup.

Some things you can try:

  • Ensure that your office document is fully loaded before calling getFileData. You might need to check the document loading status.

  • Verify that the full API is properly initialized and that all necessary resources are loaded before attempting to convert the document.

  • Check if there are any errors or warnings during the document loading phase that might affect conversion.

  • Consider using the CoreControls methods to handle office document conversion if getFileData doesn’t support it directly.

  • Ensure that the PDFNet library is properly initialized and that all dependencies are loaded correctly.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

Hello Denis,

Thank you for contacting WebViewer Forums.

Office documents are not able to flatten with annotations. If you would like to include annotations into the office document, it first needs to be converted or loaded in as PDF and the process should work as expected.

More information on loadAsPDF option can be found here: JavaScript PDF Manipulation Library | Apryse documentation

Regards,
Luke

1 Like