- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 pdfkit,并且可以成功将 pdf 上传到 S3 一次。但如果第二次尝试就会抛出此错误。
Error: write after end
at writeAfterEnd (_stream_writable.js:220:12)
at PDFReference.Writable.write (_stream_writable.js:271:5)
at PDFPage.write (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/page.js:95:27)
at PDFDocument.addContent (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/document.js:161:17)
at PDFDocument.save (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/mixins/vector.js:19:19)
at PDFDocument._fragment (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/mixins/text.js:257:12)
at PDFDocument._line (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/mixins/text.js:203:12)
at emitThree (events.js:140:20)
at LineWrapper.emit (events.js:216:7)
at /Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/line_wrapper.js:141:17
at LineWrapper.wrap (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/line_wrapper.js:207:9)
at PDFDocument._text (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/mixins/text.js:48:17)
at PDFDocument.text (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/pdfkit/js/mixins/text.js:59:19)
at /Users/jonathancorrin/Desktop/workspace/rent-app/server/routes/image-upload.js:36:6
at Layer.handle [as handle_request] (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/layer.js:95:5)
at /Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:335:12)
at next (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:174:3)
at router (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:317:13)
at /Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:335:12)
at next (/Users/jonathancorrin/Desktop/workspace/rent-app/node_modules/express/lib/router/index.js:275:10)
我不确定是什么原因导致此错误。这是我的服务器端代码
var express = require('express');
var router = express.Router();
var aws = require('aws-sdk');
var fs = require('fs');
var path = require('path');
var path3 = path.join(__dirname, "../config/config-aws.json");
var pdf = require('pdfkit');
var multer = require('multer');
var multerS3 = require('multer-s3');
var doc = new pdf;
aws.config.loadFromPath(path3);
var s3 = new aws.S3();
var fileName = '';
var uploadM = multer({
storage: multerS3({
s3: s3,
bucket: 'XXXX',
acl: 'public-read',
metadata: function (req, file, cb) {
cb(null, {fieldName: file.fieldname});
},
key: function (req, file, cb) {
fileName = Date.now().toString() + "-" + (Math.round(Math.random() * 10000000000000000)).toString() + '-' + file.originalname;
cb(null, fileName)
}
})
});
router.post('/upload/contract', function (req,res) {
doc.fontSize(21)
.text(req.body.contractType, 240, 50);
doc.fontSize(15)
.text(req.body.text, 100, 100)
.text(req.body.text2, 100, 280);
doc.end();
var params = {
Key: req.body.fileName,
Body: doc,
Bucket: 'XXXX',
ACL: 'public-read',
contentType: 'application/pdf'
};
s3.upload(params, function (err, response) {
if (err) {
return res.status(400).json({
message: "Error uploading pdf",
error: err.stack
});
}
return res.status(200).json({
title: "PDF uploaded successfully",
obj: response
});
});
});
它与 doc.end() 有关,但我不确定到底是什么。这是我发出请求的客户端代码。
onReturnPDF(html: string, fileName: string, contractType: string, html2: string) {
const body = {
fileName: fileName,
text: html,
contractType: contractType,
text2: html2
};
return this.http.post(this.devUrl + '/upload/contract', body)
.shareReplay()
}
有人知道我该如何解决这个问题吗?
最佳答案
可能是这样,因为您正在将 doc
创建为全局的。移动var doc = new pdf;
就在 doc.fontSize(21)
之前,它应该可以工作。
问题是 - 在第一次请求时 - pdf 被实例化并关闭(使用 doc.end()
)。在第二个请求中,您无法写入 pdf,因为它已经关闭(因为它没有在当前请求的上下文中实例化)
关于node.js - 错误: write after end with pdfkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45949758/
我创建了 iPhone 应用程序,在其中使用 fastpdfkit 显示 PDF 并播放音频和视频文件。 现在我也想为 Android 制作相同的应用程序。有没有适用于 Android 的套件可以让我
我安装了 pdfkit,甚至还安装了 wkhtmltopdf,但是每次我尝试创建 pdf 时都会收到以下错误。 PDFKit::NoExecutableError No wkhtmltopdf exe
我正在尝试使用 PDFKit。 它看起来相当简单,所以我试图关注 Ryan's Rails cast . 所以我将 gem 添加到我的 GemFile 并更新了我的 application.rb和:
我想知道是否有人知道如何在运行 pdfkit 时实现超时? 我正在尝试遍历大量 URL 以打印每个 URL 页面的 pdf。有时循环可能会挂起,但是如果它花费超过 30 秒,我只想跳过循环中的 URL
是否可以使用 PDFKit 在矩形上呈现文本。也许可以使用hack,用不透明度填充矩形 - 但我不想那样使用它。我的文本被矩形隐藏(我通过交替使用不同颜色的矩形创建表格)。 更新 我发现文本在某种程度
在我的应用程序中,我使用 PDFKit 来显示简单的 PDF。 PDF 显示在 ViewController 上。 PDF 要设置为屏幕宽度,仅此而已。我在 Storyboard 中将 PDFView
我有一个使用 PDFKIT 创建的 PDF View ,它在 iPad 中加载 PDF。当我们缩放 PDF 并进行一些手绘时,它会崩溃。可能是什么问题? 最佳答案 我有一个类似的问题,放大具有多个子类
我正在使用 PDFKit在浏览器中生成 PDF,然后将该 PDF 的 blob 数据发送到新选项卡以供用户下载。我真的很喜欢 PDFKit...它非常漂亮。 但是,当我尝试使用 PDFDocument
我正在尝试整合 PSPDFKit对于我的项目中的 iOS,我还没有成功。下载Demo版后,将框架添加到我的项目中,添加所有需要的库并放置 #import 在“前缀”文件上,我收到链接器错误: ld:
我一直在网上搜索使用 pdfkit(python 包装器)实现页眉和页脚的示例,但找不到任何示例。 谁能展示一些如何使用 pdfkit python 包装器在 wkhtmltopdf 中实现选项的示例
我想在 pdf 中找到一个特定的单词并在其上绘制一个边界框。为此,我使用 func findString(_ string: String, withOptions options: NSString
我正在使用 Apple 的 PDFKit,我正在使用他们的 sample app for adding a watermark到pdf文档。 除我拥有的一份 pdf 文件外,该代码按预期工作。这个特定
是否可以使用 PDFkit 将文本中的“ěščřžýáé”等字符保存为 PDF? 他们的浏览器演示在这里: http://pdfkit.org/demo/browser.html 注意:我只使用js库
如何使用 PDFKit 在 PDFView 中禁用滚动反弹? 显示 PDF 的 View 没有滚动反弹选项。 这是我的代码: if let path = Bundle.main.path(forRes
我正在尝试在 iOS 上使用 PDFKit 向文档添加高亮注释。 let highlight = PDFAnnotation(bounds: selection.bounds(for: page),
是否可以在 PDFKit 中更改 FreeText 注释的文本(即 contents)而不删除注释/构建新注释? 在 PDFView 中查看时,以下代码片段不会更改注释的内容: let url = B
使用python pdfkit生成pdf文件中遇到中文乱码问题 1.生成的文件名不能带有中文字符 2.生成的pdf内容中文为乱码 生成的文件名不能带有中文字符 解决方法: 我暂时想到的处理
如何从 pt/px 设置 characterSpacing? 如何从 pt/px 设置 lineHeight? 我只是不明白如何将点或像素转换为 pdfkit 的值。请帮帮我 https://gith
我试图了解如何让 PDF Kit 在 React JS 中工作。 我的简单要求是使用 ReactJS 和 PDFKit 在浏览器中呈现文件。 查看教程,引用了一些 PDFKit 可以在浏览器中工作的选
我想控制pdf文件的缩放级别。默认情况下,当它启动时,它不适合屏幕。即使手动(捏缩放)放大和缩小也不能使其适合页面。我已将 autoScales 设置为 true。 还尝试使用以下变量,但没有帮助
我是一名优秀的程序员,十分优秀!