Skip to content

Instantly share code, notes, and snippets.

@asimmon
Last active November 20, 2015 15:07
Show Gist options
  • Save asimmon/83e26f04aa4326d47ce2 to your computer and use it in GitHub Desktop.
Save asimmon/83e26f04aa4326d47ce2 to your computer and use it in GitHub Desktop.
Rendering all pages of a PDF file to PNG with the MuPDF Xamarin Android library
var pdf = new MuPDFCore(this, pdfFilepath);
var cookie = new MuPDFCore.Cookie(pdf);
var count = pdf.CountPages();
for (int i = 0; i < count; i++)
{
var size = pdf.GetPageSize(i);
int pageWidth = (int)size.X;
int pageHeight = (int)size.Y;
var bitmap = Bitmap.CreateBitmap(ScreenWidth, ScreenHeight, Bitmap.Config.Argb8888);
pdf.DrawPage(bitmap, i, pageWidth, pageHeight, 0, 0, ScreenWidth, ScreenHeight, cookie);
String filename = String.Format("/mnt/sdcard/pdf-{0}.png", i);
using (var fos = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite))
{
bitmap.Compress(Bitmap.CompressFormat.Png, 100, fos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment