ну сделал один компонент
This commit is contained in:
parent
a94ad17abc
commit
c281e4e07b
36
CheckedListBoxLibrary/Components/PdfImage/PdfImage.Designer.cs
generated
Normal file
36
CheckedListBoxLibrary/Components/PdfImage/PdfImage.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace MyUserControls.Components.PdfImage
|
||||
{
|
||||
partial class PdfImage
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
47
CheckedListBoxLibrary/Components/PdfImage/PdfImage.cs
Normal file
47
CheckedListBoxLibrary/Components/PdfImage/PdfImage.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using MyUserControls.Components.office_package;
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using MyUserControls.Components.office_package.HelperModels;
|
||||
using MyUserControls.Components.office_package.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.PdfImage
|
||||
{
|
||||
public partial class PdfImage : Component
|
||||
{
|
||||
ISaveToPdf SaveToPdf = new SaveToPdf();
|
||||
|
||||
public PdfImage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfImage(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreatePdf(PdfImageInfo info)
|
||||
{
|
||||
info.CheckFields();
|
||||
SaveToPdf.CreatePdf(info);
|
||||
SaveToPdf.CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = info.Title,
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
foreach (var image in info.Images)
|
||||
{
|
||||
SaveToPdf.CreateImage(image);
|
||||
}
|
||||
SaveToPdf.SavePdf(info);
|
||||
}
|
||||
}
|
||||
}
|
24
CheckedListBoxLibrary/Components/PdfImage/PdfImageInfo.cs
Normal file
24
CheckedListBoxLibrary/Components/PdfImage/PdfImageInfo.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using MyUserControls.Components.office_package.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.PdfImage
|
||||
{
|
||||
public class PdfImageInfo : IPdfInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<byte[]> Images { get; set; } = new List<byte[]>();
|
||||
|
||||
public void CheckFields()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(FileName) || string.IsNullOrWhiteSpace(Title) || Images == null || Images.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("Все поля должны быть заполнены.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
CheckedListBoxLibrary/Components/PdfTable/PdfTable.Designer.cs
generated
Normal file
36
CheckedListBoxLibrary/Components/PdfTable/PdfTable.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace MyUserControls.Components.PdfTable
|
||||
{
|
||||
partial class PdfTable
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
25
CheckedListBoxLibrary/Components/PdfTable/PdfTable.cs
Normal file
25
CheckedListBoxLibrary/Components/PdfTable/PdfTable.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.PdfTable
|
||||
{
|
||||
public partial class PdfTable : Component
|
||||
{
|
||||
public PdfTable()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfTable(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
12
CheckedListBoxLibrary/Components/PdfTable/PdfTableInfo.cs
Normal file
12
CheckedListBoxLibrary/Components/PdfTable/PdfTableInfo.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.PdfTable
|
||||
{
|
||||
internal class PdfTableInfo
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperEnums
|
||||
{
|
||||
public enum PdfCellsMergeDirections
|
||||
{
|
||||
Down,
|
||||
Right
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperEnums
|
||||
{
|
||||
public enum PdfDiagramLegendLocation
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom,
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperEnums
|
||||
{
|
||||
public enum PdfParagraphAlignmentType
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public interface IPdfInfo
|
||||
{
|
||||
public string FileName { get; }
|
||||
public string Title { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public interface IPdfPieChartParameters
|
||||
{
|
||||
public string ChartTitle { get; }
|
||||
public PdfDiagramLegendLocation LegendLocation { get; }
|
||||
public PdfDiagramSeries Series { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public interface ITableTextParameters
|
||||
{
|
||||
public string Style { get; }
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public class PdfCellParameters : ITableTextParameters
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public class PdfCellsMergeParameters
|
||||
{
|
||||
public int RowIndex = 0;
|
||||
public int ColumnIndex = 0;
|
||||
public PdfCellsMergeDirections Direction;
|
||||
public int CellNumber = 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public class PdfColumnParameters : ITableTextParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public int ColumnIndex = 0;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public class PdfDiagramSeries
|
||||
{
|
||||
public string SeriesName { get; set; } = string.Empty;
|
||||
public Dictionary<string, double> Data = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public class PdfParagraph
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package.HelperModels
|
||||
{
|
||||
public class PdfRowParameters : ITableTextParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
using MyUserControls.Components.office_package.HelperModels;
|
||||
using MyUserControls.Components.PdfImage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components.office_package
|
||||
{
|
||||
public interface ISaveToPdf
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
void CreatePdf(IPdfInfo info);
|
||||
/// <summary>
|
||||
/// Создание параграфа с текстом
|
||||
/// </summary>
|
||||
void CreateParagraph(PdfParagraph paragraph);
|
||||
/// <summary>
|
||||
/// Создание изображения в pdf файле
|
||||
/// </summary>
|
||||
void CreateImage(byte[] image);
|
||||
/// <summary>
|
||||
/// Создание таблицы
|
||||
/// определенной ширины
|
||||
/// </summary>
|
||||
void CreateTable();
|
||||
/// <summary>
|
||||
/// Создание таблицы с заданным количеством столбцов
|
||||
/// определенной ширины
|
||||
/// </summary>
|
||||
void CreateTableWithColumns(List<string> columns);
|
||||
/// <summary>
|
||||
/// Создание таблицы с заданным количеством столбцов
|
||||
/// </summary>
|
||||
void CreateTableWithColumns(int columnNumber);
|
||||
/// <summary>
|
||||
/// Создание и заполнение строки
|
||||
/// </summary>
|
||||
/// <param name="rowParameters"></param>
|
||||
void CreateRow(PdfRowParameters rowParameters);
|
||||
/// <summary>
|
||||
/// Создание и заполнение столбца
|
||||
/// </summary>
|
||||
void InsertTextIntoColumn(PdfColumnParameters columnParameters);
|
||||
/// <summary>
|
||||
/// Создание и заполнение ячейки
|
||||
/// </summary>
|
||||
void InsertTextIntoCell(int rowIndex, int columnIndex, PdfCellParameters cellParameters);
|
||||
/// <summary>
|
||||
/// Создание и заполнение ячейки
|
||||
/// </summary>
|
||||
void MergeCells(PdfCellsMergeParameters parameters);
|
||||
/// <summary>
|
||||
/// Создание и заполнение круговой диаграммы
|
||||
/// </summary>
|
||||
void CreatePieChart(IPdfPieChartParameters parameters);
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
void SavePdf(IPdfInfo info);
|
||||
}
|
||||
}
|
@ -0,0 +1,256 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
using System.Reflection;
|
||||
using System.Data.Common;
|
||||
using MigraDoc.DocumentObjectModel.Shapes;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MyUserControls.Components.office_package.HelperEnums;
|
||||
using MyUserControls.Components.office_package.HelperModels;
|
||||
|
||||
namespace MyUserControls.Components.office_package.Implements
|
||||
{
|
||||
public class SaveToPdf : ISaveToPdf
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
|
||||
private readonly Unit BORDER_WIDTH = 0.5;
|
||||
private readonly Unit COLUMN_WIDTH = Unit.FromCentimeter(3.5);
|
||||
private readonly Unit IMAGE_WIDTH = Unit.FromCentimeter(15);
|
||||
|
||||
public void CreatePdf(IPdfInfo info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
public void SavePdf(IPdfInfo info)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(info.FileName))
|
||||
{
|
||||
throw new ArgumentNullException("Имя файла не задано");
|
||||
}
|
||||
|
||||
if (_document == null || _section == null)
|
||||
{
|
||||
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
|
||||
}
|
||||
var renderer = new PdfDocumentRenderer(true){
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
private static ParagraphAlignment GetParagraphAlignment(
|
||||
PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
|
||||
private static void DefineStyles(Document document)
|
||||
{
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
|
||||
public void CreateParagraph(PdfParagraph pdfParagraph)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_section == null)
|
||||
{
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
||||
paragraph.Style = pdfParagraph.Style;
|
||||
}
|
||||
public void CreateImage(byte[] image)
|
||||
{
|
||||
if (image == null || image.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException("Картинка не загружена");
|
||||
}
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_section == null)
|
||||
{
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
var imageFileName = Path.GetTempFileName();
|
||||
File.WriteAllBytes(imageFileName, image);
|
||||
var img = _section.AddImage(imageFileName);
|
||||
img.Width = IMAGE_WIDTH;
|
||||
img.LockAspectRatio = true;
|
||||
_section.AddParagraph();
|
||||
}
|
||||
public void CreateTable()
|
||||
{
|
||||
if (_document == null || _section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _section.AddTable();
|
||||
}
|
||||
|
||||
public void CreateTableWithColumns(List<string> columns)
|
||||
{
|
||||
if (_document == null || _section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _section.AddTable();
|
||||
foreach (var elem in columns)
|
||||
{
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateTableWithColumns(int columnNumber)
|
||||
{
|
||||
if (_document == null || _section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _section.AddTable();
|
||||
for (int i = 0; i < columnNumber; i++)
|
||||
{
|
||||
_table.AddColumn(COLUMN_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateRow(PdfRowParameters rowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(rowParameters.Texts[i]))
|
||||
InsertTextIntoCell(row.Index, i, rowParameters, rowParameters.Texts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertTextIntoColumn(PdfColumnParameters columnParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < columnParameters.Texts.Count; ++i)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(columnParameters.Texts[i]))
|
||||
InsertTextIntoCell(i, columnParameters.ColumnIndex, columnParameters, columnParameters.Texts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertTextIntoCell(int rowIndex, int columnIndex, PdfCellParameters cellParameters)
|
||||
{
|
||||
InsertTextIntoCell(rowIndex, columnIndex, cellParameters, cellParameters.Text);
|
||||
}
|
||||
|
||||
private void InsertTextIntoCell(int rowIndex, int columnIndex, ITableTextParameters parameters, string text)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Cell cell = _table.Rows[rowIndex].Cells[columnIndex];
|
||||
cell.AddParagraph(text);
|
||||
if (!string.IsNullOrEmpty(parameters.Style))
|
||||
{
|
||||
cell.Style = parameters.Style;
|
||||
}
|
||||
cell.Borders.Left.Width = BORDER_WIDTH;
|
||||
cell.Borders.Right.Width = BORDER_WIDTH;
|
||||
cell.Borders.Top.Width = BORDER_WIDTH;
|
||||
cell.Borders.Bottom.Width = BORDER_WIDTH;
|
||||
cell.Format.Alignment = GetParagraphAlignment(
|
||||
parameters.ParagraphAlignment);
|
||||
cell.VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
|
||||
public void MergeCells(PdfCellsMergeParameters parameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Cell cell = _table.Rows[parameters.RowIndex].Cells[parameters.ColumnIndex];
|
||||
switch (parameters.Direction)
|
||||
{
|
||||
case PdfCellsMergeDirections.Down:
|
||||
cell.MergeDown = parameters.CellNumber;
|
||||
break;
|
||||
case PdfCellsMergeDirections.Right:
|
||||
cell.MergeRight = parameters.CellNumber;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void CreatePieChart(IPdfPieChartParameters parameters)
|
||||
{
|
||||
if (_document == null || _section == null)
|
||||
throw new ArgumentNullException(nameof(_document), "Document is not created.");
|
||||
Chart chart = new Chart(ChartType.Pie2D);
|
||||
Series series = chart.SeriesCollection.AddSeries();
|
||||
series.Name = parameters.Series.SeriesName;
|
||||
series.Add(parameters.Series.Data.Select(x => x.Value).ToArray());
|
||||
chart.XValues.AddXSeries().Add(parameters.Series.Data.Select(x => x.Key).ToArray());
|
||||
ConfigChart(parameters, chart);
|
||||
_section.Add(chart);
|
||||
}
|
||||
|
||||
private void ConfigChart(IPdfPieChartParameters parameters, Chart chart)
|
||||
{
|
||||
chart.DataLabel.Type = DataLabelType.Percent;
|
||||
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
||||
chart.Width = Unit.FromCentimeter(16.0);
|
||||
chart.Height = Unit.FromCentimeter(12.0);
|
||||
chart.TopArea.AddParagraph(parameters.ChartTitle);
|
||||
chart.XAxis.MajorTickMark = (TickMarkType)2;
|
||||
chart.YAxis.MajorTickMark = (TickMarkType)2;
|
||||
chart.YAxis.HasMajorGridlines = true;
|
||||
chart.PlotArea.LineFormat.Width = new Unit(1);
|
||||
chart.PlotArea.LineFormat.Visible = true;
|
||||
switch (parameters.LegendLocation)
|
||||
{
|
||||
case PdfDiagramLegendLocation.Left:
|
||||
chart.LeftArea.AddLegend();
|
||||
break;
|
||||
case PdfDiagramLegendLocation.Right:
|
||||
chart.RightArea.AddLegend();
|
||||
break;
|
||||
case PdfDiagramLegendLocation.Top:
|
||||
chart.TopArea.AddLegend();
|
||||
break;
|
||||
case PdfDiagramLegendLocation.Bottom:
|
||||
chart.BottomArea.AddLegend();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,4 +7,12 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Components\PdfDiagram\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
BIN
WinFormsApp1/Documents/PdfWithImage.pdf
Normal file
BIN
WinFormsApp1/Documents/PdfWithImage.pdf
Normal file
Binary file not shown.
54
WinFormsApp1/Form1.Designer.cs
generated
54
WinFormsApp1/Form1.Designer.cs
generated
@ -35,11 +35,15 @@
|
||||
testComponent1 = new MyUserControls.Components.testComponent(components);
|
||||
buttonSave = new Button();
|
||||
richTextBoxText = new RichTextBox();
|
||||
pdfImage = new MyUserControls.Components.PdfImage.PdfImage(components);
|
||||
listBoxImages = new ListBox();
|
||||
chooseImage = new Button();
|
||||
createPdfImages = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// smartCheckedListBox1
|
||||
//
|
||||
smartCheckedListBox1.Location = new Point(37, 12);
|
||||
smartCheckedListBox1.Location = new Point(12, 12);
|
||||
smartCheckedListBox1.Name = "smartCheckedListBox1";
|
||||
smartCheckedListBox1.SelectedValue = "";
|
||||
smartCheckedListBox1.Size = new Size(241, 182);
|
||||
@ -47,23 +51,23 @@
|
||||
//
|
||||
// smartTextBox1
|
||||
//
|
||||
smartTextBox1.Location = new Point(12, 318);
|
||||
smartTextBox1.Location = new Point(0, 329);
|
||||
smartTextBox1.MaxLength = 100;
|
||||
smartTextBox1.MinLength = 0;
|
||||
smartTextBox1.Name = "smartTextBox1";
|
||||
smartTextBox1.Size = new Size(312, 98);
|
||||
smartTextBox1.Size = new Size(295, 98);
|
||||
smartTextBox1.TabIndex = 2;
|
||||
//
|
||||
// hierarchicalTreeView
|
||||
//
|
||||
hierarchicalTreeView.Location = new Point(12, 163);
|
||||
hierarchicalTreeView.Location = new Point(0, 162);
|
||||
hierarchicalTreeView.Name = "hierarchicalTreeView";
|
||||
hierarchicalTreeView.Size = new Size(266, 174);
|
||||
hierarchicalTreeView.TabIndex = 3;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(337, 162);
|
||||
buttonSave.Location = new Point(337, 111);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(168, 32);
|
||||
buttonSave.TabIndex = 4;
|
||||
@ -75,15 +79,47 @@
|
||||
//
|
||||
richTextBoxText.Location = new Point(337, 26);
|
||||
richTextBoxText.Name = "richTextBoxText";
|
||||
richTextBoxText.Size = new Size(168, 130);
|
||||
richTextBoxText.Size = new Size(168, 70);
|
||||
richTextBoxText.TabIndex = 5;
|
||||
richTextBoxText.Text = "";
|
||||
//
|
||||
// listBoxImages
|
||||
//
|
||||
listBoxImages.FormattingEnabled = true;
|
||||
listBoxImages.ItemHeight = 20;
|
||||
listBoxImages.Location = new Point(330, 162);
|
||||
listBoxImages.Name = "listBoxImages";
|
||||
listBoxImages.Size = new Size(184, 64);
|
||||
listBoxImages.TabIndex = 6;
|
||||
//
|
||||
// chooseImage
|
||||
//
|
||||
chooseImage.Location = new Point(331, 232);
|
||||
chooseImage.Name = "chooseImage";
|
||||
chooseImage.Size = new Size(183, 27);
|
||||
chooseImage.TabIndex = 7;
|
||||
chooseImage.Text = "Добавить картинку";
|
||||
chooseImage.UseVisualStyleBackColor = true;
|
||||
chooseImage.Click += chooseImage_Click;
|
||||
//
|
||||
// createPdfImages
|
||||
//
|
||||
createPdfImages.Location = new Point(330, 265);
|
||||
createPdfImages.Name = "createPdfImages";
|
||||
createPdfImages.Size = new Size(184, 29);
|
||||
createPdfImages.TabIndex = 8;
|
||||
createPdfImages.Text = "Создать пдф";
|
||||
createPdfImages.UseVisualStyleBackColor = true;
|
||||
createPdfImages.Click += createPdfImages_Click;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1120, 450);
|
||||
ClientSize = new Size(1120, 474);
|
||||
Controls.Add(createPdfImages);
|
||||
Controls.Add(chooseImage);
|
||||
Controls.Add(listBoxImages);
|
||||
Controls.Add(richTextBoxText);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(hierarchicalTreeView);
|
||||
@ -102,5 +138,9 @@
|
||||
private MyUserControls.Components.testComponent testComponent1;
|
||||
private Button buttonSave;
|
||||
private RichTextBox richTextBoxText;
|
||||
private MyUserControls.Components.PdfImage.PdfImage pdfImage;
|
||||
private ListBox listBoxImages;
|
||||
private Button chooseImage;
|
||||
private Button createPdfImages;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
using MyUserControls;
|
||||
using MyUserControls.Components.office_package.Implements;
|
||||
using MyUserControls.Components.PdfImage;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private List<byte[]> selectedImages = new List<byte[]>();
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -70,5 +74,62 @@ namespace WinFormsApp1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void chooseImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
using OpenFileDialog openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Multiselect = true,
|
||||
Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp"
|
||||
};
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
selectedImages.Clear();
|
||||
listBoxImages.Items.Clear();
|
||||
foreach (string filePath in openFileDialog.FileNames)
|
||||
{
|
||||
selectedImages.Add(File.ReadAllBytes(filePath));
|
||||
listBoxImages.Items.Add(Path.GetFileName(filePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void createPdfImages_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (selectedImages.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Íåòó êàðòèíîê", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
string currentDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
string filePath = Path.Combine(currentDirectory, @"..\..\..\Documents\PdfWithImage.pdf");
|
||||
|
||||
var info = new PdfImageInfo
|
||||
{
|
||||
FileName = filePath,
|
||||
Title = "title",
|
||||
Images = selectedImages
|
||||
};
|
||||
pdfImage.CreatePdf(info);
|
||||
MessageBox.Show("Ïäô ñîçäàí óñïåøíî", "ôàéë ñîçäàí", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -120,4 +120,7 @@
|
||||
<metadata name="testComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="pdfImage.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>183, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -12,4 +12,8 @@
|
||||
<ProjectReference Include="..\CheckedListBoxLibrary\MyUserControls.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Documents\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user