如何将多个PDF文件中的数据导入到一个表中,并用PDF文件名标记?你好呀,
我有一个包含100多个PDF的文件夹,所有PDF都以一致的格式列出。 每个PDF的文件名代表我要利用的批号,并且在每个PDF中都有要提取的特定数据表。
我的目的是为每个PDF提取相同的数据表,然后连接所有提取的数据表,并以PDF文件名(批号)标记。 最后,我想拆分连接表中的列,并按PDF文件名将其分组以得到最终表。
我可以手动进行操作,并且可以进入我需要的最终表,但是这非常耗时,因为我必须分别打开并选择每个PDF中的表。
因此,我想知道是否有一些JSL可以帮助您解决此问题?
我刚开始编写脚本,但是能够创建一个脚本,该脚本可以为我提供前两个PDF文件的确切需求:
//Opening up the first two files (Batch Number 1 & 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" ) << 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" ) << 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)我需要修改此脚本以打开所有PDF文件(而不仅仅是前两个文件)以创建以PDF文件名标记的最终数据表。
有谁可以帮助我吗?
非常感谢,
艾丽西亚(Alicia)
数据表脚本编写回复:如何将多个PDF文件中的数据导入到一个表中,并用PDF文件名标记?如果您有两个工作,那么其中的代码串联数据表可能会带你到那里。 FilesInDirectory()可能是您需要的功能。
有许多类似的例子。在目录中搜索文件可能会找到它们。
再问一遍,那是否还不能解决您的问题,我认为您已经接近了。
回复:如何将多个PDF文件中的数据导入到一个表中,并用PDF文件名标记?这是一个包含所需步骤的示例。 的职位@Craige_Hales有助于了解这些事物的工作方式。
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 <= 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 <= 10, i++,
jrn = cdt << Journal;
jrn << save pdf( tempdir || "/" || Char( i ) || "_Big Class.pdf" );
jrn << close window;
);
// 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 All Tables() ) )
);
// Concat PDF's
If( N Items( table_lst ) > 1,
result_table = table_lst[1] << concatenate( table_lst[2 :: N Items( table_lst )], Output Table( "ResultTable" ), Create Source Column )
);
// Close single PDF's
For( i = 1, i <= N Items( table_lst ), i++,
Close( table_lst[i], noSave )
);
split_table = result_table << Split(
Split By( :sex ),
Group( :Source Table ),
Split( :age ),
Remaining Columns( Drop All ),
Sort by Column Property, output table("Split_Result")
);回复:如何将多个PDF文件中的数据导入到一个表中,并用PDF文件名标记?非常感谢@Craige_Hales和@乔治您的帮助。 我去看看是否可以改编该脚本。 非常感谢!