- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在使用 EVOPdf 从 WebAPI Controller 向 AngularJS 应用程序呈现 PDF 时遇到问题。
到目前为止,这是我的代码:
Angular 调用:
var url = 'api/form/build/' + id;
$http.get(url, null, { responseType: 'arraybuffer' })
.success(function (data) {
var file = new Blob([data], { type: 'application/pdf' });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(file);
}
else {
var objectUrl = URL.createObjectURL(file);
window.open(objectUrl);
}
});
APIController 方法:
var url = "http://localhost/index.html#/form/build/" + id;
#region PDF Document Setup
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
//htmlToPdfConverter.HtmlViewerWidth = 1024; //default
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait;
htmlToPdfConverter.ConversionDelay = 3;
htmlToPdfConverter.MediaType = "print";
htmlToPdfConverter.PdfDocumentOptions.LeftMargin = 10;
htmlToPdfConverter.PdfDocumentOptions.RightMargin = 10;
htmlToPdfConverter.PdfDocumentOptions.TopMargin = 10;
htmlToPdfConverter.PdfDocumentOptions.BottomMargin = 10;
htmlToPdfConverter.PdfDocumentOptions.TopSpacing = 10;
htmlToPdfConverter.PdfDocumentOptions.BottomSpacing = 10;
htmlToPdfConverter.PdfDocumentOptions.ColorSpace = ColorSpace.RGB;
// Set HTML content destination in PDF page
htmlToPdfConverter.PdfDocumentOptions.Width = 640;
htmlToPdfConverter.PdfDocumentOptions.FitWidth = true;
htmlToPdfConverter.PdfDocumentOptions.StretchToFit = true;
#endregion
byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(url);
string outPdfFile = @"c:\temp\forms\" + id + ".pdf";
System.IO.File.WriteAllBytes(outPdfFile, outPdfBuffer);
HttpResponseMessage result = null;
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new ByteArrayContent(outPdfBuffer.ToArray());
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = "filename.pdf";
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return result;
当我检查我使用 WriteAllBytes
写出的 PDF 时,它呈现完美,但是当它通过 Angular 调用返回并在 Adobe Reader 中打开时,我得到一个 “无效的色彩空间" 多次弹出错误消息,但文档未打开。当我将色彩空间更改为 GrayScale 时,PDF 打开但它是空白的。
我感觉是 ByteArrayContent
转换导致了这个问题,被认为是实际创建 PDF 并将其发送回 Angular 调用之间唯一发生的事情,但我碰壁了,想不通是什么问题。
我非常感谢你们能提供的任何帮助,因为我已经快要解决这个问题了,我只需要在电话返回时正确“转换”文档。
在此先感谢您的帮助。
问候,约翰。
最佳答案
问题似乎出在客户端,响应中的字符未正确解析。对于任何为此苦苦挣扎的人,我在这里找到了我的解决方案:SO Question
关于javascript - 使用 EVOPdf、WebAPI 和 AngularJS 生成 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31934297/
我正在尝试使用 evoPDF dll 将 URL 转换为 pdf。当我在本地机器上执行它时运行良好,但每次托管在 IIS 服务器上时都会失败。错误如下。 加载 HTML 错误或导航超时。 任何关于此失
我知道可以使用 C# API 在页眉/页脚中呈现“Y 页 X”,如下所示: //write the page number TextElement footerText = new TextEleme
EvoPDF HTML 到 PDF 转换库 (http://www.evopdf.com/) 声称它支持 Windows Azure 云平台,但我无法让它工作。我得到了异常(exception): [
我在使用 EVOPdf 从 WebAPI Controller 向 AngularJS 应用程序呈现 PDF 时遇到问题。 到目前为止,这是我的代码: Angular 调用: var url = 'a
将 EvoPDF 用于 .Net Web 应用程序可以在本地运行,但是一旦部署到 Microsoft Azure 网站,它就会抛出一般异常:“无法呈现 html”。 堆栈跟踪: [Exception:
将 EvoPDF 用于 .Net Web 应用程序可以在本地运行,但是一旦部署到 Microsoft Azure 网站,它就会抛出一般异常:“无法呈现 html”。 堆栈跟踪: [Exception:
我正在尝试在 Azure Web 应用程序上使用 evoPDF HTML 到 PDF 转换器,但我似乎遇到了仅在通过 HTTPS 访问站点时才会出现的问题。 我的 azure 部署安装了我的 SSL
我正在使用 EvoPDf(版本 6.10)的示例代码在 MVC 中将 Html 转换为 PDF。代码如下所示。 byte[] outPdfBuffer = htmlToPdfConverter.Con
我是一名优秀的程序员,十分优秀!