SOLVED

Power Query import using relative path of PDF file error

Copper Contributor

Hello,

I have a query that currently imports a pdf file based on a specific file name and location.  I'm trying to make the file name and location relative but keep getting an error.  I'm using Excel365.

 

This is the Source line from the hard coded pdf import:

let
Source = Pdf.Tables(File.Contents("C:\Users\User26\Documents\Projects\IG Receivable - Schools\PCR's- Adobe Extension.pdf"), [Implementation="1.3"]),

 

When I change the code in the advanced editor to the following in order to make it relative I get an stating "DataFormat.Error: External table is not in the expected format"

 

let
FolderPath = Excel.CurrentWorkbook(){[Name="FolderPath"]}[Content]{0}[Column1],
PCRFileName = Excel.CurrentWorkbook(){[Name="PCRFileName"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(FolderPath & PCRFileName), null, true),
PCRs = Source(Pdf.Tables(File.Contents((FolderPath & PCRFileName),[Implementation="1.3"])))
in
PCRs

 

I suspect the issue is with the PCRs = Source line of the code but haven't been able to figure out what.  Any suggestions?

 

Thank you

Bridgett

2 Replies
best response confirmed by Bridgett_B (Copper Contributor)
Solution

@Bridgett_B 

The first three lines of M-code should look like this:

FolderPath = Excel.CurrentWorkbook(){[Name="FolderPath"]}[Content]{0}[Column1],
PCRFileName = Excel.CurrentWorkbook(){[Name="PCRFileName"]}[Content]{0}[Column1],
Source = Pdf.Tables(File.Contents(FolderPath & PCRFileName), [Implementation="1.3"]),

Now you can navigate to the table(s) you want to extract from the PDF.

That worked perfectly!  Thank you!@Riny_van_Eekelen 

1 best response

Accepted Solutions
best response confirmed by Bridgett_B (Copper Contributor)
Solution

@Bridgett_B 

The first three lines of M-code should look like this:

FolderPath = Excel.CurrentWorkbook(){[Name="FolderPath"]}[Content]{0}[Column1],
PCRFileName = Excel.CurrentWorkbook(){[Name="PCRFileName"]}[Content]{0}[Column1],
Source = Pdf.Tables(File.Contents(FolderPath & PCRFileName), [Implementation="1.3"]),

Now you can navigate to the table(s) you want to extract from the PDF.

View solution in original post