Issue
The CAD files that get made from an Inventor drawing are coming out nice, but the files that are made in CAD from the start are not getting the logo image; the other images are there but the logo isn’t going through. The images appear to have the same properties, but the LOGO is just not showing up on the PDF.
Other Info
It is working fine on Inventor DWG files, but for the AutoCAD DWG, it will not output the logo on the PDF.
When converting to PDF directly in AutoCAD, it works just fine.
Any ideas on why the LOGO image would not appear on PDF but the other images (which seem to have the same properties) do?
@jacobstokeswarner
Cause
The issue you’re experiencing with the logo image not appearing in the PDF when converting from AutoCAD DWG files is likely due to specific properties of the logo image, such as its format, resolution, or how it is referenced in the CAD file. Since the logo works correctly when converting from Inventor DWG files, this indicates that the problem is specific to the AutoCAD files.
Solution
To troubleshoot and resolve this issue, please follow these steps:
-
Check Image Format: Ensure that the logo image is in a supported format (like PNG, JPEG, etc.) and not in a format that might not be handled properly by the conversion process.
-
Verify Image Path: Confirm that the path to the logo image in the AutoCAD file is correct and accessible. Relative paths can cause issues if the working directory changes.
-
Inspect Image Properties: Compare the properties of the logo image with those of other images that are rendering correctly. Look for differences in resolution, size, or color depth.
-
Update Aspose.CAD: Make sure you are using the latest version of the Aspose.CAD library, as updates may include bug fixes and improvements related to image handling.
-
Use Rasterization Options: When converting, utilize the CadRasterizationOptions
to specify settings that may help render the logo correctly. For example, you can set the background color or adjust the scaling options.
Code Example
Here’s a basic example of how to set up the conversion with rasterization options:
using Aspose.CAD;
using Aspose.CAD.ImageOptions;
// Load the AutoCAD file
string sourceFilePath = "path_to_your_file.dwg";
using (var image = Image.Load(sourceFilePath))
{
// Create rasterization options
var rasterizationOptions = new CadRasterizationOptions
{
PageWidth = 1200,
PageHeight = 1200,
AutomaticLayoutsScaling = true // Enable auto layout scaling
};
// Create PDF options and set rasterization options
var pdfOptions = new PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
// Save the output PDF
image.Save("output.pdf", pdfOptions);
}
Next Steps
- Test the conversion using the provided code and check if the logo appears in the PDF.
- If the issue persists, isolate the logo image and test it in a new CAD file to see if it converts correctly.
- If you continue to face challenges, please provide more details about the logo image properties and any error messages you might encounter.
Please let me know if this resolves your issue!
Source Code
/// <summary>
/// Converts a DWG file to PDF using Aspose.CAD.
/// See documentation here: https://products.aspose.com/cad/net/conversion/dwg-to-pdf/
/// </summary>
/// <param name="drawingFile">Drawing File to use for the conversion</param>
/// <param name="outputDir">Output Directory to save the PDF to</param>
/// <param name="outputPdf">Output File Name (including extension)</param>
internal static void ConvertDwgToPdf(string drawingFile, string outputDir, string outputPdf)
{
// set license
if (license == null)
{
license = new License();
license.SetLicense(embeddedStream);
}
// Load the DWG file using Aspose.CAD
using (Image image = Image.Load(drawingFile))
{
/*
PaperKind paperKind = PaperKind.Ledger;
if (image.Width > image.Height)
{
paperKind = PaperKind.LetterRotated;
}
// get height and width of paper kind
*/
// create an instance of CadRasterizationOptions and set page height & width
// rasterization docs: https://docs.aspose.com/cad/net/developer-guide/converting-cad-drawings-to-pdf-and-raster-image-formats/
var rasterizationOptions = new CadRasterizationOptions()
{
PageWidth = image.Width,
PageHeight = image.Height,
// use color
// https://forum.aspose.com/t/dwg-converted-to-pdf-but-pdf-is-only-black-and-white-color-how-to-set-to-multi-color/209913/3
DrawType = CadDrawTypeMode.UseObjectColor,
Quality = HighQuality,
AutomaticLayoutsScaling = true // Enable auto layout scaling
};
// create an instance of PdfOptions
var options = new PdfOptions();
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export DWG to PDF
image.Save(Path.Combine(outputDir, outputPdf), options);
}
}
Troubleshooting
- I have been told that the image type should be one of the supported image types.
- I have been told the CAD properties of the item that does not appear are the same as the ones that do appear.
Regarding the code example provided, I think my code is similar. The Logo renders perfectly in Inventor DWGs, but this one logo
@jacobstokeswarner,
Hello.
It is hard to answer without the file. It could be feature we do not support if the image is OLE object, it could be bug if it is embedded as raster for instance. We need to reproduce the issue on our side, check its reading, processing and exporting and see exactly why it is missing. Please attach the file with such logo image for investigation.
1738.zip (164.9 KB)
See attached for compressed Zip File of the Logo.
@jacobstokeswarner,
thank you for details, we have logged CADNET-10178 to investigate the reason and fix.