<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I import data from multiple PDF files into one table, tagged by PDF file name? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/375924#M62583</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a folder containing over 100 PDFs, all set out in a consistent format. The file name of each PDF represents a batch number which I want to utilise and in each PDF there is a particular table of data that I want to extract.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My aim is to extract the same table of data for every PDF then concatenate all the extracted data tables, tagged by PDF file name (batch number). Finally I want to split the columns in the concatenated table and group it by PDF file name to end up with a final table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’ve had a go at doing this manually and can get to the final table I need however it is extremely time-consuming as I have to open and select the table in every PDF separately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I wonder if there is some JSL that will be able to help with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m very new to scripting but have been able to create a script that gives me exactly what I need for the first two PDF files:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Opening up the first two files (Batch Number 1 &amp;amp; Batch Number 2) from the folder

Open(
	"C:\Example folder\Batch 1.pdf",
	PDF Tables(
		Table(
			table name( "Batch 1" ),
			add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) )
		)
	)
)

;

Open(
	"C:\Example folder\Batch 2.pdf",
	PDF Tables(
		Table(
			table name( "Batch 2" ),
			add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) )
		)
	)
)

;


//Concatenating the data for the first 2 batches into one table and adding a source column:

Data Table( "Batch 1" ) &amp;lt;&amp;lt; Concatenate(
	Data Table( "Batch 2" ),
	Create source column,
	Output table("Concat")
)
;


//Splitting by the concatenated table by the Characteristic column and grouping by source column (batch number) to create a Final table:


Data Table( "Concat" ) &amp;lt;&amp;lt; Split(
	Split By( :Characteristic ),
	Split( :Value ),
	Group( :Source Table ),
	Remaining Columns( Drop All ),
	Sort by Column Property,
	Output table("Final")
)

;

//Close all other tables

Close("Batch 1", no save)
;
Close("Batch 2", no save)
;
Close("Concat", no save)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to adapt this script to open all the PDF files (not just the first two) to create the Final table of data, tagged by the PDF file name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyone who can help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alicia&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 23:28:35 GMT</pubDate>
    <dc:creator>Alicia</dc:creator>
    <dc:date>2023-06-10T23:28:35Z</dc:date>
    <item>
      <title>How do I import data from multiple PDF files into one table, tagged by PDF file name?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/375924#M62583</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a folder containing over 100 PDFs, all set out in a consistent format. The file name of each PDF represents a batch number which I want to utilise and in each PDF there is a particular table of data that I want to extract.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My aim is to extract the same table of data for every PDF then concatenate all the extracted data tables, tagged by PDF file name (batch number). Finally I want to split the columns in the concatenated table and group it by PDF file name to end up with a final table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’ve had a go at doing this manually and can get to the final table I need however it is extremely time-consuming as I have to open and select the table in every PDF separately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I wonder if there is some JSL that will be able to help with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m very new to scripting but have been able to create a script that gives me exactly what I need for the first two PDF files:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Opening up the first two files (Batch Number 1 &amp;amp; Batch Number 2) from the folder

Open(
	"C:\Example folder\Batch 1.pdf",
	PDF Tables(
		Table(
			table name( "Batch 1" ),
			add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) )
		)
	)
)

;

Open(
	"C:\Example folder\Batch 2.pdf",
	PDF Tables(
		Table(
			table name( "Batch 2" ),
			add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) )
		)
	)
)

;


//Concatenating the data for the first 2 batches into one table and adding a source column:

Data Table( "Batch 1" ) &amp;lt;&amp;lt; Concatenate(
	Data Table( "Batch 2" ),
	Create source column,
	Output table("Concat")
)
;


//Splitting by the concatenated table by the Characteristic column and grouping by source column (batch number) to create a Final table:


Data Table( "Concat" ) &amp;lt;&amp;lt; Split(
	Split By( :Characteristic ),
	Split( :Value ),
	Group( :Source Table ),
	Remaining Columns( Drop All ),
	Sort by Column Property,
	Output table("Final")
)

;

//Close all other tables

Close("Batch 1", no save)
;
Close("Batch 2", no save)
;
Close("Concat", no save)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to adapt this script to open all the PDF files (not just the first two) to create the Final table of data, tagged by the PDF file name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyone who can help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alicia&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:28:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/375924#M62583</guid>
      <dc:creator>Alicia</dc:creator>
      <dc:date>2023-06-10T23:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I import data from multiple PDF files into one table, tagged by PDF file name?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/375975#M62584</link>
      <description>&lt;P&gt;If you've got two working, the code in &lt;LI-MESSAGE title="Concatenate data tables" uid="82457" url="https://community.jmp.com/t5/JSL-Cookbook/Concatenate-data-tables/m-p/82457#U82457" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; will probably get you there. FilesInDirectory() may be the function you need.&lt;/P&gt;&lt;P&gt;There are a number of similar examples; searching for Files In Directory will probably find them.&lt;/P&gt;&lt;P&gt;Ask again if that doesn't get you there, I think you are close.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 15:02:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/375975#M62584</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-04-12T15:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I import data from multiple PDF files into one table, tagged by PDF file name?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/376148#M62592</link>
      <description>&lt;P&gt;Here is an example that contains the steps you'll need. The post of &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;helps to understand how these things work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Prepare a directory
tempdir = "$TEMP\pdf_test";
If( !Directory Exists( tempdir ),
	Create Directory( tempdir ),
	file_lst = Files In Directory( tempdir );
	For( i = 1, i &amp;lt;= N Items( file_lst ), i++,
		Delete File( tempdir || "/" || file_lst[i] )
	);
);

// Open sample Table
cdt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// Prepare PDF's
For( i = 1, i &amp;lt;= 10, i++,
	jrn = cdt &amp;lt;&amp;lt; Journal;
	jrn &amp;lt;&amp;lt; save pdf( tempdir || "/" || Char( i ) || "_Big Class.pdf" );
	jrn &amp;lt;&amp;lt; close window;
);

// Read PDF's
file_lst = Files In Directory( tempdir );
table_lst = {};
For( i = 1, i &amp;lt;= N Items( file_lst ), i++,
	Insert Into( table_lst, Open( tempdir || "/" || file_lst[i], PDF All Tables() ) )
);

// Concat PDF's
If( N Items( table_lst ) &amp;gt; 1,
	result_table = table_lst[1] &amp;lt;&amp;lt; concatenate( table_lst[2 :: N Items( table_lst )], Output Table( "ResultTable" ), Create Source Column )
);
// Close single PDF's
For( i = 1, i &amp;lt;= N Items( table_lst ), i++,
	Close( table_lst[i], noSave )
);

split_table = result_table &amp;lt;&amp;lt; Split(
	Split By( :sex ),
	Group( :Source Table ),
	Split( :age ),
	Remaining Columns( Drop All ),
	Sort by Column Property, output table("Split_Result")
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Apr 2021 05:11:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/376148#M62592</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2021-04-13T05:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I import data from multiple PDF files into one table, tagged by PDF file name?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/376247#M62606</link>
      <description>&lt;P&gt;Huge thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/9474"&gt;@Georg&lt;/a&gt;&amp;nbsp;for your help. I'll have a go and see if I can adapt the script. Really appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 14:26:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-import-data-from-multiple-PDF-files-into-one-table/m-p/376247#M62606</guid>
      <dc:creator>Alicia</dc:creator>
      <dc:date>2021-04-13T14:26:28Z</dc:date>
    </item>
  </channel>
</rss>

