mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 12:22:17 +01:00
fix: chromium exact colors (#361)
This commit is contained in:
@@ -363,6 +363,31 @@ func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath
|
|||||||
|
|
||||||
return fmt.Errorf("wait for events: %w", err)
|
return fmt.Errorf("wait for events: %w", err)
|
||||||
}),
|
}),
|
||||||
|
chromedp.ActionFunc(func(ctx context.Context) error {
|
||||||
|
// See:
|
||||||
|
// https://github.com/gotenberg/gotenberg/issues/354
|
||||||
|
// https://github.com/puppeteer/puppeteer/issues/2685
|
||||||
|
// https://github.com/chromedp/chromedp/issues/520
|
||||||
|
script := `
|
||||||
|
(() => {
|
||||||
|
const css = 'html { -webkit-print-color-adjust: exact !important; }';
|
||||||
|
|
||||||
|
const style = document.createElement('style');
|
||||||
|
style.type = 'text/css';
|
||||||
|
style.appendChild(document.createTextNode(css));
|
||||||
|
document.head.appendChild(style);
|
||||||
|
})();
|
||||||
|
`
|
||||||
|
|
||||||
|
evaluate := chromedp.Evaluate(script, nil)
|
||||||
|
err := evaluate.Do(ctx)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("add CSS for exact colors: %w", err)
|
||||||
|
}),
|
||||||
chromedp.ActionFunc(func(ctx context.Context) error {
|
chromedp.ActionFunc(func(ctx context.Context) error {
|
||||||
if options.WaitDelay > 0 {
|
if options.WaitDelay > 0 {
|
||||||
// We wait for a given amount of time so that JavaScript
|
// We wait for a given amount of time so that JavaScript
|
||||||
|
|||||||
@@ -321,6 +321,9 @@ func TestChromium_PDF(t *testing.T) {
|
|||||||
URL: "file:///tests/test/testdata/chromium/html/sample6/index.html",
|
URL: "file:///tests/test/testdata/chromium/html/sample6/index.html",
|
||||||
allowFileAccessFromFiles: true,
|
allowFileAccessFromFiles: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
URL: "file:///tests/test/testdata/chromium/html/sample7/index.html",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
func() {
|
func() {
|
||||||
mod := new(Chromium)
|
mod := new(Chromium)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<h1>This image is loaded from a URL</h1>
|
<h1>This image is loaded from a URL</h1>
|
||||||
<img src="https://gutendev.com/wp-content/uploads/2018/10/01_03-1.jpg">
|
<img src="https://user-images.githubusercontent.com/8983173/130322857-185831e2-f041-46eb-a17f-0a69d066c4e5.png">
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
14
test/testdata/chromium/html/sample7/index.html
vendored
Normal file
14
test/testdata/chromium/html/sample7/index.html
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Gutenberg</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Gutenberg</h1>
|
||||||
|
<p style="color: #d1d0d0;">
|
||||||
|
It is a press, certainly, but a press from which shall flow in inexhaustible streams...Through it, God will spread His Word. A spring of truth shall flow from it: like a new star it shall scatter the darkness of ignorance, and cause a light heretofore unknown to shine amongst men.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user