58 lines
2.3 KiB
C#
58 lines
2.3 KiB
C#
|
|
using System;
|
|
using System.Text;
|
|
using UglyToad.PdfPig;
|
|
using UglyToad.PdfPig.DocumentLayoutAnalysis.TextExtractor;
|
|
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
string pdfPath = "/home/windpacer/projects/ExperionCrawler/futurePlan/plant-9100.pdf";
|
|
string markdownPath = "/home/windpacer/projects/ExperionCrawler/futurePlan/plant-9100-extracted.md";
|
|
|
|
Console.WriteLine($"PdfPig 버전: {typeof(PdfDocument).Assembly.GetName().Version}");
|
|
Console.WriteLine($"PDF 파일: {pdfPath}");
|
|
Console.WriteLine();
|
|
|
|
using (var document = PdfDocument.Open(pdfPath))
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
sb.AppendLine("# plant-9100.pdf 추출 결과");
|
|
sb.AppendLine();
|
|
sb.AppendLine("## PDF 정보");
|
|
sb.AppendLine();
|
|
sb.AppendLine($"- **버전**: {document.Version}");
|
|
sb.AppendLine($"- **페이지 수**: {document.NumberOfPages}");
|
|
sb.AppendLine($"- **제목**: {document.Information.Title ?? "(없음)"}");
|
|
sb.AppendLine($"- **작성자**: {document.Information.Author ?? "(없음)"}");
|
|
sb.AppendLine($"- **생성 프로그램**: {document.Information.Producer ?? "(없음)"}");
|
|
sb.AppendLine($"- **생성일**: {document.Information.CreationDate ?? "(없음)"}");
|
|
sb.AppendLine();
|
|
|
|
foreach (var page in document.GetPages())
|
|
{
|
|
sb.AppendLine($"## 페이지 {page.Number}");
|
|
sb.AppendLine();
|
|
sb.AppendLine($"- **크기**: {page.Width} x {page.Height}");
|
|
sb.AppendLine();
|
|
|
|
string text = page.Text;
|
|
sb.AppendLine("### 추출 텍스트");
|
|
sb.AppendLine();
|
|
sb.AppendLine("```");
|
|
sb.AppendLine(text);
|
|
sb.AppendLine("```");
|
|
sb.AppendLine();
|
|
|
|
Console.WriteLine($"페이지 {page.Number} 추출 완료 ({text.Length}자)");
|
|
}
|
|
|
|
System.IO.File.WriteAllText(markdownPath, sb.ToString());
|
|
Console.WriteLine();
|
|
Console.WriteLine($"전체 추출 완료. 결과 저장: {markdownPath}");
|
|
}
|
|
}
|
|
}
|