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();
xgfx.Graphics
is alwaysnull
? The description for thenew Bitmap(int, int, Graphics)
method: "Initializes a new instance of the Bitmap class with the specified size and with the resolution of the specified Graphics object." No wonder that all pixel return 0 as this function does not (and cannot) copy any pixels from the Graphics object. – Parthia