PDFsharp & MigraDoc Forum
https://forum.pdfsharp.net/

Converting pdf file into images
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3318
Page 1 of 1

Author:  puvi044 [ Fri Mar 11, 2016 7:32 pm ]
Post subject:  Converting pdf file into images

Hello,
I'm trying to split my pdf page and convert each page into an image. However I only get a black empty image every time. Below is the code I was trying out.
Code:
            PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.Modify);
            var page = inputDocument.Pages[0];
            XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Replace);
            //var state = gfx.Save();
            //gfx.Restore(state);

            Image image = new Bitmap((int)gfx.Graphics.VisibleClipBounds.Width, (int)gfx.Graphics.VisibleClipBounds.Height, gfx.Graphics);
            image.Save("image.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);

The commented 2 lines, I was not sure if I needed it. Any suggestions on how I can get this working would be great.
Thanks and appreciate a quick response.

Author:  TH-Soft [ Sat Mar 12, 2016 8:20 am ]
Post subject:  Re: Converting pdf file into images

Hi!
puvi044 wrote:
Thanks and appreciate a quick response.
A link to a quick answer from 2010:
http://stackoverflow.com/a/3015623/1015447

Reading the manual for "new Bitmap" would have led to an even quicker self-answer. :wink:

Save and Restore do not make any difference here.

Author:  puvi044 [ Mon Mar 14, 2016 5:21 am ]
Post subject:  Re: Converting pdf file into images

Thanks for the response, is there another software that I can use in tandem with PDFSharp so that I can split the document using PDFSharp, and use the other software to convert it to an image?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/