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:
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("white-background.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("custom-background.png",options);}
Cropping Image Area
Crop a specific rectangular area from the converted image. The CropArea property takes a Rectangle with X, Y coordinates for the top-left corner, and Width, Height for the dimensions:
usingGroupDocs.Conversion.Contracts;using(Converterconverter=newConverter("sample.pdf")){ImageConvertOptionsoptions=newImageConvertOptions{Format=ImageFileType.Png,CropArea=newRectangle(100,100,400,300)// X, Y, Width, Height};converter.Convert("cropped-image.png",options);}