我正在研究一个将autocad文件.dwg转换为PDF的asp.net项目。
我使用以下代码进行操作:
using (var image = Aspose.CAD.Image.Load(filePath))
{
// create an instance of CadRasterizationOptions & set resultant page size
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageSize = new Aspose.CAD.SizeF(image.Size.Width, image.Size.Height),
};
// save resultant PDF
image.Save("****" + "***", new Aspose.CAD.ImageOptions.PdfOptions() { VectorRasterizationOptions = rasterizationOptions });
}
我得到的pdf文件:
另一张图片
答案 0 :(得分:0)
我已观察到您共享的示例代码。您能否在导出的PDF中分享您遇到的问题。能否请您共享源DWG文件以及预期的输出PDF。同样,在您的上图中,当您在应用程序中设置Aspose.CAD的许可证时,左上角的水印也会被删除。
我正在Aspose中担任支持开发人员/宣传人员。
非常感谢
答案 1 :(得分:0)
我建议您尝试使用下面的示例代码来设置渲染文件的打印区域。
var cadImage =(CadImage) Aspose.CAD.Image.Load("filePath");
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.Layouts = new string[] { "Model" };
rasterizationOptions.NoScaling = true;
// note: preserving some empty borders around part of image is the responsibility of customer
// top left point of region to draw
Point topLeft = new Point(6156, 7053);
double width = 3108;
double height = 2489;
CadVportTableObject newView = new CadVportTableObject();
newView.Name = new CadStringParameter();
newView.Name.Init("*Active");
newView.CenterPoint.X = topLeft.X + width / 2f;
newView.CenterPoint.Y = topLeft.Y - height / 2f;
newView.ViewHeight.Value = height;
newView.ViewAspectRatio.Value = width / height;
for (int i = 0; i < cadImage.ViewPorts.Count; i++)
{
CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]);
if (cadImage.ViewPorts.Count == 1 || string.Equals(currentView.Name.Value.ToLowerInvariant(), "*active"))
{
cadImage.ViewPorts[i] = newView;
break;
}
}
cadImage.Save("Saved.pdf", new Aspose.CAD.ImageOptions.PdfOptions() { VectorRasterizationOptions = rasterizationOptions });