1

ヘッドレスChromeでPDF印刷を試行しています。これは私が扱ってるのエラーです:ヘッドレスChromeでPrintToPDFが動作しない60

(node:6761) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: PrintToPDF is not implemented

Node.jsのパッケージ:

html-pdf-chrome 

依存性:

✔ "chrome-remote-interface": "^0.23.1" (v0.23.2 installed) 
✔ Chrome 59 (v60 beta installed) 

ドライバースクリプト:

const htmlPdf = require('html-pdf-chrome'); 
const html = '<p>Hello, world!</p>'; 
const options = { 
    port: 9222, // port Chrome is listening on 
}; 
htmlPdf.create(html, options).then((pdf) => pdf.toFile('test.pdf')); 

クローム60ヘッドレスモードでインストールされ、実行されています。

> google-chrome --version 
Google Chrome 60.0.3112.24 beta 

私は、エラーが発生した場所であるPage.printToPDF呼び出すコードセクションを突き止めました:

const CDP = require("chrome-remote-interface"); 
... 
const { Page } = client; 
... 
// https://chromedevtools.github.io/debugger-protocol-viewer/tot/Page/#method-printToPDF 
const pdf = yield Page.printToPDF(options.printOptions); 

は私が必ずPage.captureScreenshotのように他の広告を出して機能を実行することができています。

Page.printToPDFを広告として掲載するにはどうすればよいですか?ここで

答えて

1

は私がapacheユーザーでChromeを実行するためにPHPでのヘッドレスクロームコマンドを作成する方法である:

private $headlessChromeCmd = [ 
    '$(which google-chrome)', 
    '--headless', 
    '--disable-gpu', 
    '--hide-scrollbars', 
    '--remote-debugging-port=%u', 
    '--no-first-run', 
    '--safebrowsing-disable-auto-update', 
    '--disable-background-networking', 
    //'--disable-extensions', <-- This was the problem 
    '--disable-translate', 
    '--disable-sync' 
]; 

... 

// Launch Chrome in a non-blocking background process 
$cmd = sprintf(implode(' ', $this->headlessChromeCmd), $port) . ' </dev/null>"'. $this->chromeStdoutFile . '" 2>&1 & echo $!;'; 

// For brevity without capturing stdout, stderr nor response codes 
shell_exec($cmd); 

のCLIのparam --disable-extensionsが犯人でした。 PDFを生成するために必要なChromeのPDFビューアは、このパラメータで無効になっている拡張機能の1つです。謎解き。

関連する問題