largeTextPfg

This commit is contained in:
Леонид Малафеев 2024-10-06 17:39:02 +04:00
parent 6b8069c9d9
commit 17d45a0339
7 changed files with 145 additions and 1 deletions

View File

@ -7,4 +7,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="docs\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,36 @@
namespace Controls
{
partial class LargeTextComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@ -0,0 +1,67 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Controls
{
public partial class LargeTextComponent : Component
{
private Document? _document;
private Section? _section;
public LargeTextComponent()
{
InitializeComponent();
}
public LargeTextComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateDocument(string docPath, string title, string[] rows)
{
if (string.IsNullOrEmpty(docPath))
{
throw new ArgumentNullException("Введите путь до файла!");
}
if (string.IsNullOrEmpty(title))
{
throw new ArgumentNullException("Введите заголовок");
}
if (rows.Length <= 0)
{
throw new ArgumentNullException("Нету данных для сохранения");
}
_document = new Document();
var style = _document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
_section = _document.AddSection();
var paragraph = _section.AddParagraph(title);
paragraph.Format.SpaceAfter = "0.1cm";
paragraph.Format.Font.Bold = true;
foreach (var row in rows)
{
_section.AddParagraph(row);
}
var renderer = new PdfDocumentRenderer(true);
renderer.Document = _document;
renderer.RenderDocument();
renderer.PdfDocument.Save(docPath);
}
}
}

Binary file not shown.

View File

@ -39,6 +39,8 @@
buttonGetBro = new Button();
toolTip = new ToolTip(components);
button1 = new Button();
largeTextComponent1 = new Controls.LargeTextComponent(components);
buttonLargeText = new Button();
SuspendLayout();
//
// customTextBoxNumber
@ -126,11 +128,22 @@
button1.UseVisualStyleBackColor = true;
button1.Click += buttonAdd_Click;
//
// buttonLargeText
//
buttonLargeText.Location = new Point(840, 42);
buttonLargeText.Name = "buttonLargeText";
buttonLargeText.Size = new Size(132, 51);
buttonLargeText.TabIndex = 9;
buttonLargeText.Text = "СОЗДАТЬ PDF";
buttonLargeText.UseVisualStyleBackColor = true;
buttonLargeText.Click += buttonLargeText_CLick;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(1025, 450);
Controls.Add(buttonLargeText);
Controls.Add(button1);
Controls.Add(buttonGetBro);
Controls.Add(buttonValidate);
@ -146,6 +159,11 @@
PerformLayout();
}
private void ButtonLargeText_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
#endregion
private Controls.CustomTextBoxNumber customTextBoxNumber;
@ -158,5 +176,7 @@
private Button buttonGetBro;
private ToolTip toolTip;
private Button button1;
private Controls.LargeTextComponent largeTextComponent1;
private Button buttonLargeText;
}
}

View File

@ -64,5 +64,12 @@ namespace Forms
{
customComboBox.ComboBoxItems.Add("abobaSECRET");
}
private void buttonLargeText_CLick(object sender, EventArgs e)
{
string[] strings = new string[] { "aboba", "not aboba" , "best aboba"};
LargeTextComponent largeText = new LargeTextComponent();
largeText.CreateDocument("C:\\Ulstu\\COP\\Cop_25\\Controls\\docs\\text.pdf", "OMEGA LABA 2", strings);
}
}
}

View File

@ -120,4 +120,10 @@
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="largeTextComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>125, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>48</value>
</metadata>
</root>