cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate IV
Advocate IV

Convert File - PreconditionFailed

Getting the error "PreconditionFailed" when using Convert File to create a PDF from HTML

The HTML renders as expected but the file contains inline images and is over 2MB

 

{
  "status": 412,
  "message": "The html content length cannot be greater than 2 MB\nInnerExceptionMessage: \nStackTrace:    at OneDrive.Media.Transforms.Rasterizers.HtmlRasterizer.ValidateLength(String htmlContent, Int64 maxLength) in C:\\agent\\1\\_work\\1\\s\\Transforms\\Rasterizers\\HtmlRasterizer.cs:line 202\r\n   at OneDrive.Media.Transforms.Rasterizers.HtmlRasterizer.<>c__DisplayClass18_0.<Generate>b__0() in C:\\agent\\1\\_work\\1\\s\\Transforms\\Rasterizers\\HtmlRasterizer.cs:line 120\r\n   at OneDrive.Media.Utilities.MemoryStreamHelper.ExecuteAndDisposeStreamIfErrorOccurs(Stream outputStream, Action method) in C:\\agent\\1\\_work\\1\\s\\Utilities\\MemoryStreamHelper.cs:line 58\r\n   at OneDrive.Media.Transforms.Rasterizers.HtmlRasterizer.Generate(String htmlContent, ConvertHtmlParameters parameters) in C:\\agent\\1\\_work\\1\\s\\Transforms\\Rasterizers\\HtmlRasterizer.cs:line 114\r\n   at OneDrive.Media.Transforms.Rasterizers.HtmlRasterizer.<ConvertHtmlAsync>d__17.MoveNext() in C:\\agent\\1\\_work\\1\\s\\Transforms\\Rasterizers\\HtmlRasterizer.cs:line 98\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.Transforms.Rasterizers.HtmlRasterizer.<ConvertWithinSandboxAsync>d__16.MoveNext() in C:\\agent\\1\\_work\\1\\s\\Transforms\\Rasterizers\\HtmlRasterizer.cs:line 83\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:\\agent\\1\\_work\\1\\s\\Sandbox\\SandboxService.cs:line 55\n ThrowSite: ",
  "source": "api.connectorp.svc.ms"
}

 

Has anyone got a work around for this?

2MB is a too small to be workable for my use case 

 

1 ACCEPTED SOLUTION

Accepted Solutions

I saw that solution as well but my HTML is very complicated with lots of dynamic stuff, so a word template would not be a solution...

However, I just came upon this:
https://blog.encodian.com/2019/08/the-html-content-length-cannot-be-greater-than-2-mb/

Will test it soon

View solution in original post

8 REPLIES 8
Community Support
Community Support

Hi @AFD256,

 

I am afraid that you may have to reduce the content length within the limit.

Besides, I would suggest you post a request on Flow Ideas Forum to ask for removing 2MB content length limit at here:

https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

I will suggest other customers who have the same request to vote your idea as well.

 

Best regards,

Mabel

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Posted on the Ideas forum

 

I can't reduce the content of the file - that would defeat the purpose of having a dynamic report that could contain multiple embeded images 

Could you share the link to the Flow Idea in the forum? I can't find it but would love to vote for it... it's been a year since your original post and I still have the same problem...

https://powerusers.microsoft.com/t5/Power-Automate-Ideas/Remove-the-2mb-limit-for-Convert-File/idi-p...

 

It might not be a straight swap - but if you can, look at the using (Premium) Word Connector for populating Word Templates and then making PDFs 

I saw that solution as well but my HTML is very complicated with lots of dynamic stuff, so a word template would not be a solution...

However, I just came upon this:
https://blog.encodian.com/2019/08/the-html-content-length-cannot-be-greater-than-2-mb/

Will test it soon

View solution in original post

Looks good, only question is if there a subscription/usage cost for the Encodian connectors?

 

Other options are:

Plumsail offer a paid solution for generating PDFs from HTML

Hacking something together in Azure with WIKIHTMLtoPDF and a HTTP function call

It seems like there is a subscription, but also a free offer limited to 50 actions per month, all Encodian options included.

Well, this dosn't suit my needs, but some may only need a couple of actions per month so give it a try

Frequent Visitor

Hi,

 

I have been waiting for this too but meanwhile I found a work around which works for me. Please use if it works for you:

The key step is to embed Java script provided here into your HTML which adds a "save as PDF" button at the end of your HTML. Then,

 

1) Seperate flow into 2 branches after convert HTML to PDF.

2) If convert succeeds, go with the regular flow.

3) If it fails, send HTML as attachment and (optionally embed that HTML as body) then use Save as PDF button in the HTML to save it as PDF easily.

 

Again, in my case, users need the PDF emailed. So, even if I email them the HTML with a save as PDF button, my users wouldn't mind clicking it and save it. If this works for you, please do use it that way until the 2MB limitation is lifted.  

Helpful resources

Announcements
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (9,554)