Skip to main content

Notifications

Community site session details

Community site session details

Session Id : WbYz4fOcs5IVd5HgCw4+L1
Power Automate - Building Flows
Answered

Convert email to pdf

Like (0) ShareShare
ReportReport
Posted on 20 Dec 2021 17:14:36 by

Basically I have a very simple workflow that is supposed to be triggered by when I receiver a certain e-mail in my outlook, that then converts the e-mail to a PDF and updates it to a sharepoint file library.

 

I have done this workflow before with other e-mails and it has worked fine. Attached are screen shots. I have tried two things one where I specify the file’s extension as .html and another one as a .eml. Both yield errors.

 

When I specify HTML the workflow runs for a while. And then gives me this error:  Error 502 Gateway:

 

{

  "error": {

    "code": 502,

    "source": "flow-apim-msmanaged-na-northcentralus-01.azure-apim.net",

    "clientRequestId": "722875f0-b6ea-4d77-b3df-d2695ab6b2bd",

    "message": "BadGateway",

    "innerError": {

      "status": 502,

      "message": "IndexOutOfRangeException: Index was outside the bounds of the array.\nInnerExceptionMessage: \nStackTrace:    at System.String.get_Chars(Int32 index)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.CssParser.ParseFontFamilyProperty(String propValue)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.CssParser.ParseFontFamily(String value)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.TranslateAttributes(HtmlTag tag, CssBox box)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeApplyStyles(CssBox box, CssData cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.GenerateCssTree(String html, HtmlContainerInt htmlContainer, CssData& cssData)\r\n   at TheArtOfDev.HtmlRenderer.Core.HtmlContainerInt.SetHtml(String htmlSource, CssData baseCssData)\r\n   at TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.AddPdfPages(PdfDocument document, String html, PdfGenerateConfig config, CssData cssData, EventHandler`1 stylesheetLoad, EventHandler`1 imageLoad)\r\n   at TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(String html, PageSize pageSize, Int32 margin, CssData cssData, EventHandler`1 stylesheetLoad, EventHandler`1 imageLoad)\r\n   at OneDrive.Media.Transforms.Rasterizers.HtmlToPdfConverter.<>c__DisplayClass12_1.<GenerateStream>b__1() in C:\\source\\Transforms\\PdfConverters\\HtmlToPdfConverter.cs:line 83\r\n   at OneDrive.Media.Utilities.MemoryStreamHelper.ExecuteAndDisposeStreamIfErrorOccurs(Stream outputStream, Action method) in C:\\source\\Utilities\\MemoryStreamHelper.cs:line 62\r\n   at OneDrive.Media.Transforms.Rasterizers.HtmlToPdfConverter.<>c__DisplayClass12_0.<GenerateStream>b__0() in C:\\source\\Transforms\\PdfConverters\\HtmlToPdfConverter.cs:line 101\r\n   at OneDrive.Media.Transforms.Rasterizers.HtmlRasterizer.ExecuteMethod(Func`1 method) in C:\\source\\Transforms\\Rasterizers\\HtmlRasterizer.cs:line 110\r\n   at OneDrive.Media.Transforms.Rasterizers.HtmlToPdfConverter.<GeneratePdfAsync>d__11.MoveNext() in C:\\source\\Transforms\\PdfConverters\\HtmlToPdfConverter.cs:line 58\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at OneDrive.Media.Utilities.Sandbox.SandboxService.<RunRequestAsync>d__1.MoveNext() in C:\\source\\Sandbox\\SandboxService.cs:line 85\n ThrowSite: ",

      "source": "api.connectorp.svc.ms"

    }

  }

}

 

 

When I specify it as a .eml it errors at the same step with a different error:  Conversion of this file to PDF is not supported. (Sandbox_BadArgument_Argument / Invalid destination page in call to CreateDocumentLink: page number is one-based and must be 1 or higher.)

 

Screenshots of flow

 

112233

 

  • Verified answer
    v-jefferni Profile Picture
    on 23 Dec 2021 at 07:17:02
    Re: Convert email to pdf

    Hi @SharePointNinja ,

     

    Please refer to below thread:

    https://powerusers.microsoft.com/t5/Building-Flows/save-email-as-pdf/td-p/109005

     

    In addition, the compose action is not necessary in your case, you may try change the file name from the output of compose to a fixed value such as the Email subject, and check if it is the output of compose caused the problems.

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • NuttyPistons Profile Picture
    398 on 20 Dec 2021 at 17:25:45
    Re: Convert email to pdf

    Hi @SharePointNinja ,

     

    You shouldn't need the compose step above, and you can use .msg as the file extension. This test flow seemed to do the trick for me:

    NuttyPistons_0-1640021056972.png


    If this solved your problem, please Accept this post as the solution.



Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard
Loading started
Loading complete