cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tomservo75
Level: Powered On

Trying to convert files to PDF

I have a pretty simple flow that needs to find xls files in a folder then convert them to PDF (by printing only page 1 in portrait format). I'm starting though with just trying to convert files and save them in the same folder and am having problems. After much trial and error I arrived at the following:

1. Recurrence (I can't find any better way to trigger this because I don't want to have to add a file to a folder just to do so)

Find Files in Folder: Pattern .xls, and selected the folder where they reside.

So far it works, it finds the four .xls files in that folder.

2. So the next step I have is Apply to Each

For "select output" I have no choice but "Body"

then "convert file" file="id" target type = "pdf." I tried other things like "file name" for convert file, but all of those fail. "ID" was the only one I got to work.

 

The flow says it runs successfully but I'm not seeing the converted PDF files. I tried "Convert by file path" but it won't let me just enter the path to the .xls files, it insists on my selecting a particular file!

 

I just picked up Power Automate last week so I'm brand new to this. Can anyone point me in the right direction?

1. Find files *.xls in a particular folder

2. Print Page 1 only as PDF.

 

Also is there any way to get the flow to run manually or is it better to just do it as files are copied in to that folder? The problem is that there will be multiple folders these .xls files are saved in.

2019-11-26_15-26-32.png

 

1 REPLY 1
Super User
Super User

Re: Trying to convert files to PDF

Hi @tomservo75 

After the 'Convert File' action has run you need to add a 'Create File' action to add the converted PDF file to the desired location, for example:

a.png

The OneDrive connector will not allow you to convert a single page... you'll need to use a third party connector. An example of how to get just the first page of a PDF using the Encodian connector is detailed below:

a.png

 

A few notes on the expressioms used:

 

  • Split PDF
    • Split Configuration: you could simply use [1-1] which would return only the first page a single document in the returned array. The current [1-1], [2-999] will return two documents in the returned array... the first containing the first page and second PDF all pages from 2 to 999 or whatever is the last page.
  • Create File
    • File Name: first(body('Split_PDF')['documents'])['fileName'] - This expression gets the filename property of the first document returned in the array of documents returned by the 'Split PDF' action.
    • File Content: base64ToBinary(first(body('Split_PDF')['documents'])['fileContent']) - This expression gets the file content property of the first document returned in the array of documents returned by the 'Split PDF' action and provides in the correct format to the 'Create File' action

HTH

Jay

-------------------------------------------------------------------------

If I have answered your question, please mark your post as Solved.

If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,236)