Hi Support,
I am trying to get the PDF Viewer Component to work to display a PDF and its outline. I have a NextJs 14 application.
I am now getting the following compile error:
⨯ node_modules/@syncfusion/ej2-react-base/src/component-base.js (6:15) @ extendStatics
⨯ TypeError: Object prototype may only be an Object or null: undefined
at setPrototypeOf (<anonymous>)
at extendStatics (webpack-internal:///(rsc)/./node_modules/@syncfusion/ej2-react-base/src/component-base.js:19:16)
at eval (webpack-internal:///(rsc)/./node_modules/@syncfusion/ej2-react-base/src/component-base.js:22:9)
at eval (webpack-internal:///(rsc)/./node_modules/@syncfusion/ej2-react-base/src/component-base.js:59:5)
at eval (webpack-internal:///(rsc)/./node_modules/@syncfusion/ej2-react-base/src/component-base.js:636:2)
Server Error
Error: Object prototype may only be an Object or null: undefined
Here is the code:
Thanks in advance for your help!
Hi Donald,
We tried to reproduce the issue based on the given details.
But, we are unable to reproduce the issue. We have shared a sample in the
following link, in which we tried to reproduce the issue.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/nextjs14Sample418860508.zip
Please test the sample on your end and inform us if you encounter any concerns. If you have identified any problems, kindly provide a modified sample, relevant code snippets, and a video recording demonstrating the reported issue. These details will assist us in further analysis and providing appropriate assistance.
THanks for your help. Now i get the error:
digest: "2293169714"
⨯ Error: Unsupported Server Component type: {...}
at stringify (<anonymous>)
⨯ Error: Unsupported Server Component type: {...}
at stringify (<anonymous>)
digest: "2293169714"
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check your code at page.tsx:15.
⨯ Error: Unsupported Server Component type: {...}
at stringify (<anonymous>)
⨯ Error: Unsupported Server Component type: {...}
at stringify (<anonymous>)
digest: "2293169714"
Error: Unsupported Server Component type: {...}
I added the "use client" at the top of the page. I know get the error:
Internal error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Here is the code:
Here is the component code:
I got it to work.... I had the code in the wrong page.
How do I seleect/display a PDF in the public folder of the web server?
I have a PDF in the folder:
Public (doc root)/reports/testReport.pdf
I have set the document path as follows but I get the error: Invalid PDF Type or PDF file not found. Please select a valid PDF file.
The error message "Invalid PDF file type or PDF file not found. Please select a valid PDF file" appears when the document is not found at the specified server location. Only a limited number of documents are available in the demo service URL ( https://services.syncfusion.com/react/production/api/pdfviewer). If you wish to load your own default document, we recommend creating your own web service. To learn how to create your own web service, please refer to the link below:
KB link: https://www.syncfusion.com/kb/10346/how-to-create-pdf-viewer-web-service-application-in-asp-net-core
We have also shared a sample on GitHub, which you can find at the link below:
GitHub link: https://github.com/SyncfusionExamples/EJ2-PDFViewer-WebServices/tree/main/ASP.NET%20Core
To load the own document, follow these steps:
NextJS screenshot:
ASP.NET.Core screenshot:
I created a web service that returns the PDF. I can see the contents of the pdf in the console log. However, now I get the following error in the viewer.
Please advise as to what is required for the web service. Code is below.
Here is the API code:
We have provided a video recording demonstrating how to connect to your own web service and load PDF documents.
Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebServiceVideo-1372889773.zip
Please note that our web service support is available for .NET only.
Additionally, if you have the base64 string of the document, you can load PDF documents using the viewer.load() method with the demo serviceURL (" https://services.syncfusion.com/react/production/api/pdfviewer") itself and you don't need to create any custom web service.
Documentation to load the PDF document dynamically: https://ej2.syncfusion.com/react/documentation/pdfviewer/how-to/load-document
So how do i load the document returned from the service?
Your docs and direction to use are confusing and dont work.
If you have obtained the document base64 string using Node.js, you can load the load the PDF document using our demo serviceURL (https://services.syncfusion.com/react/production/api/pdfviewer) and you don't need to create your own web service. We have provided the code snippet and sample to load the document using base64 string.
Code snippet:
|
const loadDocumentFromBase64 = async () => { const response = await fetch("http://localhost:3000/api/hello"); const data = await response.json(); viewer.load("data:application/pdf;base64,"+ AddBase64String, null); }; |
Documentation: https://ej2.syncfusion.com/react/documentation/pdfviewer/how-to/load-document
In the provided sample, when you click the "LoadDocument" button, we retrieve the document's base64 string using the Node.js and fetch API, and then loaded the document in the PDF Viewer using the `viewer.load()` method.
Kindly try this sample and If you have any concerns, please share the sample in which you are facing the issue or modify the provided sample. This will help us investigate the problem further.