cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Alicia
Level III

How to rename column for multiple PDF tables

Hi there,

 

I've wrote a script that enables me to extract a table from multiple pdf files. Each table opens and the table name is matched to the file name.

 

I've realised the format of the pdfs isn't always consistent and so the header for column 3 can be different. Therefore, I would like to incorporate a function into my script that renames column 3 as "Property" for all the tables. I've tried the Set Name() function but it's not working. Perhaps it's in the wrong place?

 

// Prepare a directory
tempdir = "C:\folder path";
// Read PDF's
file_lst = Files In Directory( tempdir );
table_lst = {};
For( i = 1, i <= N Items( file_lst ), i++,
	Insert Into( table_lst, Open( tempdir || "/" || file_lst[i], 
	PDF Tables(
		Table(
		table name(file_lst[i]),
		add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) ),
		column(table_lst[i],3) << set name("Property")
		)
	)
)
	)
	)

Any help on this would be hugely appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to rename column for multiple PDF tables

I attempted your approach, and continued to get the error. Therefore I changed to the approach that I used in my last entry. However, when I pasted it into the entry, I left a statement out of the code.

insert into( table_lst, dt );

I believe if you use the code below, it will work for you

// Prepare a directory
tempdir = "C:\folder path";
// Read PDF's
file_lst = Files In Directory( tempdir );
table_lst = {};
For( i = 1, i <= N Items( file_lst ), i++,
	dt = Open(
		tempdir || "/" || file_lst[i],
		PDF Tables(
			Table( table name( file_lst[i] ), add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) ) )
		)
	);
	insert into( table_lst, dt );
	Column( table_lst[i], 3 ) << set name( "Property" );
);
Jim

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: How to rename column for multiple PDF tables

I believe the below rework of your code will properly rename the column 

// Prepare a directory
tempdir = "C:\folder path";
// Read PDF's
file_lst = Files In Directory( tempdir );
table_lst = {};
For( i = 1, i <= N Items( file_lst ), i++,
	dt = Open(
		tempdir || "/" || file_lst[i],
		PDF Tables(
			Table( table name( file_lst[i] ), add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) ) )
		)
	);
	Column( table_lst[i], 3 ) << set name( "Property" );
);
Jim
Alicia
Level III

Re: How to rename column for multiple PDF tables

Many thanks for your reply @txnelson . Unfortunately I get the follow JMP alert when I run the script:

 

Alicia_0-1618490964525.png

 

Re: How to rename column for multiple PDF tables

Hello,

Column( table_lst[i], 3 ) << set name( "Property" );

is outside the "for" loop.

If you copy/paste it into the loop, should work.

Guillaume
Georg
Level VII

Re: How to rename column for multiple PDF tables

Balanced Parantheses are crucial,

I like very much the option "Reformat Script" (--> Edit-Menu, or crtl-m) to test for correct syntax.

 

Georg
Alicia
Level III

Re: How to rename column for multiple PDF tables

Many thanks for the help!

 

I've updated my script as below and it works however after all the tables are open the same JMP Alert comes up again.

 

Any suggestions?

Names Default To Here( 1 );

// Prepare a directory
tempdir = "C:\filepath;
// Read PDF's
file_lst = Files In Directory( tempdir );
table_lst = {};
For( i = 1, i <= N Items( file_lst ), i++,
	Insert Into(
		table_lst,
		Open(
			tempdir || "/" || file_lst[i],
			PDF Tables( Table( table name( file_lst[i] ), add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) ) ) )
		)
	);
	Column( table_lst[i], 3 ) << set name( "Property" );
)

 

Georg
Level VII

Re: How to rename column for multiple PDF tables

The colors already show you that you have not ended the string tempdir by ";

Reformating the script really helps to see this.

Georg
txnelson
Super User

Re: How to rename column for multiple PDF tables

I attempted your approach, and continued to get the error. Therefore I changed to the approach that I used in my last entry. However, when I pasted it into the entry, I left a statement out of the code.

insert into( table_lst, dt );

I believe if you use the code below, it will work for you

// Prepare a directory
tempdir = "C:\folder path";
// Read PDF's
file_lst = Files In Directory( tempdir );
table_lst = {};
For( i = 1, i <= N Items( file_lst ), i++,
	dt = Open(
		tempdir || "/" || file_lst[i],
		PDF Tables(
			Table( table name( file_lst[i] ), add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) ) )
		)
	);
	insert into( table_lst, dt );
	Column( table_lst[i], 3 ) << set name( "Property" );
);
Jim
Alicia
Level III

Re: How to rename column for multiple PDF tables

Got it working. Really appreciate all the help!