Hello,
The footer page number in the multi sheets workbook is different converting JPEG/PDF.
The PDF file can be outputted the page number of the 3rd and 4th. the total page number is 4.
But Jpeg files are outputted page number of each sheet.
Can I output the total page number and page number in workbook like PDF file?
I have attached the original Excel file and converted PDF file and Jpeg Images.
HeaderFooter.zip (121.4 KB)
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,