Dear Team,
I am facing text alignment issue while converting dwg to pdf. I am using Aspose.Cad v24.10. Below is my c# code for the same
Aspose.CAD.Image cadImage1 = Aspose.CAD.Image.Load(strTreePath)
List validLayouts = new List();
var cadImageNew = (Aspose.CAD.FileFormats.Cad.CadImage)cadImage1;
foreach (var layout in cadImageNew.Layouts)
{
validLayouts.Add(layout.Key);
}
//
PDF Export Options
PdfOptions pdfOptions = new PdfOptions
{
VectorRasterizationOptions = new CadRasterizationOptions
{
PageWidth = iPageWidth, //
Adjust for better scaling
PageHeight = iPageHeight,
Layouts = validLayouts.ToArray(), //
Export “Model” layout
ExportAllLayoutContent = true //
Ensure all objects are included
}
};
cadImage1.Save(strSavingPath, pdfOptions);
Sharing sample of source dwg file
E3007-203-R0.7z (70.9 KB)
Regards
XCoder
@perfectdata.techno
Cause
The text alignment issue you are experiencing while converting DWG to PDF may stem from the way the CAD file’s layout and text styles are defined. Different CAD applications can handle text alignment differently, which might lead to discrepancies when exporting to PDF.
Solution
To address the text alignment issue, consider the following adjustments:
-
Check Text Styles: Ensure that the text styles in your DWG file are correctly set up. Misconfigured text styles can lead to unexpected alignment in the PDF output.
-
Adjust PDF Options: You can modify the CadRasterizationOptions
to better handle text rendering. For instance, setting the TextRenderingHint
can improve the quality of text in the PDF.
-
Use Layouts Properly: Make sure you are exporting the correct layout. If your DWG file has multiple layouts, ensure that you are selecting the one that contains the properly aligned text.
Code
Here’s a modified version of your code that includes a suggestion for setting the TextRenderingHint
:
Aspose.CAD.Image cadImage1 = Aspose.CAD.Image.Load(strTreePath);
List<string> validLayouts = new List<string>();
var cadImageNew = (Aspose.CAD.FileFormats.Cad.CadImage)cadImage1;
foreach (var layout in cadImageNew.Layouts)
{
validLayouts.Add(layout.Key);
}
// PDF Export Options
PdfOptions pdfOptions = new PdfOptions
{
VectorRasterizationOptions = new CadRasterizationOptions
{
PageWidth = iPageWidth,
PageHeight = iPageHeight,
Layouts = validLayouts.ToArray(),
ExportAllLayoutContent = true,
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias // Improve text rendering
}
};
cadImage1.Save(strSavingPath, pdfOptions);
Next Steps
- Test the modified code to see if it resolves the text alignment issue.
- If the problem persists, check the original DWG file in a CAD application to verify the text alignment settings.
- Explore the Aspose documentation for further details on text rendering options and layout handling.
Please implement these changes and let me know the outcome!
This code is giving error CadRasterizationOptions does not contain a definition for TextRenderingHint.
Regards
Xcoder
@perfectdata.techno,
Hello,
we are able to reproduce the problem and see shifted text, we have logged CADNET-10180 ticket to investigate the reason.