57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
|
using BarsukovComponents.NotVisualComponents.Configs;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using MigraDoc;
|
|||
|
using MigraDoc.DocumentObjectModel;
|
|||
|
using PdfSharp.Pdf;
|
|||
|
using MigraDoc.Rendering;
|
|||
|
using BarsukovComponents.Exceptions;
|
|||
|
|
|||
|
namespace BarsukovComponents.NotVisualComponents
|
|||
|
{
|
|||
|
public partial class PdfHugeText : Component
|
|||
|
{
|
|||
|
public PdfHugeText()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
public PdfHugeText(IContainer container)
|
|||
|
{
|
|||
|
container.Add(this);
|
|||
|
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
public void CreatePdf(TextPdfConf conf)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(conf.Filename) || string.IsNullOrEmpty(conf.Title) || conf.Rows.Count == 0)
|
|||
|
{
|
|||
|
throw new CustomException("Путь до файла, заголовок или текст пусты");
|
|||
|
}
|
|||
|
|
|||
|
Document document = new Document();
|
|||
|
|
|||
|
Section section = document.AddSection();
|
|||
|
Paragraph paragraphTitle = section.AddParagraph();
|
|||
|
paragraphTitle.AddText(conf.Title);
|
|||
|
paragraphTitle.Format.Font.Bold = true;
|
|||
|
paragraphTitle.Format.Font.Size = 20;
|
|||
|
paragraphTitle.Format.SpaceAfter = "0.3cm";
|
|||
|
|
|||
|
Paragraph paragraph = section.AddParagraph();
|
|||
|
paragraph.Format.Font.Size = 14;
|
|||
|
foreach (var row in conf.Rows)
|
|||
|
{
|
|||
|
paragraph.AddText(row + '\n');
|
|||
|
}
|
|||
|
|
|||
|
var renderer = new PdfDocumentRenderer(true);
|
|||
|
renderer.Document = document;
|
|||
|
renderer.RenderDocument();
|
|||
|
|
|||
|
renderer.PdfDocument.Save(conf.Filename);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|