@huanguwjie1
Thank you for your request and for providing the details. I understand that you are encountering an issue with overlapping titles, legends, and tick labels when converting a Word document to a PDF using Aspose.Words.
Here are some steps to help you diagnose and potentially resolve the issue:
Steps to Diagnose and Resolve the Issue
1. Check Chart Rendering Options
Ensure that you are using the latest version of Aspose.Words. Sometimes, specific chart rendering issues are fixed in newer releases.
2. Use High-Res Image Conversion
If you are still encountering issues with chart rendering, you can try converting charts in your document to images. This approach can sometimes resolve rendering discrepancies.
Here is a sample code snippet for converting charts to images:
// Load the document
var testDoc = new Document("D:\\test.docx");
// Iterate through each chart in the document
foreach (Shape shape in testDoc.GetChildNodes(NodeType.Shape, true))
{
if (shape.HasChart)
{
// Render the chart to an image
var stream = new MemoryStream();
shape.Chart.ToImage(stream, new ImageSaveOptions(ImageFormat.Png));
stream.Position = 0;
// Replace the chart with the image
shape.ImageByteArray = stream.ToArray();
}
}
// Save the document
testDoc.Save("D:\\test.pdf", SaveFormat.Pdf);
3. Adjust Chart Layout in Word
Sometimes, adjusting chart properties directly in Word (like increasing the spacing between elements) before conversion can help. Here’s how you can do that:
- Open the Word document in Microsoft Word.
- Select the chart and click on the “Chart Tools” tab.
- Adjust the chart axes, gridlines, and other elements to ensure there is enough spacing.
4. Use Custom PDF Save Options
You can configure the PdfSaveOptions class to improve the quality of the PDF output.
var options = new PdfSaveOptions();
options.JpegQuality = 100; // Highest quality
var testDoc = new Document("D:\\test.docx");
testDoc.Save("D:\\test.pdf", options);
5. Check Word Document Content
Ensure that the Word document itself is well-structured and formatted properly. Sometimes poorly formatted content can lead to rendering issues.
Additional Resources
If after trying these steps you still encounter issues, please provide more details or any error messages that appear. This information will help in understanding the problem further and providing a more precise solution.