c# - 使用 MigraDoc 将文本与图像对齐的问题

标签 c# pdf-generation migradoc

我有这种格式的标题--

标题”“图片”“标题”

下面是我用来实现此目的的代码片段 -

    Paragraph header = section.Headers.Primary.AddParagraph("Heading");            
    header.Format.Font.Bold = true;
    header.AddTab();
    Image image = header.AddImage("../../Images/logo.png");
    image.Height = Unit.FromMillimeter(6);
    header.AddFormattedText("Title", TextFormat.NotBold);

我需要对齐我的“图像”和“标题”,使标题相对于图像的高度垂直居中对齐,我怎样才能实现这一点?

非常感谢任何指针/代码片段。

最佳答案

您可以使用表格将所有信息放入特定的结构中:

// create document
Document MigraDokument = new Document();

// create section. 
Section section = MigraDokument.AddSection();            
section.PageSetup.PageFormat = PageFormat.A4;

// create a table
Table t = section.AddTable();
// size to use for the image and the image cell in the table
int size = 6;

// create 3 columns
Column column_header = t.AddColumn("6cm");
column_header.Format.Alignment = ParagraphAlignment.Center;

Column column_image = t.AddColumn(Unit.FromMillimeter(size));
column_image.Format.Alignment = ParagraphAlignment.Center;

Column column_text = t.AddColumn("4cm");
column_text.Format.Alignment = ParagraphAlignment.Center;

// Add 1 row to fill it with the content
Row r = t.AddRow();

// add you Header
Paragraph header = r.Cells[0].AddParagraph("Heading");
header.Format.Font.Bold = true;
header.AddTab();

// add the image            
Image image = r.Cells[1].AddImage("../../logo.png"); 
image.Height = Unit.FromMillimeter(size);

// Add your Title
r.Cells[2].AddParagraph("Title");

// allign all of them
r.Cells[0].VerticalAlignment = VerticalAlignment.Center;
r.Cells[1].VerticalAlignment = VerticalAlignment.Center;
r.Cells[2].VerticalAlignment = VerticalAlignment.Center;

在我的文档中,结果如下所示:

enter image description here

关于c# - 使用 MigraDoc 将文本与图像对齐的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39572213/

相关文章:

c# - 拒绝从 ASP.NET 网站启动进程

c# - 如何使用 itextsharp 将 UTF-8 字符写入 pdf 文件?

pdfsharp - 使用 PDFSharp 旋转表格单元格内的文本

bookmarks - pdfsharp没有相关书签的段落

c# - 用于 ASP.Net 应用程序的简单 Javascript 图像编辑器

c# - 协程中值为 true 后无法返回字符串

c# - 这些比较应该返回什么?

php - 我想使用 dompdf 在循环中创建多个 pdf?

python - 迪维希语 django-pisa pdf 的问题

c# - 为什么 MigraDoc 在我的 asp.net 应用程序中生成空白 pdf?