Telerik Document Processing in Azure function

6 posts, 0 answers
  1. Bill
    Bill avatar
    8 posts
    Member since:
    Jun 2016

    Posted 16 Apr Link to this post

    Hi,

    In my app on azure cloud, I need to convert  docx, xlsx and html file to pdf and, I'm trailing your library. The code from this example works fine locally but when I publish it to azure I get error 500. My test function app service runs in Standard pricing tier. Are there any specific requirements?

    Thanks,

    b.

  2. Martin
    Admin
    Martin avatar
    82 posts

    Posted 21 Apr Link to this post

    Hello Bill,

    This behavior could be caused because of not properly referenced binaries.

    In order to set up your NuGet packages to work both on your local machine and in Azure, you have several options described in detail in this article: Set Up Private NuGet Feed for Azure. In the article, you will find how to set up the private NuGet feed in Azure to publish an ASP.NET Core application that references Telerik packages (in the example: Telerik UI for ASP.NET Core package).

    I hope this helps. If this is not your case, I would like to ask you to provide us with more information about the specific setup. Any additional information would be highly appreciated.

    Meanwille, do not hesitate to contact us if any additional questions arise.

    Regards,
    Martin
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  3. Bill
    Bill avatar
    8 posts
    Member since:
    Jun 2016

    Posted 21 Apr in reply to Martin Link to this post

    Hello,

    The issue on the azure function app service is that file doesn't exists:

    var finalFilePath = executionContext.FunctionAppDirectory + "\\FileResultFile.pdf"; // value on the azure is something like D:\site\wwwroot\...

    File.Create(finalFilePath) //this line produce an error

    Regards,

    Bill

  4. Bill
    Bill avatar
    8 posts
    Member since:
    Jun 2016

    Posted 21 Apr Link to this post

    I need to convert a excel Stream into a pdf Stream in an Azure function.

    I've tried using asp.net mvc dlls but they don't work in azure function. I need to use Xamarin dll's but I don't know how to import excel stream and export it into pdf stream.

    Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider doesn't have import function

    Telerik.Windows.Documents.Spreadsheet.Model doesn't exists.

    Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider doesn't have export function.

    Is it possible?

    Regards,

    Bill

    [FunctionName("GeneratePdf")]
            public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req)
            {
                Stream stream = req.Content.ReadAsStreamAsync().Result;           
     
                var formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
                var pdfFormatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
                 
                Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = formatProvider.Import(stream);
                var pdfBytes = pdfFormatProvider.Export(workbook);
                var memoryStream = new MemoryStream(pdfBytes);
     
                //Create the response to return
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    //Set the PDF document content response
                    Content = new ByteArrayContent(memoryStream.ToArray())
                };
     
                //Set the contentDisposition as attachment
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = "Output.pdf"
                };
     
                //Set the content type as PDF format mime type
                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
     
                //Return the response with output PDF stream
                return response;
            }
  5. Lance | Manager - Technical Support
    Admin
    Lance | Manager - Technical Support avatar
    1112 posts

    Posted 24 Apr Link to this post

    Hello Bill,

    At the time I wrote the blog post, we did not yet have separate NuGet packages for the new .NET Standard 2.0 Document Processing libraries, so I needed to use the DLLs that were shipped with UI for Xamarin.

    Azure functions (v3) are compiled for .NET Core (see the C# Azure Functions reference). Those assemblies you're currently using  are only for .NET Framework projects because it comes from the UI for ASP.NET MVC product (which is for ASP.NET MVC5).

    Now that you know the "why", let's move on to the "how" and get you up and running.

    Solution

    You need to instead switch to .NET Standard 2.0 versions. You can get these from a few places:

    • NuGet Packages (recommended)
    • .NET Core Product Installation folders
      • UI for ASP.NET Core - C:\Program Files (x86)\Progress\Telerik UI for ASP.NET Core [version]\dpl
      • UI for Xamarin - C:\Program Files (x86)\Progress\Telerik UI for Xamarin [version]\Binaries\Portable

    I have updated my demo code on GitHub to use the NuGet server instead, you can use that for a quick reference. Please visit LanceMcCarthy/DocProcessingFunctions.

    Updating the Project

    Let me take you through each step to fix your current project.

    1. Remove Incorrect References

    The first thing you'll want to do is delete the all the current .NET Framework DLL assembly references you have for Document Processing.

    Tip - You should not even have a visible node for "Assemblies" anymore. Typically, .NET Core projects use NuGet packages instead of assembly references.

    Step 2. NuGet Package Manager

    Open the NuGet Package Manager, switch to the Telerik NuGet server and filter the packages by "Telerik.Documents"

    Advanced Tip - You can also use an offline packages folder instead of the Telerik NuGet server (as long as you copied all the .nupkg files into it).

    3. Install the Required Document Processing Libraries packages

    Since you're using SpreadProcessing libraries, you can find the required packages in RadSpreadProcessing Getting Started documentation.  As this is .NET Core project, you need to use .NET Standard version, which is listed under the .NET STANDARD-COMPATIBLE section.

    Be sure not to miss any additional functionality. Because you're also using the PDF export, you'll need to look down a little further under the next

    Here's a screenshot to help guide you:

    The NuGet package name is the same as the assembly name, but without the .dll file extension. The end result should look like this:

    Important Note: I have .Trial in the name because this project is for GitHub public repo. You would be using the ones without the .Trial suffix instead.

    Wrapping Up

    If I was able to answer your question, you can let me know by using the thread's "Answered" button so that other folks can more easily find it for their

    If you have any further trouble or questions about the usage of the libraries in NET Core, please open a Support Ticket here (you have a priority support license with 24hr support) so that Martin and his team can assist further.

    Thank you for choosing Telerik for your project, have a great day and stay safe!

    Regards,
    Lance | Team Lead - US DevTools Support
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  6. Bill
    Bill avatar
    8 posts
    Member since:
    Jun 2016

    Posted 26 Apr in reply to Lance | Manager - Technical Support Link to this post

    Thank you Lance
Back to Top