Windows Azure托管站点上的EvoPDF库失败
PDF HTML到PDF转换库(http://www.evopdf.com/)声称它支持WindowsAzure云平台,但我无法让它工作。我得到一个例外:Windows Azure托管站点上的EvoPDF库失败,azure,evopdf,Azure,Evopdf,PDF HTML到PDF转换库(http://www.evopdf.com/)声称它支持WindowsAzure云平台,但我无法让它工作。我得到一个例外: [Exception: Could not get conversion result header. Data receive error. Could not receive data. Error code: 109] EvoPdf.HtmlToPdf.ImgConverter.GetLayoutFromUrl(String ur
[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
在库通过web请求获取HTML内容时,这看起来是失败的。Azure中是否存在阻止传出web请求的内容
库被部署为两个DLL,一个本机DLL和一个托管程序集-是否需要任何特殊的Azure配置来允许加载本机DLL?(该库确实支持xcopy部署,我在其他托管环境中也采用了这种方式)。如果问题与本机DLL有关,您可能希望尝试在中更改以下属性:
- enablenaviativecodeexecution:确保将其设置为true(默认值为true)
- executionContext:尝试将其更改为提升
<configuration>
<system.web>
<trust level="Full" />
</system.web>
</configuration>
根据我所见,您需要使用和Azure Web角色,而不是Azure网站。这些站点不支持完全信任运行
EvoPdf有一个Azure的示例项目,您可以下载该项目,该项目展示了如何使用可以运行EvoPdf dll的站点设置Web角色。EVO HTML to PDF.NET通用库直接在Azure Web角色、Azure工作者角色和Azure虚拟机中工作 对于Azure网站,您可以使用。从中复制的代码示例有:
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();
}
Include.dat文件
您是否也将evointernal.dat复制/包含到该站点?这为我解决了错误。它应该与*.dll文件位于同一文件夹中
背景:DLL+DAT文件
EVO HTML到PDF库由三个文件组成:
- EVOTHTMLTOPDF.dll
- EVOTHTMLTOPDF.xml
- evointernal.dat
请注意,更新DLL后,也要更新evointeral.dat。否则,109错误将再次发生。尝试了上述所有方法,但均无效:-(我接受答案,因为建议联系EvoPDF作者:-)您找到解决方案了吗?我也有同样的问题。界面与相同版本的原始EvoPdf完全不同…正如您在上面的代码示例中所看到的,在执行URL或HTML字符串的HTML到PDF转换时,通用库和Azure库之间没有区别。NET的通用库和Azure的库在事件处理方面可能存在一些小的API差异,但不能因此说API完全不同。