You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cross-platform library to render pdf documents as images with PdfPig using SkiaSharp, or to extract images contained in a pdf page as SkiaSharp images.
Important
This is a very early version and the code is constantly evolving.
usingUglyToad.PdfPig.Graphics.Colors;usingUglyToad.PdfPig;usingUglyToad.PdfPig.Rendering.Skia;usingSkiaSharp;[...]using(vardocument=PdfDocument.Open(_path)){stringfileName=Path.GetFileName(_path);document.AddSkiaPageFactory();// Same as document.AddPageFactory<SKPicture, SkiaPageFactory>()for(intp=1;p<=document.NumberOfPages;p++){using(varfs=newFileStream($"{fileName}_{p}.png",FileMode.Create))using(varms=document.GetPageAsPng(p,_scale,RGBColor.White)){ms.WriteTo(fs);}}}
Get the SKBitmap from a page
usingUglyToad.PdfPig.Graphics.Colors;usingUglyToad.PdfPig;usingUglyToad.PdfPig.Rendering.Skia;usingSkiaSharp;[...]using(vardocument=PdfDocument.Open(_path)){document.AddSkiaPageFactory();// Same as document.AddPageFactory<SKPicture, SkiaPageFactory>()for(intp=1;p<=document.NumberOfPages;p++){varbitmap=document.GetPageAsSKBitmap(p,_scale,RGBColor.White);// Use the SKBitmap}}
Get the SKPicture from a page
usingUglyToad.PdfPig.Graphics.Colors;usingUglyToad.PdfPig;usingUglyToad.PdfPig.Rendering.Skia;usingSkiaSharp;[...]using(vardocument=PdfDocument.Open(_path)){document.AddSkiaPageFactory();// Same as document.AddPageFactory<SKPicture, SkiaPageFactory>()for(intp=1;p<=document.NumberOfPages;p++){varpicture=document.GetPage<SKPicture>(p);// Use the SKPicture}}
How to extract images contained in a pdf page
usingUglyToad.PdfPig.Rendering.Skia.Helpers;[...]using(vardocument=PdfDocument.Open(_path,SkiaRenderingParsingOptions.Instance)){for(intp=1;p<=document.NumberOfPages;p++){varpage=document.GetPage(p);foreach(varpdfImageinpage.GetImages()){varskImage=pdfImage.GetSKImage();// Use SKImage}}}
About
Cross-platform library to render pdf documents as images with PdfPig using SkiaSharp