[英]MigraDOC and pdfSharp, center dynamic text
i was looking for a solution to create a document (PDF) in such why that i can calculate an input field: The PDF content should look something like this 我一直在寻找一种创建文档(PDF)的解决方案,为什么可以计算输入字段:PDF内容应如下所示:
(all pdf content needs to be centered) (所有pdf内容都必须居中)
Header
标头
Field1 : not dynamic (needs to be centered)
Field1:不是动态的(需要居中)
Field2 : UserName (dynamic- needs to be appended in the center of the paragraph) - since each user has a different name length
Field2:用户名(动态-必须在段落的中间添加)-因为每个用户的名称长度都不同
So my questions is , does pdfSharp or migraDoc has a method or something that can align the text to center (meaning that it does some calculates - determine the font-family, font-size and does the magic so that in the end the marked text is centered) ? 所以我的问题是,pdfSharp或migraDoc是否有一种方法或某种可以使文本居中对齐的方法(这意味着它需要进行一些计算-确定字体系列,字体大小并进行魔术处理,以便最终标记文本居中)? If so what is the method since i've searched the migraDoc and pdfSharp documentation and could not find anything like that.
如果是这样,自从我搜索了migraDoc和pdfSharp文档以来找不到什么类似的方法,那是什么方法。
And if such method does not exist, did someone try this? 如果不存在这种方法,有人尝试过吗? worked with it?
工作了吗? has any suggestions how can i achieve this behavior?
有什么建议我如何实现这种行为? maybe some source to look from.
也许有一些来源可供参考。 Thank you
谢谢
Sample 1 shows with a lot of code example how to create a pdf and use almost all functionality that Migradoc offers. 示例1通过大量代码示例演示了如何创建pdf并使用Migradoc提供的几乎所有功能。 Sample 2 shows in detail how to create tables, which might also be interesting for you in respect to layout the page's content.
示例2详细显示了如何创建表,这对于您布局页面的内容可能也很有趣。
The alignment (center/left/right) is usually done by setting the Format.Alignment
property like this: 对齐方式(中心/左/右)通常是通过设置
Format.Alignment
属性来完成的,如下所示:
Paragraph par = new Paragraph();
par.Format.Alignment = ParagraphAlignment.Center;
A short version of a document with centered content would be: 具有居中内容的文档的简短版本为:
// 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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.