Hello team,
Thank you for your support.
PQ2322.zip (314.6 KB)
1.jpg (198.8 KB)
2.jpg (186.2 KB)
I have converted PQ2322.xlsx to images with Aspose.Cells 17.8. Please find error portions at jpg files.
- partially missing character.
- line break
This is my code.
public static List ConvertExcelToImage(string docName, MemoryStream docStream, Dictionary<string, string> config)
{
try
{
var pageInfoList = new List();
// Get config setting
string docRootDir = config["DocumentsFilePath"];
int dpi = int.Parse(config["ImageDPI"]);
int thumbMaxH = int.Parse(config["ThumbnailMaxHeight"]);
int thumbMaxW = int.Parse(config["ThumbnailMaxWidth"]);
int maxPageNum = int.Parse(config["DocumentMaxPageNum"]);
double readScale = double.Parse(config["ImageReadScale"]);
int readDpi = Convert.ToInt32(dpi * readScale);
// Create images directory
string pageImgDir = docRootDir;
if (!Directory.Exists(pageImgDir))
Directory.CreateDirectory(pageImgDir);
// Get the encoder of JPEG
ImageCodecInfo jpgEncoder = GetCodecInfo();
//EncoderParameters encParams = GetEncoderParams();
EncoderParameters encParams = GetEncoderParams(int.Parse(config["ImageJpegQuality"]));
// Instantiate the License class
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense("Aspose.Total.lic");
// Convert .doc and .docx file to PDF.
Workbook book = new Workbook(docStream);
//Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
//Specify the image format
imgOptions.ImageFormat = ImageFormat.Png;
imgOptions.VerticalResolution = readDpi;
imgOptions.HorizontalResolution = readDpi;
int totalPageCount = 0;
foreach (Worksheet sheet in book.Worksheets)
{
//Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int i = 0; i < sr.PageCount; i++)
{
totalPageCount++;
if (totalPageCount <= maxPageNum)
{
//Render the image for the sheet
string imgFile = string.Format("{0}_{1:D8}.jpg",
Path.GetFileNameWithoutExtension(docName), totalPageCount);
string imgPath = Path.Combine(pageImgDir, imgFile);
using (Bitmap bitmap = sr.ToImage(i))
{
// Export image file
bitmap.SetResolution(dpi, dpi);
bitmap.Save(imgPath, jpgEncoder, encParams);
// Add PageInfo List
pageInfoList.Add(imgPath);
}
}
else
{
break;
}
}
if (totalPageCount >= maxPageNum) break;
}
// return results with flag of max page limit over
return pageInfoList;
}
finally
{
}
}
They are parameters.
// Get config setting
Create Appseting key value for async function
Dictionary<string, string> config = new Dictionary<string, string>();
config.Add("DocumentsFilePath", outDir);
config.Add("ImageDPI", "96");
config.Add("ImageReadScale", "1.25");
config.Add("ThumbnailMaxHeight", "252");
config.Add("ThumbnailMaxWidth", "210");
config.Add("ImageJpegQuality", "80");
config.Add("DocumentMaxPageNum", "1000");
Thank you,
PFU DSOL2