如何将AutoCAD文件转换为清晰的PDF文件?

3
我正在处理一个asp.net项目,将.autocad文件.dwg转换为PDF格式。
我使用以下代码实现此功能:
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文件是这个:

enter image description here

另一张图片

在此输入图片描述 我希望建筑物位于pdf文件的中心,并且足够大以便用户使用。我该如何调整视图并使其清晰可见?


我发现那个 PDF 的质量相当高。请仔细阅读并具体说明您想要修改的内容。 - CodeCaster
2个回答

0

我已经查看了您分享的示例代码。您能否请分享一下您在导出PDF时遇到的问题。同时,能否请提供源DWG文件以及预期输出的PDF文件。此外,在您上面的图像中,当您在应用程序中设置Aspose.CAD的许可证时,左上角的水印将被删除。

我是Aspose的支持开发者/布道者。

非常感谢


很遗憾,由于保密原因,我无法分享DWG文件。我希望建筑物位于PDF文件的中心,并且足够大以便用户使用。 - s.e

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 });

我尝试了你的代码。当我打开文件时,出现了“文件加载失败:输入数据未被识别为有效的pdf”错误,并发现它是一个带有空白页面的Chrome HTML文档。 - s.e
我需要你那边引起问题的DWG文件以验证问题。不幸的是,如果没有提供请求的信息,我可能无法为您提供进一步的帮助。 - Mudassir

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接