【问题标题】:How to convert an autocad file to a pdf file with clear view?如何将AutoCAD文件转换为具有清晰视图的pdf文件?
【发布时间】:2018-12-11 11:49:42
【问题描述】:

我正在开发一个将 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:

另一张图片

我希望建筑物位于 pdf 文件的中心,并且足够大以对用户有用。我怎样才能修正这个观点并使其清晰?

【问题讨论】:

  • 我发现 PDF 质量很高。请阅读How to Ask 并详细说明您要更改的内容。

标签: c# aspose


【解决方案1】:

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

我在 Aspose 担任支持开发人员/宣传员。

非常感谢

【讨论】:

  • 很遗憾,出于保密原因,我无法共享 dwg 文件。我希望建筑物位于 pdf 文件的中心,并且足够大以对用户有用。
【解决方案2】:

我建议您尝试使用下面的示例代码来设置渲染文件的打印区域。

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

【讨论】:

  • 我试过你的代码。我收到此错误 File Loading Failed: Input data is not Recognized as valid pdf 。当我打开文件时,我发现它是带有空白页的 chrome html 文档
  • 我需要在您端引起问题的 DWG 文件来验证问题。很遗憾,如果不提供所要求的信息,我可能无法为您提供进一步的帮助。
猜你喜欢
  • 1970-01-01
  • 2014-12-06
  • 2014-07-17
  • 2019-06-03
  • 2010-12-23
  • 2011-11-26
  • 2012-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多