我正在寻找一个解决方案来创建一个文档( PDF ),这样我就可以计算一个输入字段:PDF内容应该如下所示
(所有pdf内容都需要居中)
标题
Field1 :不是动态的(需要居中)
Field2 : UserName (dynamic-需要在段落的中心附加)--因为每个用户的名称长度不同
因此,我的问题是,pdfSharp或migraDoc是否有一种方法或什么东西可以使文本与中心对齐(这意味着它做了一些计算-确定字体系列、字体大小和魔法,以便标记的文本最终以中心为中心)?如果是这样的话,我搜索了migraDoc和pdfSharp文档之后,方法是什么,却找不到这样的东西。
如果这种方法不存在,有人尝试过吗?用过它吗?有什么建议,我如何才能实现这一行为?也许有什么消息来源可以看。谢谢
发布于 2016-06-14 07:08:03
样本1用大量的代码示例演示了如何创建pdf并使用Migradoc提供的几乎所有功能。示例2详细展示了如何创建表,这对您可能对页面内容的布局也感兴趣。
对齐(中间/左/右)通常通过设置Format.Alignment属性来完成,如下所示:
Paragraph par = new Paragraph();
par.Format.Alignment = ParagraphAlignment.Center;具有居中内容的文档的简短版本如下:
// first you need a document
Document MigraDokument  = new Document();
// each document needs at least one section
Section section = MigraDokument.AddSection();
section.PageSetup.PageFormat = PageFormat.A4;
// and then you add paragraphs to the section
Paragraph par = section.AddParagraph();
// and set the alignment as you wish
par.Format.Alignment = ParagraphAlignment.Center;
// now just fill it with content and set the rest of the parameters...
par.AddText("text");https://stackoverflow.com/questions/37743895
复制相似问题