xps 파일을 png 파일로 변경하는 코드
{
// Make sure this is an xps file.
if (!xps_file.ToLower().EndsWith(".xps"))
throw new ArgumentException(
"Method XpsToPng only works for .xps files.");
            // Get the file's name without the .xps on the end.
            string file_prefix =
                xps_file.Substring(0, xps_file.Length - 4);
            // Load the XPS document.
            XpsDocument xps_doc = new XpsDocument(xps_file, FileAccess.Read);
            // Get a fixed paginator for the document.
            IDocumentPaginatorSource page_source =  xps_doc.GetFixedDocumentSequence();
            DocumentPaginator paginator =  page_source.DocumentPaginator;
            // Process the document's pages.
            int num_pages = paginator.PageCount;
            for (int i = 0; i < num_pages; i++)
            {
                using (DocumentPage page = paginator.GetPage(i))
                {
                    // Render the page into the memory stream.
                    int width = (int)page.Size.Width;
                    int height = (int)page.Size.Height;
                    RenderTargetBitmap bitmap =
                        new RenderTargetBitmap(
                            width, height, 96, 96,
                            PixelFormats.Default);
                    bitmap.Render(page.Visual);
                    // Save the PNG file.
                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(bitmap));
                    using (MemoryStream stream = new MemoryStream())
                    {
                        encoder.Save(stream);
                        using (FileStream file = new FileStream(
                            file_prefix + (i + 1).ToString() + ".png",
                            FileMode.Create))
                        {
                            file.Write(stream.GetBuffer(), 0,
                                (int)stream.Length);
                            file.Close();
                        }
                    }
                }
            }
            return num_pages;
        }
'C# > Winform' 카테고리의 다른 글
| How to generate a PDF from HTML using wkhtmltopdf with C# in WinForms (0) | 2018.03.02 | 
|---|---|
| (C#) ShuffleArray (0) | 2018.02.24 | 
| (C#) 프린터 출력시 이벤트 처리하기 (0) | 2018.02.24 | 
| (C#)프린터 목록 가져오기 (0) | 2018.02.24 | 
| ICollection 과 IEnumerable 또는 List <T> 의 차이 - 링크 (0) | 2018.02.18 | 





