Browse Source

pdf图层完善

master
review512jwy@163.com 1 month ago
parent
commit
afaa54caf7
  1. 65
      test-convert.ps1
  2. 168
      test-probe.ps1

65
test-convert.ps1

@ -1,65 +0,0 @@
# テスト用スクリプト - Convert-Pdf.ps1のテスト実行
# 現在のプロジェクトのJARファイルを使用したテスト
$jarPath = "build\libs\pdf-memo-layers.jar"
$samplesDir = "samples"
Write-Host "=== Convert-Pdf.ps1 テスト実行 ===" -ForegroundColor Green
# JARファイルの存在確認
if (-not (Test-Path $jarPath)) {
Write-Host "エラー: JARファイルが見つかりません: $jarPath" -ForegroundColor Red
Write-Host "まず 'gradlew build' または 'gradlew fatJar' を実行してください" -ForegroundColor Yellow
exit 1
}
# サンプルディレクトリの存在確認
if (-not (Test-Path $samplesDir)) {
Write-Host "エラー: samplesディレクトリが見つかりません" -ForegroundColor Red
exit 1
}
# 1. DryRunテスト
Write-Host "`n1. DryRunテスト実行中..." -ForegroundColor Cyan
.\Convert-Pdf.ps1 `
-RootDir $samplesDir `
-Converter "java -jar `"$jarPath`" --in `"{input}`" --out `"{output}`"" `
-DryRun
# 2. 実際の変換テスト(単一ファイル処理)
Write-Host "`n2. 実際の変換テスト(順次処理)..." -ForegroundColor Cyan
.\Convert-Pdf.ps1 `
-RootDir $samplesDir `
-Converter "java -jar `"$jarPath`" --in `"{input}`" --out `"{output}`"" `
-Concurrency 1 `
-Log "convert-test.log"
# 3. 並列処理テスト
Write-Host "`n3. 並列処理テスト..." -ForegroundColor Cyan
.\Convert-Pdf.ps1 `
-RootDir $samplesDir `
-Converter "java -jar `"$jarPath`" --in `"{input}`" --out `"{output}`"" `
-Concurrency 2 `
-Log "convert-parallel-test.log" `
-Force
# 4. 出力先指定テスト
Write-Host "`n4. 出力先指定テスト..." -ForegroundColor Cyan
$outputDir = "test-output"
if (Test-Path $outputDir) {
Remove-Item $outputDir -Recurse -Force
}
.\Convert-Pdf.ps1 `
-RootDir $samplesDir `
-Converter "java -jar `"$jarPath`" --in `"{input}`" --out `"{output}`"" `
-OutputRoot $outputDir `
-Log "convert-output-test.log"
Write-Host "`n=== テスト完了 ===" -ForegroundColor Green
Write-Host "生成されたファイルを確認してください:" -ForegroundColor Yellow
Write-Host "- samplesディレクトリ内の *.converted.pdf ファイル"
Write-Host "- test-outputディレクトリ内のファイル"
Write-Host "- ログファイル: convert-*.log"

168
test-probe.ps1

@ -1,168 +0,0 @@
# PDF解析ツール(PdfProbeApp)のテスト用スクリプト
Write-Host "=== PDF解析ツール テスト実行 ===" -ForegroundColor Green
# JARファイルのパス
$probeJarPath = "build\libs\pdf-probe.jar"
$samplesDir = "samples"
# JARファイルの存在確認
if (-not (Test-Path $probeJarPath)) {
Write-Host "JARファイルが見つかりません。ビルドを実行します..." -ForegroundColor Yellow
# Gradleビルドを実行してJARファイルを作成
try {
Write-Host "Gradleビルド実行中..." -ForegroundColor Cyan
$env:JAVA_TOOL_OPTIONS = "-Dfile.encoding=UTF-8"
# 既存のクラスファイルを使ってJARを作成
Write-Host "JARファイル作成中..." -ForegroundColor Cyan
# probeJarタスクを実行
if (Test-Path "gradlew.bat") {
& .\gradlew.bat probeJar 2>$null
} else {
# 手動でJARファイルを作成
$buildLibsDir = "build\libs"
if (-not (Test-Path $buildLibsDir)) {
New-Item -Path $buildLibsDir -ItemType Directory -Force | Out-Null
}
# クラスファイルとライブラリからJARを作成
Write-Host "手動でJARファイルを作成中..." -ForegroundColor Cyan
# Manifestファイルを作成
$manifestContent = @"
Manifest-Version: 1.0
Main-Class: co.jp.techsor.pdf.PdfProbeApp
"@
$manifestPath = "build\MANIFEST.MF"
$manifestContent | Out-File -FilePath $manifestPath -Encoding UTF8
# PowerShellでJARファイルを作成(zipコマンドの代替)
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (Test-Path $probeJarPath) {
Remove-Item $probeJarPath -Force
}
$archive = [System.IO.Compression.ZipFile]::Open($probeJarPath, [System.IO.Compression.ZipArchiveMode]::Create)
# クラスファイルを追加
$classesDir = "build\classes"
if (Test-Path $classesDir) {
Get-ChildItem -Path $classesDir -Recurse -File | ForEach-Object {
$relativePath = $_.FullName.Substring((Resolve-Path $classesDir).Path.Length + 1)
$relativePath = $relativePath.Replace('\', '/')
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, $_.FullName, $relativePath) | Out-Null
}
}
# ライブラリファイルを追加
$libDir = "lib"
if (Test-Path $libDir) {
Get-ChildItem -Path $libDir -Filter "*.jar" | ForEach-Object {
$libArchive = [System.IO.Compression.ZipFile]::OpenRead($_.FullName)
foreach ($entry in $libArchive.Entries) {
if (-not $entry.FullName.EndsWith('/') -and -not $entry.FullName.StartsWith('META-INF/')) {
$newEntry = $archive.CreateEntry($entry.FullName)
$newEntry.LastWriteTime = $entry.LastWriteTime
$stream = $newEntry.Open()
$entryStream = $entry.Open()
$entryStream.CopyTo($stream)
$stream.Close()
$entryStream.Close()
}
}
$libArchive.Dispose()
}
}
# Manifestを追加
$manifestEntry = $archive.CreateEntry("META-INF/MANIFEST.MF")
$manifestStream = $manifestEntry.Open()
$manifestBytes = [System.Text.Encoding]::UTF8.GetBytes($manifestContent)
$manifestStream.Write($manifestBytes, 0, $manifestBytes.Length)
$manifestStream.Close()
$archive.Dispose()
Write-Host "JARファイルを手動で作成しました: $probeJarPath" -ForegroundColor Green
}
}
catch {
Write-Host "ビルドエラー: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "手動でJARファイルを確認してください" -ForegroundColor Yellow
exit 1
}
}
# サンプルディレクトリの確認
if (-not (Test-Path $samplesDir)) {
Write-Host "エラー: samplesディレクトリが見つかりません" -ForegroundColor Red
exit 1
}
# テスト対象のPDFファイルを取得
$pdfFiles = Get-ChildItem -Path $samplesDir -Filter "*.pdf" | Select-Object -First 3
if ($pdfFiles.Count -eq 0) {
Write-Host "エラー: samplesディレクトリにPDFファイルが見つかりません" -ForegroundColor Red
exit 1
}
Write-Host "`n対象PDFファイル:" -ForegroundColor Cyan
$pdfFiles | ForEach-Object { Write-Host " - $($_.Name)" }
# 各PDFファイルに対してテストを実行
foreach ($pdfFile in $pdfFiles) {
Write-Host "`n" + ("=" * 60) -ForegroundColor Yellow
Write-Host "解析対象: $($pdfFile.Name)" -ForegroundColor Yellow
Write-Host ("=" * 60) -ForegroundColor Yellow
$inputPath = $pdfFile.FullName
try {
# 基本解析
Write-Host "`n1. 基本解析:" -ForegroundColor Cyan
java -Dfile.encoding=UTF-8 -jar $probeJarPath -i "$inputPath"
# 詳細解析
Write-Host "`n2. 詳細解析:" -ForegroundColor Cyan
java -Dfile.encoding=UTF-8 -jar $probeJarPath -i "$inputPath" -v
# 結果をファイルに保存
$outputFile = "analysis-result-$($pdfFile.BaseName).txt"
Write-Host "`n3. ファイル出力テスト:" -ForegroundColor Cyan
java -Dfile.encoding=UTF-8 -jar $probeJarPath -i "$inputPath" -v -o $outputFile
if (Test-Path $outputFile) {
Write-Host "✓ 結果ファイルが作成されました: $outputFile" -ForegroundColor Green
} else {
Write-Host "⚠ 結果ファイルの作成に失敗しました" -ForegroundColor Yellow
}
}
catch {
Write-Host "エラー: $($_.Exception.Message)" -ForegroundColor Red
}
}
# ヘルプの表示
Write-Host "`n" + ("=" * 60) -ForegroundColor Yellow
Write-Host "ヘルプ表示テスト" -ForegroundColor Yellow
Write-Host ("=" * 60) -ForegroundColor Yellow
try {
java -jar $probeJarPath --help
}
catch {
Write-Host "ヘルプ表示エラー: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "`n=== PDF解析ツール テスト完了 ===" -ForegroundColor Green
Write-Host "生成されたファイル:" -ForegroundColor Yellow
Get-ChildItem -Filter "analysis-result-*.txt" | ForEach-Object {
Write-Host " - $($_.Name)" -ForegroundColor White
}
Loading…
Cancel
Save