gpt4 book ai didi

image - Azure 上的 Syncfusion PdfViewerControl

转载 作者:行者123 更新时间:2023-12-02 07:07:59 29 4
gpt4 key购买 nike

我正在利用 Syncfusion 的 PdfViewerControl 和 PdfLoadedDocument 类来生成 PDF 的缩略图。但是,当我将项目移至 Azure 应用服务后,PdfViewerControl 在初始化时会引发异常。我很好奇它是否正在尝试使用系统内存而 Azure 正在阻止此操作。下面是我创建的方法GenerateThumbnails,在创建新的PdfViewerControl 时抛出异常。如果有人解决了这个问题,或者在迁移到 Azure 时经历过类似的事情,我们将不胜感激。

除此之外,如果有人知道另一种工具可以通过这种方式从 PDF 创建缩略图,那也会非常有帮助。谢谢!

异常(exception):
System.AccessViolationException:“尝试读取或写入 protected 内存。这通常表明其他内存已损坏。'

方法:

public static List<Byte[]> GenerateThumbnails(Byte[] file)
{
Int32 resizedHeight;
Int32 resizedWidth;
List<Byte[]> thumbnails = new List<Byte[]>();

using (PdfViewerControl pdfViewerControl = new PdfViewerControl())
using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(file, true))
{
// The PDF Viewer Control must load the PDF from a PdfLoadedDocument, rather than directly from the filename because
// when loaded from the filename, it is not disposed correctly and causes a file lock.
pdfViewerControl.Load(pdfLoadedDocument);

for (Int32 i = 0; i < pdfViewerControl.PageCount; ++i)
{
using (Bitmap originalBitmap = pdfViewerControl.ExportAsImage(i))
{
if (pdfViewerControl.LoadedDocument.Pages[i].Size.Width > pdfViewerControl.LoadedDocument.Pages[i].Size.Height)
{
resizedHeight = (PdfUtility.TARGET_THUMBNAIL_WIDTH_LANDSCAPE * originalBitmap.Height) / originalBitmap.Width;
resizedWidth = PdfUtility.TARGET_THUMBNAIL_WIDTH_LANDSCAPE;
}
else
{
resizedHeight = PdfUtility.TARGET_THUMBNAIL_HEIGHT_PORTRAIT;
resizedWidth = (PdfUtility.TARGET_THUMBNAIL_HEIGHT_PORTRAIT * originalBitmap.Width) / originalBitmap.Height;
}

using (Bitmap resizedBitmap = new Bitmap(originalBitmap, new Size(resizedWidth, resizedHeight)))
using (MemoryStream memoryStream = new MemoryStream())
{
resizedBitmap.Save(memoryStream, ImageFormat.Jpeg);

thumbnails.Add(memoryStream.ToArray());
}
}
}
}

return thumbnails;
}

最佳答案

更新现在支持 Windows 上的容器 Web 应用程序。这允许您携带在沙箱外部运行的自己的 docker 容器,因此下面描述的限制不会影响您的应用程序。

应用程序运行的沙箱中存在一些限制,会阻止某些 API 调用。

Here is a list of frameworks and scenarios that have been found to be not be usable due to one or more of the restrictions above. It's conceivable that some will be supported in the future as the sandbox evolves.

PDF generators failing due to restriction mentioned above:

Syncfusion Siberix Spire.PDF The following PDF generators are supported:

SQL Reporting framework: requires the site to run in Basic or higher (note that this currently does not work in Functions apps in Consumptions mode) EVOPDF: See http://www.evopdf.com/azure-html-to-pdf-converter.aspx for vendor solution Telerik reporting: requires the site to run in Basic or higher. More info here Rotativa / wkhtmltopdf: requires the site to run in Basic or higher. NReco PdfGenerator (wkhtmltopdf): requires subscription plan Basic or higher Known issue for all PDF generators based on wkhtmltopdf or phantomjs: custom fonts are not rendered (system-installed font is used instead) because of sandbox GDI API limitations that present even in VM-based Azure Apps plans (Basic or higher).

Other scenarios that are not supported:

PhantomJS/Selenium: tries to connect to local address, and also uses GDI+.

https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox

关于image - Azure 上的 Syncfusion PdfViewerControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51954226/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com