Can't create blank PDF - 'PDFWorkerError'

I am unsuccessful in creating a bank pdf as demonstrated in Audrey’s video “How to generate PDF with PDFTron PDFNet Node.js SDK - YouTube”.

[Ubuntu 22.10, Nodejs v18.13.0]

// index.js
const { PDFNet } = require(“@pdftron/pdfnet-node”);

const main = async () => {
const doc = await PDFNet.PDFDoc.create();
const page = await doc.pageCreate();
doc.pagePushBack(page);
doc.save(“blank.pdf”, PDFNet.PDFDoc.SaveOptions.e_linearized);
};
PDFNet.runWithCleanup(
main,
“key”
)
.catch((err) => {
console.log(err);
})
.then(() => {
PDFNet.shutdown();
});

// package.json
{
“name”: “tron”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“test”: “echo "Error: no test specified" && exit 1”
},
“keywords”: [],
“author”: “”,
“license”: “ISC”,
“dependencies”: {
@pdftron/pdfnet-node”: “^9.4.2”
}
}

// terminal output
PDFNet is running in demo mode.
{
message: ‘Exception: \n’ +
‘\t Message: locale::facet::_S_create_c_locale name not valid\n’ +
‘\t Conditional expression: \n’ +
‘\t Version : 9.4.2-a2633dd\n’ +
‘\t Platform : Linux\n’ +
‘\t Architecture : AMD64\n’ +
‘\t Filename : \n’ +
‘\t Function : \n’ +
‘\t Linenumber : 0\n’,
type: ‘PDFWorkerError’
}

1 Like

This appears to be an environment configuration issue with your Ubuntu instance, and updating locales in your instance are how to resolve this.

I suspect something like the following will help you.
https://help.ubuntu.com/community/Locale

For example the following worked for another user.

Change the env var by export LC_ALL=C; unset LANGUAGE

1 Like

Hi @Ryan ,
I’m trying to figure out a solution for this in an aws lambda image (public.ecr.aws/lambda/nodejs:20.2023.12.13.20-arm64), the command you shared here doesn’t solve the pdfnet error for me.

What specifically is PDFWorker looking for from the locale settings?

Thanks,
Mark

1 Like

More specifically looking at locale there seems to be a key file (/etc/locale.conf ?) missing in the aws/lambda/nodejs:20 image that is preset in the nodejs:14 image, where my pdftron function code executes without the locale error:

# public.ecr.aws/lambda/nodejs:14.2024.03.28.15-arm64

sh-4.2# uname -m
aarch64
sh-4.2# node -v
v14.21.3
sh-4.2# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
sh-4.2# 



# public.ecr.aws/lambda/nodejs:20-arm64

sh-5.2# uname -m
aarch64
sh-5.2# node -v
v20.11.1
sh-5.2# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
sh-5.2# 
1 Like

I found my missing package; for the AWS provided Lambda images for nodejs, the required package for the PDFTron addon is glibc-langpack-en . I think this is specifically for operations using the Convert class.

SO Post:

1 Like