PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 11, 2024 10:26 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: PDF Page to image
PostPosted: Sat Jul 09, 2011 11:35 am 
Offline

Joined: Sat Jul 09, 2011 11:22 am
Posts: 2
Hello.
how to save the pdf page to image?
I have this code
Code:
using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Drawing;
using PdfSharp.Drawing.Pdf;
using MigraDoc.Rendering;
...............
PdfDocument pdfDocument = PdfReader.Open(pdfDocName);       

int dpi = 150;
int width = (int)pdfDocument.Pages[0].Width.Inch * dpi;
int height = (int)pdfDocument.Pages[0].Height.Inch * dpi;
MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
document.AddSection();
MigraDoc.Rendering.DocumentRenderer documentRenderer = new DocumentRenderer(document);
MigraDoc.Rendering.PdfDocumentRenderer pdfDocumentRender = new PdfDocumentRenderer();
pdfDocumentRender.PdfDocument = pdfDocument;
pdfDocumentRender.DocumentRenderer = documentRenderer;
       
Image image = new Bitmap(width, height);
Graphics graphics = Graphics.FromImage(image);
XGraphics xGraphics = XGraphics.FromGraphics(graphics, new XSize(width, height));
documentRenderer.RenderPage(xGraphics, 0);//in this line error
image.Save("1.png", ImageFormat.Png);

       
pdfDocument.Close();


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF Page to image
PostPosted: Sat Jul 09, 2011 9:53 pm 
Offline

Joined: Sat Jul 09, 2011 11:22 am
Posts: 2
I modurator from Russian forum, and will never admit topic without an answer. Probably a bad forum. Moderators will remove, but those who see will understand.


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF Page to image
PostPosted: Sun Jul 10, 2011 7:08 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
Ghost20 wrote:
I modurator from Russian forum, and will never admit topic without an answer. Probably a bad forum. Moderators will remove, but those who see will understand.

Well, if you ask questions on a Saturday morning be prepared to wait till Monday to get answers.
Provide all relevant information with your question or you'll get questions in return.
See here:
viewtopic.php?f=2&t=832

"in this line error" doesn't help me. I'd have to create a project with your source code to get the exact error message. Why don't you include the exact error message in your post (outside the source code)?

PDFsharp wasn't designed to create images and AFAIK you attempt something that cannot be done with PDFsharp.
The FAQ tell you to "invoke GhostScript to create images from PDF pages".

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 42 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group