Image is truncated and misplaced when converting word to image


#1

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.


#2

Hi Karunish,

Thanks for your inquiry.

I have tested the scenario and have managed to reproduce the same issues at my side. For the sake of correction, I have logged these issues as follow. I have highlighted these issues in attached images. If you are facing some different issue, please share it.

WORDSNET-9391 : Text position is changed after conversion from Docx to fixed file format
WORDSNET-9392 : Text is truncated after conversion from Docx to fixed file format

I have linked this forum thread to the same issues and you will be notified via this forum thread once these issue are resolved. We apologize for your inconvenience.

I have not found any issue while converting SampleDoc2.docx to Bmp file format. I have attached the output bmp file with this post for your kind reference. Please check SampleDoc2-Out_0.zip.


#3

Hi Karunish,

It is to inform you that we have completed the analysis of issue WORDSNET-9392 (SampleDoc1.docx) and has come to a conclusion that this issue and the undesired behavior is actually not a bug in Aspose.Words. So, we have closed this issue as ‘Not a Bug’.

Please note that Aspose.Words requires
TrueType fonts when rendering documents to fixed-page formats (e.g.
Tiff, PDF, XPS or SWF). Make sure you have all the Fonts installed on
the machine you’re using to convert Word document to Pdf. I would
suggest you please read the following article:
http://www.aspose.com/docs/display/wordsnet/How+Aspose.Words+Uses+True+Type+Fonts

The SampleDoc1.docx is using ‘Nirmala UI’ font. Please install this font at your system and convert it to Pdf by using Aspose.Words. This will fix the issue which you are facing. The font ‘Nirmala UI’ comes as a part of Windows 8.

Please let us know if you have any more queries.


#4

Hi,

I don't think the problem is with the true fonts you are talking about in the thread. I have verified, the fonts which are used in the original word document files are present on the machine on which the code is executed. Also, my dev environment is on Windows 8 Enterprise edition with VS 2012. What about the other sample documents? I have plenty of more such documents which are resulting in truncated or misplaced text images.

Please follow up with your engineers again. I can confirm it's not a font availability issue from my side.

Regards,

Karunish


#5

Hi Karunish,

Thanks for your inquiry. In your case, I suggest you please try the FontSettings.SetFontsFolder method. This method sets the folder where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.


Document doc = new Document(MyDir + "Rendering.doc");

// Note that this setting will override any default font sources that are being searched by default. Now only these folders will be searched for

// fonts when rendering or embedding fonts. To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and

// FontSettings.SetFontSources instead.

FontSettings.SetFontsFolder(@"C:\MyFonts\", false);

doc.Save(MyDir + "Rendering.SetFontsFolder Out.pdf");

public class HandleDocumentWarnings
: IWarningCallback

{

///

/// Our callback only needs to implement the "Warning" method. This method is called whenever there is a

/// potential issue during document procssing. The callback can be set to listen for warnings generated during document

/// load and/or document save.

///

public void Warning(WarningInfo info)

{

// We are only interested in fonts being substituted.

if (info.WarningType == WarningType.FontSubstitution)

{

Console.WriteLine("Font substitution: " + info.Description);

}

}

}

Document doc = new Document(MyDir + "SampleDoc1.docx");

PdfSaveOptions options = new PdfSaveOptions();

options.WarningCallback = new HandleDocumentWarnings ();

doc.Save(MyDir + "Out.pdf", options);


<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>
If you still face problem, please share following detail for testing purposes.
What environment are you running on?
1) OS (Windows Version)
2) Architecture (32 / 64 bit)
3) .NET Framework version
4) Please share your output Pdf file



#6

Hi Tahir,

To make it more clear, I am not converting the word document into pdf format. I am converting them into image format, precisely .bmp format. I have tried the solution provided by you but that still doesn’t work. I have also verified the fonts that are used in the templates are pretty much available on my local machine. Environment on this the tool is run is

  1. OS : Windows 8 Enterprise edition
  2. 64 bit
  3. .NET 4.5 framework
  4. Attached are the word files and their output images.

Production work is blocked due to this so a quick action is much appreciated.


#7

Hi Karunish,

Thanks for your inquiry.

karunisharora:

To make it more clear, I am not converting the word document into pdf format. I am converting them into image format, precisely .bmp format.

Yes, this issue (WORDSNET-9392) was tested with image file format (Bmp) and Pdf. After installing the font (Nirmala UI), this issue is resolved.
karunisharora:

I have also verified the fonts that are used in the templates are pretty much available on my local machine. Environment on this the tool is run is 1) OS : Windows 8 Enterprise edition 2) 64 bit 3) .NET 4.5 framework 4) Attached are the word files and their output images. Production work is blocked due to this so a quick action is much appreciated.

I have tested the scenario at Windows 8 with shared documents and have not found the text truncated issue with output document except output of TF00002066.docx. I have attached the output BMP files with this post for your kind refernece.

Please check the attached image (TextTruncated.png) for issue with TF00002066.docx. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-9583. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.


#8

The issues you have found earlier (filed as WORDSNET-9583) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

#9

The issues you have found earlier (filed as WORDSNET-9391) have been fixed in this Aspose.Words for .NET 19.8 update and this Aspose.Words for Java 19.8 update.