We are using ASPOSE.Words to convert .doc to .docx. (.NET) During transformation, the tables and images are getting truncated . What settings to use? Please help.
When converting documents from .doc to .docx using Aspose.Words, if you are experiencing issues with tables and images being truncated, there are several settings you can adjust to improve the output.
-
Metafile Rendering Options: If your document contains metafiles, you can customize how they are rendered. For instance, you can set the
EmulateRasterOperations
tofalse
and choose a rendering mode that suits your needs. This can help in preserving the layout of images and tables.MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions { EmulateRasterOperations = false, RenderingMode = MetafileRenderingMode.VectorWithFallback }; PdfSaveOptions saveOptions = new PdfSaveOptions { MetafileRenderingOptions = metafileRenderingOptions };
-
Additional Text Positioning: Enabling additional text positioning can help in better placement of text and images, which might resolve some truncation issues.
PdfSaveOptions saveOptions = new PdfSaveOptions { AdditionalTextPositioning = true };
-
Image Compression: If images are being truncated, consider adjusting the image compression settings. You can set the compression type and quality to ensure that images are preserved correctly.
PdfSaveOptions saveOptions = new PdfSaveOptions { ImageCompression = PdfImageCompression.Jpeg, JpegQuality = 100 // Adjust quality as needed };
-
Export Document Structure: If the document structure is important, enabling this option can help maintain the layout during conversion.
PdfSaveOptions saveOptions = new PdfSaveOptions { ExportDocumentStructure = true };
-
Testing and Debugging: It may also be beneficial to implement a warning callback to capture any rendering warnings that occur during the conversion process. This can provide insights into what might be causing the truncation.
HandleDocumentWarnings callback = new HandleDocumentWarnings(); doc.WarningCallback = callback;
By adjusting these settings, you should be able to mitigate the issues with tables and images being truncated during the conversion process. If problems persist, consider reviewing the specific content of the documents for any unusual formatting that might be causing issues.
For more detailed examples and options, you can refer to the Aspose documentation or the provided code samples in the Aspose GitHub repository.
@hrnallap Could you please zip and attach your problematic input and output documents here for our reference? We will check the issue and provide you more information.
Below is an example of a document thats transformed with ASPOSE.words, where tables are getting truncated in print view. Help how to render these tables without truncating.
Test Table Truncation Doc.docx (20.9 KB)
@hrnallap You can autofit the table to window to avoid truncation:
Document doc = new Document(@"C:\Temp\in.docx");
foreach (Table t in doc.GetChildNodes(NodeType.Table, true))
t.AutoFit(AutoFitBehavior.AutoFitToWindow);
doc.Save(@"C:\Temp\out.docx");
Auto fit works for Tables but not images within Tables. Our Images are still getting truncated. Pls see attached.
Back to TOC Input.docx (454.2 KB)
@hrnallap This is an expected behavior. Table.AutoFit
method does not resize shapes. You can loop through shapes in your document, check size and resize them accordingly.
Can you provide code for the same pls?
@hrnallap You can use code like the following to resize shapes in the document:
Document doc = new Document(@"C:\Temp\in.docx");
foreach (Shape s in doc.GetChildNodes(NodeType.Shape, true))
{
if (!s.IsTopLevel)
continue;
PageSetup ps = ((Section)s.GetAncestor(NodeType.Section)).PageSetup;
// This value is for demonstration purposes.
double maxPageWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
if (s.Width > maxPageWidth)
{
s.AspectRatioLocked = true;
s.Width = maxPageWidth;
}
}
doc.Save(@"C:\Temp\out.docx");