有些DWG转出来的PDF是居中显示,有些又显示在左侧,右侧,顶部,底部等,在转换的时候怎么设置把图画居中显示在PDF中?
DWG文件描述.zip (2.2 MB)
您好,我的现在的问题有2个:
1.DWG转出来的PDF,图没有填充满PDF的页面,或者能否居中全页显示
2.想在PDF里面填充姓名,能否根据图的边框的坐标定位,或者根据PDF页中指定文字来定位
There is no need to center drawing as it appears automatically. The size of the drawing is stored in EXTMIN/EXTMAX values in the Header section of the drawing. For this image the minimal point (rounded to integer) from EXTMIN is (1751;426;0), the max point is (2474;636;0). We have drawn this rectangle (Border.png), so you can see that minimal point is not correct. In some cases this may happen.
There is no way to detect this before export, but if this is a typical case for the customer, this operation may be added after the load: cadImage.UpdateSize(); and it corrects the size. I have attached the result of export.
Probably, you may add additional MTEXT (or TEXT) objects to the drawing near the required text fields. There is the example how to do it and result is attached too.
... loading of the image ...
List<CadBaseEntity> entities = new List<CadBaseEntity>(cadImage.Entities);
List<CadBaseEntity> addedEntities = new List<CadBaseEntity>();
foreach (CadBaseEntity baseEntity in entities)
{
if (baseEntity.TypeName != CadEntityTypeName.MTEXT)
{
continue;
}
else
{
CadMText mtext = (CadMText)baseEntity;
if (mtext.FullClearText == "设 计")
{
CadMText design = CreateMTextToTheRight(mtext, "Design");
// CadText design = CreateTextToTheRight(mtext, "Design");
addedEntities.Add(design);
}
if (mtext.FullClearText == "审 核")
{
CadMText audit = CreateMTextToTheRight(mtext, "Audit");
// CadText audit = CreateTextToTheRight(mtext, "Audit");
addedEntities.Add(audit);
}
if (mtext.FullClearText == "批 准")
{
CadMText audit = CreateMTextToTheRight(mtext, "Approved");
// CadText audit = CreateTextToTheRight(mtext, "Approved");
addedEntities.Add(audit);
}
}
}
foreach (CadBaseEntity addedEntity in addedEntities)
{
addedEntity.SoftOwner = cadImage.Layouts["Model"].BlockTableRecordHandle;
cadImage.BlockEntities["*MODEL_SPACE"].AddEntity(addedEntity);
}
entities.AddRange(addedEntities);
cadImage.Entities = new List<CadBaseEntity>(entities).ToArray();
... export ...
private static CadMText CreateMTextToTheRight(CadMText mtext, string value)
{
CadMText newMText = new CadMText();
newMText.Text = value;
newMText.InitialTextHeight = mtext.InitialTextHeight;
// mtext.HorizontalWidth may be useful too to get the width of the mtext
newMText.InsertionPoint = new Cad3DPoint(mtext.InsertionPoint.X + mtext.ReferenceRectangleWidth, mtext.InsertionPoint.Y);
newMText.LayerName = mtext.LayerName;
return newMText;
}
private static CadText CreateTextToTheRight(CadMText mtext, string value)
{
CadText text = new CadText();
text.DefaultValue = value;
text.TextHeight = mtext.InitialTextHeight;
text.FirstAlignment = new Cad3DPoint(mtext.InsertionPoint.X + mtext.ReferenceRectangleWidth, mtext.InsertionPoint.Y - text.TextHeight);
text.LayerName = mtext.LayerName;
return text;
}
T076025003A.dwg.pdf (430.1 KB)
T076025003A.dwg.pdf (430.1 KB)
Border.png (15.9 KB)
您好,非常感谢你的解答,很有用。
还有一个小问题,
if (mtext.FullClearText == “设 计”)
{
CadMText design = CreateMTextToTheRight(mtext, “Design”);
// CadText design = CreateTextToTheRight(mtext, “Design”);
addedEntities.Add(design);
}
这里我可以插入一张图片吗?
是的,有没有别的类是可以处理图片的,插入到指定位置
if (mtext.FullClearText == “设 计”)
{
CadMText design = CreateMTextToTheRight(mtext, “Design”);
// CadText design = CreateTextToTheRight(mtext, “Design”);
addedEntities.Add(design);
}
这里插入文字的签名,有一个单元格,我想插入图片的签名(png格式的),有没有方法?不是在DWG中,是DWG转成后的PDF里面,因为DWG转出的PDF,每张图的尺寸不一样,不能根据坐标来定位。