EvoPDF HTML到PDF转换库(http://www.evopdf.com/)声称它支持Windows Azure云平台,但我无法让它工作。我得到了例外:
[Exception: Could not get conversion result header. Data receive error. Could not receive data. Error code: 109]
EvoPdf.HtmlToPdf.ImgConverter.GetLayoutFromUrl(String url, ps& htmlParseInfo) +622
EvoPdf.HtmlToPdf.PdfConverter.ConvertAndGetPdfDocument(String url, String htmlString, String baseUrl, String internalLinksDocUrl, Boolean fromUrl) +9748
EvoPdf.HtmlToPdf.PdfConverter.ConvertAndSaveToStream(Stream outStream, String url, String htmlString, String baseUrl, String internalLinksDocUrl, Boolean fromUrl) +61
EvoPdf.HtmlToPdf.PdfConverter.SavePdfFromUrlToStream(String url, Stream outPdfStream) +20
这看起来像是在图书馆通过网络请求获取HTML内容时失败了。 Azure中是否存在阻止传出Web请求的任何内容?
该库被部署为两个DLL,一个本机DLL和一个托管程序集 - 是否需要任何特殊的Azure配置才能加载本机DLL? (该库确实支持xcopy部署,我在其他托管环境中以这种方式工作)。
答案 0 :(得分:4)
从我可以看到您需要使用Azure Web角色而不是Azure Web站点。这些网站不支持以完全信任方式运行。
EvoPdf有一个Azure示例项目,您可以下载该项目,演示如何使用可以运行EvoPdf dll的站点设置Web角色。
答案 1 :(得分:0)
如果问题与您的原生DLL相关,您可能需要尝试更改ServiceDefinition.csdef中的以下属性:
您是否部署了64位版本的DLL?
我也在错误信息中看到“错误代码:109 ”,你能不能联系EvoPDF询问这意味着什么?
更新:如果您在ASP.NET中运行,是否可以尝试更改信任级别?
<configuration>
<system.web>
<trust level="Full" />
</system.web>
</configuration>
答案 2 :(得分:0)
适用于.NET的EVO HTML to PDF通用库可直接在Azure Web角色,Azure辅助角色和Azure虚拟机中使用。
对于Azure网站,您可以使用EVO HTML to PDF for Azure Websites solution。从那里复制的代码示例是:
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Get the server IP and port
String serverIP = textBoxServerIP.Text;
uint serverPort = uint.Parse(textBoxServerPort.Text);
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, serverPort);
// Set optional service password
if (textBoxServicePassword.Text.Length > 0)
htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text;
// Set HTML Viewer width in pixels which is the equivalent in converter of the browser window width
htmlToPdfConverter.HtmlViewerWidth = int.Parse(htmlViewerWidthTextBox.Text);
// Set HTML viewer height in pixels to convert the top part of a HTML page
// Leave it not set to convert the entire HTML
if (htmlViewerHeightTextBox.Text.Length > 0)
htmlToPdfConverter.HtmlViewerHeight = int.Parse(htmlViewerHeightTextBox.Text);
// Set PDF page size which can be a predefined size like A4 or a custom size in points
// Leave it not set to have a default A4 PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = SelectedPdfPageSize();
// Set PDF page orientation to Portrait or Landscape
// Leave it not set to have a default Portrait orientation for PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = SelectedPdfPageOrientation();
// Set the maximum time in seconds to wait for HTML page to be loaded
// Leave it not set for a default 60 seconds maximum wait time
htmlToPdfConverter.NavigationTimeout = int.Parse(navigationTimeoutTextBox.Text);
// Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
// Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
if (conversionDelayTextBox.Text.Length > 0)
htmlToPdfConverter.ConversionDelay = int.Parse(conversionDelayTextBox.Text);
// The buffer to receive the generated PDF document
byte[] outPdfBuffer = null;
if (convertUrlRadioButton.Checked)
{
string url = urlTextBox.Text;
// Convert the HTML page given by an URL to a PDF document in a memory buffer
outPdfBuffer = htmlToPdfConverter.ConvertUrl(url);
}
else
{
string htmlString = htmlStringTextBox.Text;
string baseUrl = baseUrlTextBox.Text;
// Convert a HTML string with a base URL to a PDF document in a memory buffer
outPdfBuffer = htmlToPdfConverter.ConvertHtml(htmlString, baseUrl);
}
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("{0}; filename=Getting_Started.pdf; size={1}",
openInlineCheckBox.Checked ? "inline" : "attachment", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}