Aspose.cad .net (23.7.0.0)dwg中多图框转PDF时,缩放位置不正确

Aspose.cad .net (23.7.0.0)dwg中多图框转PDF时,缩放位置不正确。我的代码和图纸都在压缩包里。我的缩放代码:
rasterizationOptions.RelativePosition = new Aspose.CAD.PointF
{
X = (float)( boxMinPt.X - cadImage.MinPoint.X) / width,
Y = (float)(cadImage.MaxPoint.Y - boxMaxPt.Y ) / height,

};
rasterizationOptions.RelativeScale = (float)(mapHeight) / (float)height;

缩放后只输出了部分图纸,请帮忙解答一下是什么问题。

test.zip (407.3 KB)

@hardp,
你好.
看来RelativePosition在这里不合适。 您能否尝试一下这个替换活动视图的示例是否符合您的需求:

using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(fileName))
{
      Point3D boxMinPt = new Point3D(180137.0, 86426.0, 0.0);
      Point3D boxMaxPt = new Point3D(269185.0, 128426.0, 0.0);

      PdfOptions pdfOptions = new PdfOptions();
      CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();

      double mapWidth = boxMaxPt.X - boxMinPt.X;
      double mapHeight = boxMaxPt.Y - boxMinPt.Y;

      rasterizationOptions.NoScaling = true;

      Point topLeft = new Point((int)cadImage.MinPoint.X, (int)cadImage.MaxPoint.Y);

      rasterizationOptions.PageWidth = (int)mapWidth;
      rasterizationOptions.PageHeight = (int)mapHeight;

      CadVportTableObject newView = new CadVportTableObject();

      // note: exactly such table name is required for active view
      newView.Name = "*Active";

      newView.CenterPoint.X = topLeft.X + mapWidth / 2;
      newView.CenterPoint.Y = topLeft.Y - mapHeight / 2;

      newView.ViewHeight = cadImage.Height / 2;

      newView.UseAspectRatio = true;
      newView.ViewAspectRatio = mapWidth / mapHeight;

      // search for active viewport and replace it
      for (int i = 0; i < cadImage.ViewPorts.Count; i++)
      {
          CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]);
          if ((currentView.Name == null && cadImage.ViewPorts.Count == 1) ||
              string.Equals(currentView.Name.ToLowerInvariant(), "*active"))
          {
              cadImage.ViewPorts[i] = newView;
              break;
          }
      }

      //将窗口导出选项应用于PDF选项
      pdfOptions.VectorRasterizationOptions = rasterizationOptions;

      cadImage.Save("result.pdf", pdfOptions);
}

我使用你给的代码后,导出的pdf文件还是带白边,我怎么去掉白边。还有导出的pdf尺寸能等比例缩小吗?如果能请给出解决代码。
我导出的文件如下。
pdf.zip (754.9 KB)

我用你的代码用其他的dwg文件导出pdf后只有一部分。
test-1.zip (351.3 KB)
我导出PDF的设置代码:
if (File.Exists(ctbPath))
{
string ctbFile = layoutInfo.Item3.CurrentStyleSheet;
ctbFileStream = new FileStream(ctbPath, FileMode.Open);
rasterizationOptions.CtbSources = new Dictionary<string, Stream>();
rasterizationOptions.CtbSources.Add(ctbFile, ctbFileStream);
}
rasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
rasterizationOptions.VisibilityMode = VisibilityMode.AsPrint;
rasterizationOptions.Zoom = 1f;

if (fontPath != null && fontPath.Length > 0)
{
rasterizationOptions.ShxFonts = fontPath;
}

rasterizationOptions.Layouts = new string[] { layoutInfo.Item1 };
//rasterizationOptions.Layouts = new string[] { “布局1” };

@hardp,
你好。
您可以检查一下这是否更好:

using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(fileName))
{
	Point3D boxMinPt = new Point3D(180137.0, 86426.0, 0.0);
	Point3D boxMaxPt = new Point3D(269185.0, 128426.0, 0.0);

	PdfOptions pdfOptions = new PdfOptions();
	CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();

	double mapWidth = boxMaxPt.X - boxMinPt.X;
	double mapHeight = boxMaxPt.Y - boxMinPt.Y;

	rasterizationOptions.NoScaling = true;

	Point topLeft = new Point((int)boxMinPt.X, (int)boxMaxPt.Y);

	rasterizationOptions.PageWidth = (int)mapWidth;
	rasterizationOptions.PageHeight = (int)mapHeight;

	CadVportTableObject newView = new CadVportTableObject();

	// note: exactly such table name is required for active view
	newView.Name = "*Active";

	newView.CenterPoint.X = topLeft.X + mapWidth / 2;
	newView.CenterPoint.Y = topLeft.Y - mapHeight / 2;

	newView.ViewHeight = mapHeight;

	newView.UseAspectRatio = true;
	newView.ViewAspectRatio = mapWidth / mapHeight;

	// search for active viewport and replace it
	for (int i = 0; i < cadImage.ViewPorts.Count; i++)
	{
		CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]);
		if ((currentView.Name == null && cadImage.ViewPorts.Count == 1) ||
			string.Equals(currentView.Name.ToLowerInvariant(), "*active"))
		{
			cadImage.ViewPorts[i] = newView;
			break;
		}
	}

	pdfOptions.VectorRasterizationOptions = rasterizationOptions;

	cadImage.Save("result.pdf", pdfOptions);
}

您能否澄清“test-1.dwg”的目标? 您想仅导出白盒内的区域吗?

@oleksii.gorokhovatskyi 是的我只想导出白色盒内的区域。

@hardp,
看起来同样的方法可以解决问题(我添加了一些间隙,因此边框也可见):

using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(fileName))
{
	int gap = 50;
	Point3D boxMinPt = new Point3D(-1077122 - gap, -34679 - gap, 0.0);
	Point3D boxMaxPt = new Point3D(-1035122 + gap, -4979 + gap, 0.0);

	PdfOptions pdfOptions = new PdfOptions();
	CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();

	double mapWidth = boxMaxPt.X - boxMinPt.X;
	double mapHeight = boxMaxPt.Y - boxMinPt.Y;

	rasterizationOptions.NoScaling = true;

	Point topLeft = new Point((int)boxMinPt.X, (int)boxMaxPt.Y);

	rasterizationOptions.PageWidth = (int)mapWidth;
	rasterizationOptions.PageHeight = (int)mapHeight;

	CadVportTableObject newView = new CadVportTableObject();

	// note: exactly such table name is required for active view
	newView.Name = "*Active";

	newView.CenterPoint.X = topLeft.X + mapWidth / 2;
	newView.CenterPoint.Y = topLeft.Y - mapHeight / 2;

	newView.ViewHeight = mapHeight;

	newView.UseAspectRatio = true;
	newView.ViewAspectRatio = mapWidth / mapHeight;

	// search for active viewport and replace it
	for (int i = 0; i < cadImage.ViewPorts.Count; i++)
	{
		CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]);
		if ((currentView.Name == null && cadImage.ViewPorts.Count == 1) ||
			string.Equals(currentView.Name.ToLowerInvariant(), "*active"))
		{
			cadImage.ViewPorts[i] = newView;
			break;
		}
	}

	rasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
	rasterizationOptions.VisibilityMode = VisibilityMode.AsPrint;
	rasterizationOptions.Zoom = 1f;

	if (fontPath != null && fontPath.Length > 0)
	{
		rasterizationOptions.ShxFonts = fontPath;
	}

	rasterizationOptions.Layouts = new string[] { "Model" };

	pdfOptions.VectorRasterizationOptions = rasterizationOptions;

	cadImage.Save("result.pdf", pdfOptions);
}

输出的pdf 尺寸能等比例缩放吗?

@hardp,
如果你的意思是这样的:

rasterizationOptions.PageWidth = (int)mapWidth/4;
rasterizationOptions.PageHeight = (int)mapHeight/4;

是的,它有效。