views:

431

answers:

1

How to export a pdf page as an image using pdfsharp .net library, for pixel level manipulation ?

for example, something like, System.Drawing.BitMap.GetPixel()

I am trying to find out empty area (all white, or of any colour) inside a pdf document, to write some graphics / image.

09, June 2010:

I have tried this, but it is not working.

why the following code is not working as expected ?

Bitmap.GetPixel always returns 0.

//
// PdfSharp.Pdf.PdfDocument
// PdfSharp.Pdf.PdfPage
// PdfSharp.Drawing.XGraphics
// System.Drawing.Bitmap
//
string srcPDF = @"C:\hcr\test\tmp\file1.pdf";
PdfDocument pdfd = PdfReader.Open(srcPDF);
XGraphics xgfx = XGraphics.FromPdfPage(pdfd.Pages[0]);
Bitmap b = new Bitmap((int) pdfp.Width.Point, (int) pdfp.Height.Point, xgfx.Graphics);

int rgb = b.GetPixel(0, 0).ToArgb();
A: 

The answer can be found in the PDFsharp FAQ list: http://www.pdfsharp.net/wiki/PDFsharpFAQ.ashx#Can_PDFsharp_show_PDF_files_Print_PDF_files_Create_images_from_PDF_files_3

PDFsharp creates PDF files, but it cannot render them.

The best place to ask PDFsharp and MigraDoc Foundation related questions is the PDFsharp forum. The PDFsharp Team will not monitor stackoverflow.com on a regular basis.

PDFsharp Forum:
http://forum.pdfsharp.net/

PDFsharp Website:
http://www.pdfsharp.net/

PDFsharp Team
I don't understand, while writing to System.Drawing.Graphics is possible, reading pixels from it made intentionally impossible. For me, creating Bitmap object from Graphics looks like a reasonable requirement. :(
vi.su.
You write: "reading pixels from it made intentionally impossible".That's not true: we don't make it impossible. PDF is a vector format. How do you read pixels from a vector format?You can render PDF to a bitmap and read pixels from that. But PDFsharp doesn't render bitmaps.
PDFsharp Team