I need to add a picture to the document by coordinates

I need to add a picture to the document by coordinates.
I use this documentation: https://www.pdftron.com/documentation/web/guides/full-api/setup/

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");

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi Abram,

Thank you for contacting us regarding Webviewer.

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?

  1. Source image file(s).
  2. Code, or settings, you used to generate the output, including any important variable values
  3. 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
  4. SDK version number

Check your ticket status - https://support.pdftron.com/support/tickets/24832

Best Regards,

Ahmad Moaaz

Software Developer

PDFTron Systems, Inc.

www.pdftron.com

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.

Yes, i use this guide.

  1. Any picture in raster format. Example:
    q

` import WebViewer from ‘@pdftron/webviewer’;
import ‘regenerator-runtime/runtime’;

WebViewer(
{
path: ‘/public/webviewer’,
webviewerServerURL: ‘http://localhost:8090/’,
forceClientSideInit: true,
showLocalFilePicker: true,
fullAPI: true,
},
document.getElementById(‘viewer’)
).then(instance => {

const { documentViewer, PDFNet } = instance.Core;
documentViewer.addEventListener(‘documentLoaded’, async () => {
await PDFNet.initialize();
const doc = documentViewer.getDocument();
const pdfDoc = await doc.getPDFDoc();

// 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();

}
});
`

d) I expected to see a picture in coordinates 100, 100. For example: as in this image:

  1. server version: 1.5.6-ge8b6a41
    |UI version|‘8.0.1’|
    |Core version|‘8.0.1’|

Hello Abram,

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?

Here you can find steps to set up a basic one if you do not already have one. https://github.com/http-party/http-server

If the error persists please also send a screenshot of your network requests in your browser. Specifically the request to the image.

Check your ticket status - https://support.pdftron.com/support/tickets/24832

Best Regards,

Ahmad Moaaz

Software Developer

PDFTron Systems, Inc.

www.pdftron.com

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.