如何使用expressjs输出pdf:
var fs = require('fs');
var PdfPrinter = require('pdfmake/src/printer');
app.get('/', function (req, res) {
var printer = new PdfPrinter();
var first = 'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines';
var dd = {
content: [
first,
'Another paragraph'
]
};
var pdfDoc = printer.createPdfKitDocument(dd);
pdfDoc.pipe(fs.createWriteStream('basics.pdf')).on('finish',function(){
//success
});
pdfDoc.end();
});
Run Code Online (Sandbox Code Playgroud) 使用 Webjobs 时如何读取文件?
试图这样做:
using (StreamReader sr = new StreamReader(VirtualPathProvider.OpenFile("~/content/file/file.txt")))
{
template = sr.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)
但是在本地运行失败
可能重复:
使用NLog记录异常时如何获取堆栈跟踪?
抛出异常以从日志中获取清晰图片的最佳做法是什么?
对于日志记录,我使用的是NLog.
以下是简单的代码:
catch (Exception ex)
{
logger.Fatal(ex.Message);
throw new Exception(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
它没有给我一个好的记录消息.我需要信息,如函数,错误代码行.
我希望通过循环遍历数组来获取连续值对:
List values = Arrays.asList("A", "B", "C");
ListIterator<String> it = values.listIterator();
while(it.hasNext()) {
String start = it.previous();
String end = it.next();
}
Run Code Online (Sandbox Code Playgroud)
如何得到:
A, B
B, C
Run Code Online (Sandbox Code Playgroud) personList如果为空或过滤结果为空,以下将抛出异常:
Person b2cInwardAllocTxs = personList.stream()
.filter(x -> x.getName().equalsIgnoreCase("Alvin"))
.findFirst().get();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Exception: java.util.NoSuchElementException: No value present
Run Code Online (Sandbox Code Playgroud)
如何解决错误?
实际上,我只是希望它应该返回一个对象或null.