Files
ExperionCrawler/dxf-graph/extract_pdf.cs
2026-05-08 17:22:10 +09:00

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}");
}
}
}