We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting to tiff changed after upgrading Words 14.2 to 15.7

Hi,


As can be seen in the title, after updating the Aspose Words 14.2 to 15.7, we noticed some issues when converting files to tiff. This only goes for existing tif / tiff images and files we’ve extracted from a .zip or .7z file.
When inputting an image the outputs are as follow:
- Words 14.2: image equal to input
- Words 15.7: image is shrunk to the top left corner of the page, about a quarter of the page.

Keep in mind that the piece of code below is used for multiple types of images, not just tiff. (Including bmp, png, jpeg, tiff, and gif)

Let’s just focus on the tiff to tiff for now - one may want to convert this to e.g. lower the resolution, but for now we input a tiff and want the same image as an output.

Code
Where:
- “Data” is a MemoryStream containing the file.
- "MAX_PAGE_ … " equals 1584, as taken somewhere from the Aspose documentation. The CalculateImageSize is never reached in this example though.

// create the document - no data
document = new Document();

// we use the builder to fill the document
DocumentBuilder builder = new DocumentBuilder(document);

// load the input image from the stream
using (System.Drawing.Image image = System.Drawing.Image.FromStream(Data))
{
// Find which dimension the frames in this image represent. For example
// the frames of a BMP or TIFF are “page dimension” whereas frames of a GIF image are “time dimension”.
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);

// Get the number of frames in the image.
FrameDimension fd = this.Type == FileType.GIF ? FrameDimension.Time : FrameDimension.Page;
int framesCount = image.GetFrameCount(fd);

// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);

// Select active frame.
image.SelectActiveFrame(dimension, frameIdx);

double imageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
double imageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);

// If the image is larger than the maximum size for word document: shrink the image.
if (imageWidth >= Words.MAX_PAGE_WIDTH || imageHeight >= Words.MAX_PAGE_HEIGHT)
// Shrink the image
CalculateImageSize(image, Words.MAX_PAGE_HEIGHT, Words.MAX_PAGE_WIDTH, out imageHeight, out imageWidth);

// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = imageWidth;
ps.PageHeight = imageHeight;

// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
// any resolution
// any compression

document.Save( Some other Stream, options);

End Code

If there are any questions, let me know.

Cheers,
Knots

Hi Knots,


Thanks for your inquiry. Your inquiry pertains to Aspose.Words, so I am moving it to related forum. My Aspose.Words colleague will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi Knots,


Thanks for your inquiry. Could you please attach your input and output Tiff files here for testing? I will investigate the issue on my side and provide you more information.

Hello again,



Attached you’ll find a sample image.

Regards,
Knots

Hi Knots,


Thanks
for sharing the detail. I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-12462. 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.

Please use the following highlighted code as a workaround of this issue. Hope this helps you.


<!–[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>ZH-CN</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</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:0pt 5.4pt 0pt 5.4pt; mso-para-margin-top:0pt; mso-para-margin-right:0pt; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0pt; line-height:107%; 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]–>

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Read the image from file, ensure it is disposed.

using (Image image = Image.FromFile(MyDir + "Tiff-13p.tif"))

{

// Get the number of frames in the image.

int framesCount = image.GetFrameCount(FrameDimension.Page);

// Loop through all frames.

for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)

{

// Insert a section break before each new page, in case of a multi-frame TIFF.

if (frameIdx != 0)

builder.InsertBreak(BreakType.SectionBreakNewPage);

// Select active frame.

image.SelectActiveFrame(FrameDimension.Page, frameIdx);

// Max page size

const double maxPageHeight = 1584;

const double maxPageWidth = 1584;

double currentImageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);

double currentImageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);

if (currentImageWidth >= maxPageWidth || currentImageHeight >= maxPageHeight)

{

// Get max image size.

CalculateImageSize(image, maxPageHeight, maxPageWidth, out currentImageHeight, out currentImageWidth);

}

// We want the size of the page to be the same as the size of the image.

// Convert pixels to points to size the page to the actual image size.

PageSetup ps = builder.PageSetup;

ps.PageWidth = currentImageWidth;

ps.PageHeight = currentImageHeight;

// Insert the image into the document and position it at the top left corner of the page.

Shape shape = builder.InsertImage(

image,

RelativeHorizontalPosition.Page,

0,

RelativeVerticalPosition.Page,

0,

currentImageWidth,

currentImageHeight,

WrapType.None);

shape.Width = currentImageWidth;

shape.Height = currentImageHeight;

}

}

doc.Save(MyDir + "Out.tiff");


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


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