導入多個pdf文件警告:我是編碼新手!
我大約有500個pdf文件,其中包含要導入的列表數據。 我設法創建了一個腳本,該腳本將提取,堆疊和轉置數據,並將其附加/連接到表(我稱之為“ final.jmp ”)。 每個pdf在其中以一行表示final.jmp 。 現在是工作流程和問題我確定:
- 由於我不知道如何導入多個pdf,因此我不得不通過更改要在腳本中嵌入的* .pdf文件名來單獨導入每個pdf(嵌入在final.jmp) 。
- 每次導入後,我必須關閉在該過程中創建和打開的所有中間表,並將結果表另存為新表。 final.jmp 。
- 然後我重新打開final.jmp ,將腳本編輯為新的pdf文件名,導入新的pdf等,依此類推。
我的問題:
是否可以以重複的方式運行腳本,每次選擇一個新的pdf,直到將文件夾中的所有pdf都導入並整理到最終表中為止?
Open(
"C:\example folder\example.pdf",
PDF Tables(
Table(
table name( "1" ),
add rows( page( 1 ), Rect( 2.0419, 0.9776, 3.1993, 1.1726 ) ),
add rows( page( 1 ), Rect( 1.2137, 3.7819, 6.3603, 3.9069 ) ),
add rows( page( 1 ), Rect( 0.8717, 3.9636, 3.0796, 4.0886 ) ),
add rows(
page( 1 ),
Rect( 0.9853, 4.1436, 3.0029, 4.2686 ),
column borders( 0.9853, 2.5172, 3.0029 )
),
add rows( page( 1 ), Rect( 4.581, 4.1436, 7.297, 4.2686 ) ),
add rows(
page( 1 ),
Rect( 0.8883, 4.4136, 4.6374, 4.5386 ),
column borders( 0.8883, 1.9603, 4.6374 )
),
add rows( page( 1 ), Rect( 0.7556, 4.7979, 7.5908, 8.2654 ) )
)
)
);
Data Table( "1" ) << Stack(
columns( :Column 3, :Column 4, :Column 5, :Column 6 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output table("2")
);
Data Table( "2" ) << Transpose(
columns( :Data ),
Output Table( "Final" )
)
數據表腳本編寫回复:導入多個pdf文件可能的流程:
- 創建處理單個pdf文件的功能
- 獲取目錄pdf目錄中的所有文件
- 使用目錄中的第一個文件創建“收集器”數據表
- 循環瀏覽其余文件
- 將轉置表連接到創建的收集器數據表,並在之後關閉
也許這樣的事情可能會起作用:
Names Default To Here(1);
//directory where .pdf files exist
pdfDirectory = "C:\example folder\";
//function to open stack and transpose pdf file
stackTransposePdfFile = function({filePath}, {Default Local},
dtTemp = Open(
filePath,
PDF Tables(
Table(
table name("1"),
add rows(page(1), Rect(2.0419, 0.9776, 3.1993, 1.1726)),
add rows(page(1), Rect(1.2137, 3.7819, 6.3603, 3.9069)),
add rows(page(1), Rect(0.8717, 3.9636, 3.0796, 4.0886)),
add rows(page(1), Rect(0.9853, 4.1436, 3.0029, 4.2686), column borders(0.9853, 2.5172, 3.0029)),
add rows(page(1), Rect(4.581, 4.1436, 7.297, 4.2686)),
add rows(page(1), Rect(0.8883, 4.4136, 4.6374, 4.5386), column borders(0.8883, 1.9603, 4.6374)),
add rows(page(1), Rect(0.7556, 4.7979, 7.5908, 8.2654))
)
)
);
//stack data table from pdf
dtTemp_stacked = dtTemp << Stack(
columns(:Column 3, :Column 4, :Column 5, :Column 6),
Source Label Column("Label"),
Stacked Data Column("Data"),
invisible
);
Close(dtTemp, no save); //close table created directly from pdf
//transpose table
dtTemp_transposed = dtTemp_stacked << Transpose(columns(:Data), invisible);
Close(dtTemp_stacked no save); //close stacked table
//return transposed table
return(dtTemp_transposed);
);
//list of files in directory (this assumes that there are only .pdf files)
pdfFile_list = Files In Directory(pdfDirectory);
//use the first table as "collection table"
finalDt = stackTransposePdfFile(pdfDirectory||pdfFile_list[1]);
//loop over files in pdfFile_list starting from second file
For(i = 2, i <= N Items(pdfFile_list), i++,
pdfDt = stackTransposePdfFile(pdfDirectory||pdfFile_list[i]);
finalDt << Concatenate(pdfDt, Append to first table);
Close(pdfDt, no save); //close transposed table
);