Convert PDF with layers to image

Convert PDF, Images
8/24/2015

In the code sample below you see how you can incorporate multiple layers into your rendering process. Simply set the Visibility of the layers which you want to render to true, and add the LayerCollection to your RenderSettings object.

1 using (FileStream fs = new FileStream(@"..\..\input.pdf", FileMode.Open, FileAccess.Read)) 2 { 3 Document d = new Document(fs); 4 LayerCollection layers = d.Layers; 5 6 //select layers to render 7 layers[0].Visible = true; 8 layers[1].Visible = false; 9 10 Page page = d.Pages[0]; 11 12 Bitmap bitmap = new Bitmap((int)page.Width, (int)page.Height); 13 using (Graphics graphics = Graphics.FromImage(bitmap)) 14 { 15 RenderSettings renderSettings = new RenderSettings(); 16 renderSettings.LayerSettings.Layers = layers; 17 graphics.SmoothingMode = SmoothingMode.AntiAlias; 18 page.Draw(graphics, renderSettings); 19 } 20 bitmap.Save(@"..\..\output.bmp"); 21 }