WebpOptions contains WebP specific convert options.
UsePdf. Sometimes, for better rendering and elements positioning the source document should be converted to PDF first. If this property is set to true, the input firstly is converted to PDF and after that to desired format.
The following code snippet shows how to convert to image with advanced options:
Image formats other than TIFF hold one page per file, so the examples below save each page of the multi-page source to its own image through a SavePageContext callback.
Set a background color for the converted image where supported by the source format:
usingSystem.Drawing;using(Converterconverter=newConverter("sample.pdf")){ImageConvertOptionsoptions=newImageConvertOptions{Format=ImageFileType.Png,BackgroundColor=Color.White// Use System.Drawing.Color};converter.Convert((SavePageContextcontext)=>File.Create($"white-background-{context.Page}.png"),options);}
You can use any color from System.Drawing.Color or create custom colors:
usingSystem.Drawing;using(Converterconverter=newConverter("sample.pdf")){ImageConvertOptionsoptions=newImageConvertOptions{Format=ImageFileType.Png,BackgroundColor=Color.FromArgb(173,216,230)// Light blue (RGB)};converter.Convert((SavePageContextcontext)=>File.Create($"custom-background-{context.Page}.png"),options);}
Cropping Image Area
Crop a specific rectangular area from the converted image. The CropArea property takes a Rectangle defined by its edges, in pixels: the left and top edges of the area, followed by its right and bottom edges. The example below keeps a 300 × 200 pixel area whose top-left corner is at (100, 100):
usingGroupDocs.Conversion.Contracts;using(Converterconverter=newConverter("sample.pdf")){ImageConvertOptionsoptions=newImageConvertOptions{Format=ImageFileType.Png,BackgroundColor=System.Drawing.Color.LightGray,CropArea=newRectangle(50,50,562,562)// A 512 x 512 pixel area};converter.Convert((SavePageContextcontext)=>File.Create($"background-and-crop-{context.Page}.png"),options);}