Posted by a ceTe Software moderator
Hello,
Rasterizer cannot directly output the PDF as System.Drawing.Image object, but it can output a System.Drawing.Bitmap object which is actually derived from System.Drawing.Image object. Here is the sample code:
InputPdf pdf = new InputPdf(@"Path for input PDF");
PdfRasterizer rastObj = new PdfRasterizer(pdf);
PdfRasterizerPage page = rastObj.Pages[0];
System.Drawing.Bitmap imageData = page.DrawToBitmap(BitmapColorFormat.RgbA, ImageSize.Dpi72, false);
Our product does not have any methods or properties that you can use to generate a base64 string of the resulting image. You would need to create a byte array (similar to what you are doing in your code) and then convert that byte array to a base64 string by some other method. We tested your code by saving the byte array (ms) to a file and that produced a valid TIFF file. See code below.
byte[] ms = null;
if ((!String.IsNullOrEmpty(sourceFilePath) && sourceFilePath.Trim().Length != 0) && (PageNo > 0))
{
string nameOfTheFile = Path.GetFileName(sourceFilePath);
string fileName = sourceFilePath;
_rasterizer = new PdfRasterizer(sourceFilePath, PageNo, 1);
if (PageNo <= numberOfPages)
{
FixedImageSize fixedImageSize = new FixedImageSize(595, 841);
TiffImageFormat tiffImageFormat = new TiffImageFormat(TiffColorFormat.Rgb);
ms = _rasterizer.DrawToMultiPageTiff(tiffImageFormat, ImageSize.Dpi96);
}
}
File.WriteAllBytes("test.tiff", ms); //writing the byte array to file.
Please do the same on your end and see if the image that results from saving the byte array (ms) to file is valid. If it is then you may want to take a look at your base64 conversion code to see if it is working correctly.
Thanks,
ceTe Software Support Team.