본문 바로가기
C#

PdfSharp을 이용한 Tiff To Pdf 변환 예제

by Hwoarang757 2024. 6. 16.

PdfSharp을 이용한 Tiff To Pdf 변환 예제 입니다.

 

PdfSharp 은 MIT Licence로 opensource로 알고 있습니다.

출처 : https://www.pdfsharp.net/Licensing.ashx?AspxAutoDetectCookieSupport=1

 

Licensing - PDFsharp & MigraDoc

PDFsharp and MigraDoc Foundation are published under the MIT License. See the PDFsharp License. See the MigraDoc Foundation License. PDFsharp and MigraDoc Foundation are Open Source and free to useCopy, modify and integrate the source code of PDFsharp and

www.pdfsharp.net

 

// See https://aka.ms/new-console-template for more information
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Snippets.Drawing;
using System.Drawing;
using System.Drawing.Imaging;

using (Image image = Image.FromFile(@"D:\document\팩스이미지1.tif"))
{
    int pageCount = image.GetFrameCount(FrameDimension.Page);
    PdfDocument doc = new PdfDocument();

    for (int i = 0; i < pageCount; i++)
    {
        image.SelectActiveFrame(FrameDimension.Page, i);
        using (MemoryStream ms = new MemoryStream())
        {
            image.Save(ms, ImageFormat.Bmp);

            XImage img = XImage.FromStream(ms);
            PdfPage page = new PdfPage();
            doc.Pages.Add(page);

            XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]);
            xgr.DrawImage(img, 0, 0);
        }
    }


    doc.Save(@"D:\document\팩스이미지1.pdf");
    doc.Close();
}

 

출력 결과 입니다.