Error converting CAD content using CAD2PDF module Add-On

Product: PDFNet.CADModule

Product Version: Latest

Please give a brief summary of your issue:
I am running the package in a docker file using Ubuntu 20.04 and NodeJS v16 and I receive the following error message. When I run this outside of the docker it seems to work fine. Is there any extra dependencies that I need to install when running inside a docker?

Error: {“message”:“Exception: \n\t Message: Error converting CAD content using CAD2PDF module Add-On. \n\t Conditional expression: false\n\t Version : 9.0.0.77728\n\t Platform : Linux\n\t Architecture : AMD64\n\t Filename : Convert.cpp\n\t Function : FromCAD\n\t Linenumber : 1521\n”,“type”:“InvalidPDF”}

Please describe your issue and provide steps to reproduce it:
my index.js file

const { PDFNet } = require("@pdftron/pdfnet-node");
const path = require("path");
const fs = require("fs");

async function bootstrap() {
  PDFNet.addResourceSearchPath("/Lib");
  const doc = await PDFNet.PDFDoc.create();
  if (!(await PDFNet.CADModule.isModuleAvailable())) {
    console.log("PDFTron SDK CAD module not available.");
  }
  const files = fs.readdirSync('./schematics-and-bom');
  for (file in files) {
    const extension = files[file].split(".").pop();
    if (extension === "dwg") {
      const opts = new PDFNet.Convert.CADConvertOptions();
      opts.setPageWidth(800);
      opts.setPageHeight(600);
      opts.setRasterDPI(150);
      console.log(`adding ${files[file]}`);
      await PDFNet.Convert.fromCAD(
        doc,
        path.join("./schematics-and-bom", files[file]),
        opts
      );
    }
  }
  try {
    doc.save("newVersion.pdf", PDFNet.SDFDoc.SaveOptions.e_linearized);
  } catch (e) {
    console.error(e);
  }
}

async function run() {
  try {
    await PDFNet.runWithCleanup(bootstrap, "")
      .catch(function (error) {
        console.log("Error: " + JSON.stringify(error));
      })
      .then(function () {
        PDFNet.shutdown();
      });
  } catch (error) {
    console.log(error.message);
  }
}
run();

Dockerfile

# Container image that runs your code
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get -y install curl gnupg
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get -y install nodejs
RUN npm install --global yarn
COPY package.json /package.json
COPY yarn.lock /yarn.lock
RUN yarn install

ADD index.js /index.js
ADD https://www.pdftron.com/downloads/CADModuleLinux.tar.gz /CADModuleLinux.tar.gz
RUN tar -xzf /CADModuleLinux.tar.gz -C /
ENTRYPOINT ["node", "/index.js"]

Please provide a link to a minimal sample where the issue is reproducible:

1 Like

Please note that the CADMoule uses OpenGL for rendering 3D objects. As such, Linux environments (especially headless) will require these packages to be installed. Please see the documentation here for more information.

I got everything else from that page, but missed that last section. It worked like a charm! Thanks a lot for the help.

If anyone else want to use a docker to convert dwg to pdf here is the working docker file

# Container image that runs your code
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get -y install curl gnupg
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get -y install nodejs libgl1-mesa-dev libx11-dev libglu1-mesa-dev
RUN npm install --global yarn
COPY package.json /package.json
COPY yarn.lock /yarn.lock
RUN yarn install

ADD index.js /index.js
ADD https://www.pdftron.com/downloads/CADModuleLinux.tar.gz /CADModuleLinux.tar.gz
RUN tar -xzf /CADModuleLinux.tar.gz -C /
ENTRYPOINT ["node", "/index.js"]
2 Likes