如何將多個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和@喬治您的幫助。 我去看看是否可以改編該腳本。 非常感謝!