jsreport
및 phantom pdf recipe
을 사용하여보기를 ASP.NET Core
의 pdf로 렌더링합니다. 프로젝트는 Azure
에서 App Service
으로 실행됩니다. 내 로컬 컴퓨터에서 제대로 작동하지만, Azure
에 게시하면 아래 오류 메시지가 표시됩니다.ASP.NET 코어 Azure의 Phantom pdf
Exception: Call to Node module failed with error: ReferenceError: e is not defined at module.exports (D:\home\site\wwwroot\serviceCallDetailsPdf.js:18:26)
여기 내 프로젝트 (wwwroot에, 뷰, 컨트롤러와 같은 디렉토리 수준 등)의 루트에 내 js
파일입니다.
module.exports = function (callback, html, htmlFooter) {
var jsreport = require('jsreport-core')();
jsreport.init().then(function() {
return jsreport.render({
template: {
content: html,
engine: 'jsrender',
recipe: 'phantom-pdf',
phantom: {
orientation: "landscape",
allowLocalFilesAccess: true,
footer: htmlFooter
}
}
}).then(function (resp) {
callback(/* error */ null, resp.content.toString());
});
}).catch(function (e) {
callback(/* error */ e, null);
});
callback(/* error */ e, null);
};
참고 : 마지막 콜백은 일반적으로 존재하지 않습니다. 제거하면 Node.js 모듈의 변경 내용이 60000 밀리 초 후에 시간 초과되고 물론 표시하려면 60 초가 걸립니다.
내가 그렇지 않으면 내가Node.js
내가 부르고 파일을 미세 없습니다라고 오류가 발생하는 것입니다
publishOptions
에
*.js
및
node_modules
을 포함하는 내
project.json
파일을 업데이트했다. 나는 이것이 적절한 방법이 아니라는 것을 안다. (내가 필요로하는 것만 복사하기 위해 Gulp을 사용해야하지만, 나는 그것을 먼저 작동시키고 싶다).
나는 ConfigureServices
-services.AddNodeServices();
및 project.json
에도 "Microsoft.AspNetCore.NodeServices": "1.1.0"
을 추가했습니다. 여기
자동으로 생성 된 내 package.json
파일입니다
{
"name": "projectname",
"version": "1.0.0",
"description": "",
"main": "serviceCallDetailsPdf.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jsreport-core":"1.1.1",
"jsreport-jsrender": "1.0.1",
"jsreport-phantom-pdf": "1.3.1"
}
}
여기, 마지막으로 내 Action
:
[HttpGet]
public async Task<IActionResult> ServiceCallDetailsToPdf(int id)
{
var call = _repository.PullCallDetails(id, User.Identity.RegionId(), User.Identity.TimeZoneOffsetId());
// Render view as string
var html = await _viewRenderService.RenderToStringAsync("Render/ServiceCallDetailsPdf", call);
html = html.Replace("<style></style>", @"<style>@font-face{font-family:'Open Sans';src:url({#asset OpenSans-Regular.ttf @encoding=dataURI});format('ttf');}*{font-family:'Open Sans';}h2{font-weight:300;line-height:1.1;}</style>");
var htmlFooter = "<style>*{font-family:'Open Sans';text-align:center;}</style>" + "Page {#pageNum} of {#numPages}";
// Invoke node job to create the pdf
var result = await _nodeServices.InvokeAsync<byte[]>("./serviceCallDetailsPdf", html, htmlFooter);
// Content disposition 'inline' will return the pdf to the browser and not download it
var contentDisposition = new ContentDispositionHeaderValue("inline");
// Add file name to content disposition so if it is downloaded, it uses the correct file name
contentDisposition.SetHttpFileName("dispatch" + id.ToString() + ".pdf");
Response.Headers[HeaderNames.ContentDisposition] = contentDisposition.ToString();
return File(result, "application/pdf");
}
가 호출되는 javascript
파일을 디버깅 할 수 있습니까? 나는 이것이 작동하지 않는 이유를 알아 내려고 며칠 동안 많은 시간을 보냈습니다. 어떤 도움이라도 대단히 감사하겠습니다.
업데이트
나는이 링크에서 내 대답을 찾을 생각 :
https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox
이것은 기본적으로 당신이에서 팬텀 PDF 조리법을 사용할 수 없습니다 의미를 Azure App 서비스. 다른 사람이 확인할 수 있습니까? 이 경우 Azure App 서비스에서 작동하는 html to pdf 렌더러를 아는 사람이 있습니까?
귀하는 이미 연결된 다른 질문을 통해 답변을 찾았습니다 (기본적으로이 질문의 사본입니다). 웹 응용 프로그램에서는 ActiveX/GDI/등을 사용할 수 없습니다. –