Chrome 显示高度有限的 PDF
Chrome displays PDFs with limited height
考虑 this 文档。
在 Firefox 上,一切正常:
但是,在 Chrome 上,文档高度受到限制:
我正在使用(旧版本的)Hugo 生成网站。有谁知道是什么原因造成的?
在 Chrome 中打开开发人员控制台,您可以看到一些错误。没想到先做这个,因为它只是一个PDF,它能出什么问题?嗯,
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-[redacted]'), or a nonce ('nonce-...') is required to enable inline execution.
(5) Refused to load the image '<URL>' because it violates the following Content Security Policy directive: "img-src 'self'".
这是 HTTP 响应的样子。
> GET /pdf/impulsiv138.pdf HTTP/1.1
> Host: impulsiv.fs.tum.de
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 21 Jun 2020 05:52:33 GMT
< Server: Apache
< Last-Modified: Mon, 15 Jun 2020 15:36:36 GMT
< ETag: "4805f5-5a821312d6900"
< Accept-Ranges: bytes
< Content-Length: 4720117
< Strict-Transport-Security: max-age=15552000
< X-Frame-Options: deny
< X-Content-Type-Options: nosniff
< Content-Security-Policy: default-src 'none'; img-src 'self'; style-src 'self'; script-src 'self'; object-src 'self';
< Content-Type: application/pdf
<
您的 HTTP 服务器正在填写 Content-Security-Policy
header,这可能是由您明确填写的,也可能是您主机的一些默认设置。
经过更多挖掘,这似乎是 Chrome 加载 PDF 的常见问题:
- How to set CSS for embedded PDF viewer with CSP enabled
- Opening a PDF embedded in iframe in chrome with content security policy > plugin-types
我不完全确定更改这些指令意味着什么,但这是你的主导。
如果在浏览器中显示 PDF 不是硬性功能要求,那么我建议只指示浏览器下载它们(参见 Content-Disposition
HTTP header)。如果是,那么我会尝试制作一个页面来包装 PDF 并将其显示在那里,也许您可以通过这种方式获得更多控制权。
考虑 this 文档。
在 Firefox 上,一切正常:
但是,在 Chrome 上,文档高度受到限制:
我正在使用(旧版本的)Hugo 生成网站。有谁知道是什么原因造成的?
在 Chrome 中打开开发人员控制台,您可以看到一些错误。没想到先做这个,因为它只是一个PDF,它能出什么问题?嗯,
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-[redacted]'), or a nonce ('nonce-...') is required to enable inline execution.
(5) Refused to load the image '<URL>' because it violates the following Content Security Policy directive: "img-src 'self'".
这是 HTTP 响应的样子。
> GET /pdf/impulsiv138.pdf HTTP/1.1
> Host: impulsiv.fs.tum.de
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 21 Jun 2020 05:52:33 GMT
< Server: Apache
< Last-Modified: Mon, 15 Jun 2020 15:36:36 GMT
< ETag: "4805f5-5a821312d6900"
< Accept-Ranges: bytes
< Content-Length: 4720117
< Strict-Transport-Security: max-age=15552000
< X-Frame-Options: deny
< X-Content-Type-Options: nosniff
< Content-Security-Policy: default-src 'none'; img-src 'self'; style-src 'self'; script-src 'self'; object-src 'self';
< Content-Type: application/pdf
<
您的 HTTP 服务器正在填写 Content-Security-Policy
header,这可能是由您明确填写的,也可能是您主机的一些默认设置。
经过更多挖掘,这似乎是 Chrome 加载 PDF 的常见问题:
- How to set CSS for embedded PDF viewer with CSP enabled
- Opening a PDF embedded in iframe in chrome with content security policy > plugin-types
我不完全确定更改这些指令意味着什么,但这是你的主导。
如果在浏览器中显示 PDF 不是硬性功能要求,那么我建议只指示浏览器下载它们(参见 Content-Disposition
HTTP header)。如果是,那么我会尝试制作一个页面来包装 PDF 并将其显示在那里,也许您可以通过这种方式获得更多控制权。