JXA: How to convert HTML to PDF, and to open created PDF

Please help me to get PDF paginated from HTML, and open created PDF.

My code does not work as needed.

(function run() {
  const DT = Application("DEVONthink 3");

  DT.includeStandardAdditions = true;

  // Creates HTML — OK
  let htmlDoc = DT.createRecordWith({
    name: "df",
    type: "html",
    "plain text": "Some HTML code",
  });

  // Does not convert, just creates a copy
  let pdfDoc = DT.convert(
    {
      record: htmlDoc,
    },
    { to: "‌PDF document" }
  );

  // Does not open new record
  DT.openTabFor({ record: pdfDoc });
  //
})();

Sorry, this was my incorrect syntax in DT.convert command.

Correct, which is working as needed:

  let pdfDoc = DT.convert({
    record: htmlDoc,
    to: "PDF document",
  });
2 Likes