Hi,
We have an application which converts each page of word file into images. Our goal is to generate three different size of images for each page. Below is the code which accomplished the above requirement.
try
{
//initializing Aspose License for word application.
AsposeWord.
License license = new AsposeWord.License();
license.SetLicense(
"Aspose.Total.lic");
//initialize Aspose object for word application
AsposeWord.
Document doc = new AsposeWord.Document(sourcePath);
//fetch filename without extension
fileName =
Path.GetFileNameWithoutExtension(doc.OriginalFileName);
//define the image extension that needs to be considered as base for resizing.
imageFileExtension =
".bmp";
//finding the number of pages in word template.
int numberOfPages = doc.PageCount;
//initializing Aspose word document builder object for finding orientation.
AsposeWord.
DocumentBuilder docBuilder = new AsposeWord.DocumentBuilder(doc);
orientation = docBuilder.PageSetup.Orientation.ToString();
//defining the options of image format
Aspose.Words.Saving.
ImageSaveOptions options = new Aspose.Words.Saving.ImageSaveOptions(AsposeWord.SaveFormat.Bmp);
int imgCounter = 0;
//if temp folder directory doesn't exist create one.
tempFolderPath = CreateTargetDirectories(tempFolderPath);
//looping through first page of word document to create thumbnail.
//this can be modified to loop through all pages if thumbnail generation require for further pages.
for (int i = 0; i < 1; i++)
{
options.PageIndex = i;
options.PageCount = 1;
//saving first page of word document as a temporary bmp file in temporary folder
doc.Save(tempFolderPath +
@"\" + fileName + "_Bmp" + ++imgCounter + imageFileExtension, options);
}
}
However the above code piece results into bad image output which has either text truncated or document images misplaced on the Output Image. See attached documents.
Please provide a fix for this.