ну сделал один компонент

This commit is contained in:
Kirill 2024-11-17 17:05:03 +04:00
parent a94ad17abc
commit c281e4e07b
27 changed files with 811 additions and 7 deletions

0
1.txt Normal file
View File

View 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
}
}

View 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);
}
}
}

View 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("Все поля должны быть заполнены.");
}
}
}
}

View 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
}
}

View 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();
}
}
}

View 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
{
}
}

View File

@ -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
}
}

View File

@ -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,
}
}

View File

@ -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
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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();
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}
}
}

View File

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

Binary file not shown.

View File

@ -35,11 +35,15 @@
testComponent1 = new MyUserControls.Components.testComponent(components); testComponent1 = new MyUserControls.Components.testComponent(components);
buttonSave = new Button(); buttonSave = new Button();
richTextBoxText = new RichTextBox(); richTextBoxText = new RichTextBox();
pdfImage = new MyUserControls.Components.PdfImage.PdfImage(components);
listBoxImages = new ListBox();
chooseImage = new Button();
createPdfImages = new Button();
SuspendLayout(); SuspendLayout();
// //
// smartCheckedListBox1 // smartCheckedListBox1
// //
smartCheckedListBox1.Location = new Point(37, 12); smartCheckedListBox1.Location = new Point(12, 12);
smartCheckedListBox1.Name = "smartCheckedListBox1"; smartCheckedListBox1.Name = "smartCheckedListBox1";
smartCheckedListBox1.SelectedValue = ""; smartCheckedListBox1.SelectedValue = "";
smartCheckedListBox1.Size = new Size(241, 182); smartCheckedListBox1.Size = new Size(241, 182);
@ -47,23 +51,23 @@
// //
// smartTextBox1 // smartTextBox1
// //
smartTextBox1.Location = new Point(12, 318); smartTextBox1.Location = new Point(0, 329);
smartTextBox1.MaxLength = 100; smartTextBox1.MaxLength = 100;
smartTextBox1.MinLength = 0; smartTextBox1.MinLength = 0;
smartTextBox1.Name = "smartTextBox1"; smartTextBox1.Name = "smartTextBox1";
smartTextBox1.Size = new Size(312, 98); smartTextBox1.Size = new Size(295, 98);
smartTextBox1.TabIndex = 2; smartTextBox1.TabIndex = 2;
// //
// hierarchicalTreeView // hierarchicalTreeView
// //
hierarchicalTreeView.Location = new Point(12, 163); hierarchicalTreeView.Location = new Point(0, 162);
hierarchicalTreeView.Name = "hierarchicalTreeView"; hierarchicalTreeView.Name = "hierarchicalTreeView";
hierarchicalTreeView.Size = new Size(266, 174); hierarchicalTreeView.Size = new Size(266, 174);
hierarchicalTreeView.TabIndex = 3; hierarchicalTreeView.TabIndex = 3;
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(337, 162); buttonSave.Location = new Point(337, 111);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(168, 32); buttonSave.Size = new Size(168, 32);
buttonSave.TabIndex = 4; buttonSave.TabIndex = 4;
@ -75,15 +79,47 @@
// //
richTextBoxText.Location = new Point(337, 26); richTextBoxText.Location = new Point(337, 26);
richTextBoxText.Name = "richTextBoxText"; richTextBoxText.Name = "richTextBoxText";
richTextBoxText.Size = new Size(168, 130); richTextBoxText.Size = new Size(168, 70);
richTextBoxText.TabIndex = 5; richTextBoxText.TabIndex = 5;
richTextBoxText.Text = ""; 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 // Form1
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; 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(richTextBoxText);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(hierarchicalTreeView); Controls.Add(hierarchicalTreeView);
@ -102,5 +138,9 @@
private MyUserControls.Components.testComponent testComponent1; private MyUserControls.Components.testComponent testComponent1;
private Button buttonSave; private Button buttonSave;
private RichTextBox richTextBoxText; private RichTextBox richTextBoxText;
private MyUserControls.Components.PdfImage.PdfImage pdfImage;
private ListBox listBoxImages;
private Button chooseImage;
private Button createPdfImages;
} }
} }

View File

@ -1,10 +1,14 @@
using MyUserControls; using MyUserControls;
using MyUserControls.Components.office_package.Implements;
using MyUserControls.Components.PdfImage;
using System.ComponentModel; using System.ComponentModel;
namespace WinFormsApp1 namespace WinFormsApp1
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
private List<byte[]> selectedImages = new List<byte[]>();
public Form1() public Form1()
{ {
InitializeComponent(); 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);
}
}
} }
} }

View File

@ -120,4 +120,7 @@
<metadata name="testComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="testComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </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> </root>

View File

@ -12,4 +12,8 @@
<ProjectReference Include="..\CheckedListBoxLibrary\MyUserControls.csproj" /> <ProjectReference Include="..\CheckedListBoxLibrary\MyUserControls.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Documents\" />
</ItemGroup>
</Project> </Project>