#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 简单的Aspose.CAD许可证测试 功能:通过实际转换测试来验证许可证状态 作者:AI Assistant 日期:2024 """ import os import sys from pathlib import Path def test_license_by_conversion(): """通过转换测试许可证状态""" print("=" * 60) print(" Aspose.CAD 许可证状态测试 ") print("=" * 60) try: import aspose.cad as cad from aspose.cad.imageoptions import CadRasterizationOptions, PngOptions from aspose.cad import Color print(f"✓ Aspose.CAD版本: {cad.VERSION}") # 查找DWG文件 dwg_files = list(Path('.').glob('*.dwg')) if not dwg_files: print("✗ 未找到DWG文件进行测试") return test_file = str(dwg_files[0]) print(f"✓ 使用测试文件: {test_file}") # 加载DWG文件 print("正在加载DWG文件...") with cad.Image.load(test_file) as image: print(f"✓ 成功加载DWG文件") print(f" 图像尺寸: {image.width} x {image.height}") # 尝试转换 print("正在尝试转换为PNG...") try: # 设置光栅化选项 raster_options = CadRasterizationOptions() raster_options.page_width = 800 raster_options.page_height = 600 raster_options.background_color = Color.white # 设置PNG选项 png_options = PngOptions() png_options.vector_rasterization_options = raster_options # 保存为PNG output_path = "license_test_output.png" image.save(output_path, png_options) # 检查输出文件 if os.path.exists(output_path): file_size = os.path.getsize(output_path) print(f"✓ 转换成功!") print(f" 输出文件: {output_path}") print(f" 文件大小: {file_size:,} 字节 ({file_size/1024:.2f} KB)") # 分析结果 if file_size > 1000: # 大于1KB print(f"\n🎉 许可证状态分析:") print(f" ✓ 转换成功且文件大小正常") print(f" ✓ 可能已获得有效许可证") print(f" ✓ 或者这是评估版但功能正常") else: print(f"\n⚠️ 许可证状态分析:") print(f" ⚠ 文件大小较小,可能有许可证限制") # 清理测试文件 try: os.remove(output_path) print(f" ✓ 已清理测试文件") except: pass else: print(f"✗ 转换失败,未生成输出文件") print(f" → 这可能是许可证限制") except Exception as e: error_msg = str(e) print(f"✗ 转换失败: {error_msg}") # 分析错误类型 if "evaluation" in error_msg.lower(): print(f" → 这是评估版限制") elif "trial" in error_msg.lower(): print(f" → 这是试用版限制") elif "license" in error_msg.lower(): print(f" → 这是许可证问题") elif "watermark" in error_msg.lower(): print(f" → 这是水印限制") else: print(f" → 这可能是其他技术问题") except Exception as e: print(f"✗ 测试失败: {e}") def check_license_methods(): """检查许可证相关方法""" print("\n" + "=" * 60) print(" 检查许可证相关方法 ") print("=" * 60) try: import aspose.cad as cad from aspose.cad import License # 创建许可证对象 license_obj = License() print(f"✓ 成功创建License对象") # 检查可用的方法 methods = [attr for attr in dir(license_obj) if not attr.startswith('_')] print(f"✓ 可用方法: {methods}") # 尝试设置许可证(如果有许可证文件) print(f"\n尝试设置许可证:") license_files = list(Path('.').glob('*.lic')) if license_files: license_file = str(license_files[0]) print(f" 找到许可证文件: {license_file}") try: license_obj.set_license(license_file) print(f" ✓ 成功设置许可证") except Exception as e: print(f" ✗ 设置许可证失败: {e}") else: print(f" ℹ 未找到许可证文件(.lic)") print(f" ℹ 当前使用默认许可证状态") except Exception as e: print(f"✗ 检查许可证方法失败: {e}") def main(): """主函数""" print("Aspose.CAD 许可证状态检查工具") print("通过实际转换测试来验证许可证状态") print() # 通过转换测试许可证 test_license_by_conversion() # 检查许可证方法 check_license_methods() # 总结 print("\n" + "=" * 60) print(" 总结和建议 ") print("=" * 60) print("1. 如果转换成功且文件大小正常 → 许可证状态良好") print("2. 如果转换失败或出现评估版错误 → 需要购买许可证") print("3. 如果输出文件包含水印 → 这是评估版的正常行为") print("\n建议:") print("- 评估版通常有功能限制或水印") print("- 商业使用需要购买Aspose.CAD许可证") print("- 联系Aspose技术支持获取帮助") if __name__ == "__main__": try: main() except KeyboardInterrupt: print("\n\n用户中断了程序执行") except Exception as e: print(f"\n\n程序执行出错: {e}") import traceback traceback.print_exc()