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

Hi @mark.glimm , I’m hitting this issue while working on upgrading my app to Node 20, did you find a solution for this by chance?

1 Like

I am having the same issue on AWS Lambda when doing anything later than node18 node 20 and node 22 all give that same locale. Of course we are not creating the amazon linux run time environment - I thought it was our original packaging of library in a layer but now that I’ve tried to remove layer and package the node modules as all other lambdas I get the same error as above.
I can build in drone on aws using an amazon image :20 and :22 which is node 20 and node 22 ) but as long as I specify that this lambda is node18.x and of course architecture x86_64 (amd64 really)
Then everything works.
Has anyone seen any workarounds I am using serverless framework 4 to deploy etc. it was there using version 3 - so its not dependent on that framework…
could it be webpack or anything…

1 Like

@ashley.eatly1 I ended up getting around this locale exception issue by adding:

LANG: en_US.UTF-8
LC_ALL: C

in the environment section of my serverless.yml file.

It is now deploying using Serverless 4 and the aws node20 runtime and working successfully with no issues found so far.

1 Like