I get this error: Uncaught (in promise) Exception:
Message: The image format is not directly supported on this platform.
Filename: Image.cpp
Function: Create
Linenumber: erprintpunctspaceunicodeuppervwordxdigit
I tried to add images in png, jpg, jpeg formats. But always this mistake
The img variable is not initialized const img = await PDFNet.Image.createFromURL(pdfDoc, inputPath + "butterfly.png");
To clarify, are you trying to add an image onto the PDF document using the following guide?
It’s hard to say what the issue is. To investigate further could you please provide some additional information about the error?
Source image file(s).
Code, or settings, you used to generate the output, including any important variable values
Screenshot of what you see, clearly indicating the following:
a) Application used for viewing
b) Page number on which the issue occurs (if document more than one page)
c) Clearly indicate where the issue is in the screenshot
d) Clearly indicate what you expected to see
CONFIDENTIALITY NOTICE: This message (and any attachment to it) is intended only for the use of the individual or entity to which it is addressed in the header, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. Any reproduction, distribution, modification or use of the contents of this message (and any attachment to it) by any individual or entity other than the intended recipient is prohibited. If you have received this communication in error, please notify us immediately and delete the original.
// Ensure that we have our first page.
await pdfDoc.requirePage(1);
// Run our main function using 'runWithCleanup'
await PDFNet.runWithCleanup(async () => await main(pdfDoc));
// Refresh the cache with the newly updated document
documentViewer.refreshAll();
// Update viewer with new document
documentViewer.updateView();
});
async function main(pdfDoc) {
pdfDoc.initSecurityHandler();
pdfDoc.lock();
const inputPath = '../img';
const firstPage = await pdfDoc.getPage(1);
// create a new page builder that allows us to create new page elements
const builder = await PDFNet.ElementBuilder.create();
// create a new page writer that allows us to add/change page elements
const writer = await PDFNet.ElementWriter.create();
writer.beginOnPage(firstPage, PDFNet.ElementWriter.WriteMode.e_overlay);
// Adding a JPEG image to output file
const img = await PDFNet.Image.createFromURL(pdfDoc, inputPath + '/q.jpeg');
const imgWidth = await img.getImageWidth();
const imgHeight = await img.getImageHeight();
const element = await builder.createImageScaled(img, 100, 100, imgWidth, imgHeight);
writer.writePlacedElement(element);
writer.end();
I was unable to reproduce this error using the file provided.
However, I suspect the issue could be that the Webviewer server does not have access to the file on your filesystem. Can you please try to host the file on a local webserver?
CONFIDENTIALITY NOTICE: This message (and any attachment to it) is intended only for the use of the individual or entity to which it is addressed in the header, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. Any reproduction, distribution, modification or use of the contents of this message (and any attachment to it) by any individual or entity other than the intended recipient is prohibited. If you have received this communication in error, please notify us immediately and delete the original.