PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.

Render to Android ImageView widget

The following code renders a PDF to an Xamarin Android ImageView widget with resource ID imageView1:

private void RenderPage(Stream inputStream, int pageNum)
  if (screenWidth == 0 || screenHeight == 0)
    screenHeight = Resources.DisplayMetrics.HeightPixels;
    screenWidth = Resources.DisplayMetrics.WidthPixels;

  using (var outputStream = new MemoryStream())
    AppCompatImageView imageView = FindViewById<AppCompatImageView>(Resource.Id.imageView1);

    Document document = new Document(inputStream);
    Page page = document.Pages[pageNum];

    float dpi = 72;

    double scale1 = Math.Max(screenWidth, screenHeight) / Math.Max(page.Width, page.Height);
    double scale2 = Math.Min(screenWidth, screenHeight) / Math.Min(page.Width, page.Height);

    dpi = (float)Math.Max(scale1, scale2) * 72;

    page.SaveAsBitmap(outputStream, ImageEncoding.Png, dpi);

    Bitmap bmp = BitmapFactory.DecodeByteArray(outputStream.GetBuffer(), 0, (int)outputStream.Length);

Download PDFRasterizer.NET 4.0
We will send you a download link

  • This field is for validation purposes and should be left unchanged.
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link.