Same code executed on the server does not produce the same results as in the browser
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
调研方向
从 PDFKit 浏览器演示和提供的代码开始,然后将 Node 18.12.0 的服务器输出与附带的浏览器 PDF 和服务器 PDF 进行比较,重点关注 translate 和路径渲染。当同一份代码在两个环境中都保留预期的变换和绘制顺序时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Bug Report
Description of the problem
I have created working example of drawing SVG path into pdf using PDFKit browser sandbox (https://pdfkit.org/demo/browser.html)
The problem is, while it's working perfectly here, the same code ported to server environment produces different results.
The exact issue is within translate function, which translates the SVG path way too much (mathematically incorrectly). I assume the units would be at fault?
Attaching expected result from browser sandbox and result produced by the same code on the server (the same code minus blobStream code of course) (set the one from the browser as blue color)
4282dfc2-f3f1-4399-9ec4-191e59185540.pdf
2SFtR3p2.pdf
EDIT:
Also just discovered, when drawing rect and then drawing the path, it works as expected in the browser, but on the server the drawn rect is drawn OVER the path, even though the order of drawing is preserved.
To test, place doc.save().rect(0, 0, totalSize, totalSize).fill('#00FF00').restore() just before path drawing
result when rendered on the server:
5Hl7kt4n.pdf
result from browser sandbox:
8b7edae8-0a0c-412d-8fa9-4412d5963b9d.pdf
Code sample
var paddingFactor = 3
var size = 500
var sizeFactor = 25
var additionalSpaceIfNoPadding = 1
var scale = size / sizeFactor
var padding = paddingFactor * scale
var hasNoPadding = padding === 0
var totalSize = size + (hasNoPadding ? additionalSpaceIfNoPadding * 2 : padding * 2)
var doc = new PDFDocument({size:[totalSize,totalSize]});
var stream = doc.pipe(blobStream());
const delta = hasNoPadding ? additionalSpaceIfNoPadding : padding
doc
.save()
.translate(delta, delta)
.scale(scale)
.strokeColor('#0000ff')
.path('M0 0.5h7m1 0h1m1 0h5m3 0h7M0 1.5h1m5 0h1m2 0h2m1 0h1m1 0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display the document in the iframe to the right
doc.end();
stream.on('finish', function() {
iframe.src = stream.toBlobURL('application/pdf');
});
Your environment
- pdfkit version: 0.14.0
- Node version: 18.12.0
- Browser version (if applicable): Opera 106.0.4998.28
- Operating System: Windows 10
- 主要语言
- JavaScript
- 星标
- 10.7k
- 派生
- 1.2k
- 平均合并
- 21 小时 41 分钟
- 30 天内合并 PR
- 27
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
foliojs/pdfkit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
PDFKit crashes when providing fonts as Buffer in table可能已有人在做 @ykw9263 于 131 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
foliojs/pdfkit#1743 · 13 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
foliojs/pdfkit#1512 · 1 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
维护者通常 1 天内回复
相似的 Issue
-
Handle HTTP errors when downloading release binaries可能已有人在做 @mugenkyou 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
neutralinojs/neutralinojs-cli#468 ·
维护者通常 1 天内回复
-
area:ci priority:p0 type:chore
难度 2/5 1-3 小时 新手友好度 70/100
lucacasanova/homedeck#2 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
terser/html-minifier-terser#242 ·
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 82/100
MustacheCase/zanadir#516 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
stylelint-scss/stylelint-config-standard-scss#297 · 1 条评论 ·