I am using aspose.cad .net for converting a DWG file to a PDF file. I can’t seem to get the SHX fonts into the PDF.
There are 3 .shx fonts used in my DWG drawing put when i export my file as PDF the SHX font is not used. I see the default linestyle in stead of the shx.
I tried several ways to “export” the SHX files, using different locations, nothing seems to work. Am i missing something?
using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(dwgFile, loadOptions))
{
string[] layouts = new[] { cadImage.ActivePage.LayoutName }; //current layout
Console.WriteLine($"Selected layouts: {string.Join(", ", layouts)}");
foreach (CadLayerTable layer in cadImage.Layers)
{
Console.WriteLine($"layer: {layer.Name}, LineWeight: {layer.LineWeight}, LineTypeName: {layer.LineTypeName}");
// layer.PlotFlag = true; // Ensure the layer is set to plot
}
// Set PDF export options
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.PdfDocumentInfo = new Aspose.CAD.FileFormats.Pdf.PdfDocumentInfo
{
Title = "Converted DWG to PDF",
Author = "myCADConverter",
Subject = "DWG to PDF Conversion",
Keywords = "DWG, PDF, Conversion"
};
GetPaperSizeInPoints(pageSize, out int pageWidth, out int pageHeight);
string[] files = System.IO.Directory.GetFiles(@"C:\mypath\Fonts\", "*.shx", SearchOption.AllDirectories);
// Get all SHX font names used in the drawing
var usedShxFonts = GetUsedShxFontNames(cadImage);
// Only include SHX files that are actually used in the drawing
var shxFilesToUse = files
.Where(f => usedShxFonts.Contains(Path.GetFileName(f), StringComparer.OrdinalIgnoreCase))
.ToArray();
var rasterOptions = new CadRasterizationOptions
{
//ShxFonts = shxFilesToUse,//shxfilesloc
PageWidth = pageWidth,
PageHeight = pageHeight,
BackgroundColor = Color.White, // Use 'Color' from System.Drawing
Layouts = layouts,
DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor,
// AutomaticLayoutsScaling = true,
//NoScaling = false,
//ExportAllLayoutContent = true
};
//SHX font handling
rasterOptions.ShxFonts = new string[] //SHX files in same dir a drawing file
{
"ISO.shx",
"isocp2.shx", // this font file is expected to be near drawing file
"NLCS.SHX"
};
// Convert DWG to PDF
pdfOptions.Layers = cadImage.Layers.GetLayersNames().ToArray();
pdfOptions.VectorRasterizationOptions = rasterOptions;
cadImage.Save(pdfFile, pdfOptions);
}