我有一个TextFrame(BlueWorkOrderLine)(还有一个图像),在主标题中设置了“ WrapStyle.Through”。我想将其从页面顶部边缘定位为“ 40”。
“。Top”或“ .DistanceTop”似乎都不起作用。谁能告诉我我在做什么错?
一切似乎都符合我的期望。
public static Document CreateWorkOrderPDF2(Document document, string filename, string WorkOrderHeader, string myMessage)
{
Section section = document.AddSection();
section.PageSetup.PageFormat = PageFormat.Letter;
section.PageSetup.StartingNumber = 1;
section.PageSetup.LeftMargin = 40;
//Sets the height of the top margin
section.PageSetup.TopMargin = 100;
section.PageSetup.RightMargin = 40;
section.PageSetup.BottomMargin = 40;
/*HeaderFooter
*************/
HeaderFooter header = section.Headers.Primary;
header.Format.Font.Size = 16;
header.Format.Font.Color = Colors.DarkBlue;
header.AddParagraph();
/*Logo Image
***********/
MigraDoc.DocumentObjectModel.Shapes.Image headerImage = header.AddImage("../../Fonts/castorgate.regular.png");
headerImage.Width = "2cm";
headerImage.Top = 100;
headerImage.WrapFormat.DistanceTop = 200;
headerImage.WrapFormat.Style = WrapStyle.Through;
/*Blue Work Order Line
**********************/
TextFrame BlueWorkOrderLine = header.AddTextFrame();
BlueWorkOrderLine.Top = 40;
BlueWorkOrderLine.WrapFormat.DistanceTop = 40;
BlueWorkOrderLine.Left = 0;
BlueWorkOrderLine.Width = 300;
BlueWorkOrderLine.WrapFormat.Style = WrapStyle.Through;
Paragraph headerParagraph = BlueWorkOrderLine.AddParagraph(WorkOrderHeader);
headerParagraph.Format.Font.Name = "Consolas";
headerParagraph.Format.Font.Color = Colors.Blue;
headerParagraph.Format.Borders.Width = .5;
/*Vertical Text TextFrame
*************************/
TextFrame WorkOrderVerticalTextFrame = header.AddTextFrame();
WorkOrderVerticalTextFrame.Orientation = TextOrientation.Downward;
//moves text to the right
WorkOrderVerticalTextFrame.Left = 550;
WorkOrderVerticalTextFrame.Width = 10;
WorkOrderVerticalTextFrame.Top = 0;
WorkOrderVerticalTextFrame.Height = 150;
WorkOrderVerticalTextFrame.WrapFormat.Style = WrapStyle.Through;
Paragraph WorkOrderVerticalParagraph = WorkOrderVerticalTextFrame.AddParagraph();
//Paragraph WorkOrderVerticalParagraph = header.AddParagraph();
WorkOrderVerticalParagraph.Format.Alignment = ParagraphAlignment.Left;
WorkOrderVerticalParagraph.Format.Font.Name = "Consolas";
WorkOrderVerticalParagraph.Format.Font.Size = 8;
WorkOrderVerticalParagraph.AddText(WorkOrderHeader);
WorkOrderVerticalParagraph.Format.Borders.Width = .5;
//BODY PARAGRAPH
Paragraph EstRecordsParagraph = section.AddParagraph(myMessage);
EstRecordsParagraph.Format.Font.Size = 10;
EstRecordsParagraph.Format.Font.Color = Colors.DarkRed;
EstRecordsParagraph.Format.Borders.Width = .5;
EstRecordsParagraph.Format.RightIndent = 0;
Paragraph renderDate = section.AddParagraph();
renderDate = section.AddParagraph("Work Order Generated: ");
renderDate.AddDateField();
return document;
}
答案 0 :(得分:0)
我不完全了解TextFrames的所有位置选项,因此这只是一个猜测。也许您必须设置RelativeVertical
或其他选项之一才能获得想要的效果。
示例代码:
var tf = section.AddTextFrame();
tf.Width = "190mm";
tf.RelativeVertical = RelativeVertical.Page;
tf.Top = ShapePosition.Top;
tf.MarginTop = "230mm";