밥탄이 기록일지

CheckMate RPA C# PDF 여러개 분할하기 (Spire.pdf) 본문

CheckMate RPA

CheckMate RPA C# PDF 여러개 분할하기 (Spire.pdf)

밥탄이 2022. 11. 22. 10:00
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;

// PDF 분할을 위한 dll 
using Spire.Pdf;

public partial class CustomScript
{
	public void Execute_Code()
	{
  		string[] pdf = null;
		int count = 0;
		
        // 특정 폴더에 있는 모든 pdf 저장
        Path path = Path.Combine(@"C:\");
		pdf = Directory.GetFiles(path "*.pdf", searchOption: SearchOption.AllDirectories);
		
        // 저장된 pdf 개수만큼 회전
		for (int i = 0; i < pdf.Length; i++)
		{
			PdfDocument doc = new PdfDocument(pdf [i].ToString());
			String pattern = path + "_{0}.pdf";
			doc.Split(pattern);
			doc.Close();
		}
	}
}

 

결과

 

C 폴더에 PDF 파일이 3개이고 각각 2,3,4 페이지를 가졌다면

C 폴더에 _0 ~ _8.총 9개의 pdf 파일로 분할된다.

 

CheckMate RPA 는 dll 을 다운로드받는 형식이 아니기때문에

Spire.Pdf.dll 파일을 따로 구비해주어야 한다.