Last active
November 20, 2015 15:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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