Compare commits
2 Commits
a24dbe6e5b
...
31b37da456
Author | SHA1 | Date | |
---|---|---|---|
|
31b37da456 | ||
|
a6a440e181 |
15
ExexForm2/ExexForm2.csproj
Normal file
15
ExexForm2/ExexForm2.csproj
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Library14Petrushin\Library14Petrushin.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
137
ExexForm2/Form1.Designer.cs
generated
Normal file
137
ExexForm2/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
namespace ExexForm2
|
||||||
|
{
|
||||||
|
partial class Form1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
components = new System.ComponentModel.Container();
|
||||||
|
pdfImg1 = new Library14Petrushin.PdfImg(components);
|
||||||
|
btnSelectImages = new Button();
|
||||||
|
btnSelectDirectory = new Button();
|
||||||
|
btnCreatePdf = new Button();
|
||||||
|
txtDocumentTitle = new TextBox();
|
||||||
|
lstImages = new ListBox();
|
||||||
|
lblDirectory = new Label();
|
||||||
|
btnCrTb = new Button();
|
||||||
|
pdfColGroupTable1 = new Library14Petrushin.PdfColGroupTable();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// btnSelectImages
|
||||||
|
//
|
||||||
|
btnSelectImages.Location = new Point(24, 28);
|
||||||
|
btnSelectImages.Name = "btnSelectImages";
|
||||||
|
btnSelectImages.Size = new Size(116, 50);
|
||||||
|
btnSelectImages.TabIndex = 0;
|
||||||
|
btnSelectImages.Text = "выбор изображения";
|
||||||
|
btnSelectImages.UseVisualStyleBackColor = true;
|
||||||
|
btnSelectImages.Click += btnSelectImages_Click;
|
||||||
|
//
|
||||||
|
// btnSelectDirectory
|
||||||
|
//
|
||||||
|
btnSelectDirectory.Location = new Point(24, 89);
|
||||||
|
btnSelectDirectory.Name = "btnSelectDirectory";
|
||||||
|
btnSelectDirectory.Size = new Size(116, 49);
|
||||||
|
btnSelectDirectory.TabIndex = 1;
|
||||||
|
btnSelectDirectory.Text = "выбор директории";
|
||||||
|
btnSelectDirectory.UseVisualStyleBackColor = true;
|
||||||
|
btnSelectDirectory.Click += btnSelectDirectory_Click;
|
||||||
|
//
|
||||||
|
// btnCreatePdf
|
||||||
|
//
|
||||||
|
btnCreatePdf.Location = new Point(24, 158);
|
||||||
|
btnCreatePdf.Name = "btnCreatePdf";
|
||||||
|
btnCreatePdf.Size = new Size(101, 48);
|
||||||
|
btnCreatePdf.TabIndex = 2;
|
||||||
|
btnCreatePdf.Text = "Создать";
|
||||||
|
btnCreatePdf.UseVisualStyleBackColor = true;
|
||||||
|
btnCreatePdf.Click += btnCreatePdf_Click;
|
||||||
|
//
|
||||||
|
// txtDocumentTitle
|
||||||
|
//
|
||||||
|
txtDocumentTitle.Location = new Point(24, 224);
|
||||||
|
txtDocumentTitle.Name = "txtDocumentTitle";
|
||||||
|
txtDocumentTitle.Size = new Size(101, 27);
|
||||||
|
txtDocumentTitle.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// lstImages
|
||||||
|
//
|
||||||
|
lstImages.FormattingEnabled = true;
|
||||||
|
lstImages.Location = new Point(146, 28);
|
||||||
|
lstImages.Name = "lstImages";
|
||||||
|
lstImages.Size = new Size(179, 404);
|
||||||
|
lstImages.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// lblDirectory
|
||||||
|
//
|
||||||
|
lblDirectory.AutoSize = true;
|
||||||
|
lblDirectory.Location = new Point(24, 280);
|
||||||
|
lblDirectory.Name = "lblDirectory";
|
||||||
|
lblDirectory.Size = new Size(50, 20);
|
||||||
|
lblDirectory.TabIndex = 5;
|
||||||
|
lblDirectory.Text = "label1";
|
||||||
|
//
|
||||||
|
// btnCrTb
|
||||||
|
//
|
||||||
|
btnCrTb.Location = new Point(349, 28);
|
||||||
|
btnCrTb.Name = "btnCrTb";
|
||||||
|
btnCrTb.Size = new Size(142, 29);
|
||||||
|
btnCrTb.TabIndex = 6;
|
||||||
|
btnCrTb.Text = "Создать таблицу";
|
||||||
|
btnCrTb.UseVisualStyleBackColor = true;
|
||||||
|
btnCrTb.Click += btnCreatePdfTable_Click;
|
||||||
|
//
|
||||||
|
// Form1
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(btnCrTb);
|
||||||
|
Controls.Add(lblDirectory);
|
||||||
|
Controls.Add(lstImages);
|
||||||
|
Controls.Add(txtDocumentTitle);
|
||||||
|
Controls.Add(btnCreatePdf);
|
||||||
|
Controls.Add(btnSelectDirectory);
|
||||||
|
Controls.Add(btnSelectImages);
|
||||||
|
Name = "Form1";
|
||||||
|
Text = "Form1";
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Library14Petrushin.PdfImg pdfImg1;
|
||||||
|
private Button btnSelectImages;
|
||||||
|
private Button btnSelectDirectory;
|
||||||
|
private Button btnCreatePdf;
|
||||||
|
private TextBox txtDocumentTitle;
|
||||||
|
private ListBox lstImages;
|
||||||
|
private Label lblDirectory;
|
||||||
|
private Button btnCrTb;
|
||||||
|
private Library14Petrushin.PdfColGroupTable pdfColGroupTable1;
|
||||||
|
}
|
||||||
|
}
|
100
ExexForm2/Form1.cs
Normal file
100
ExexForm2/Form1.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
using Library14Petrushin;
|
||||||
|
|
||||||
|
namespace ExexForm2
|
||||||
|
{
|
||||||
|
public partial class Form1 : Form
|
||||||
|
{
|
||||||
|
private PdfImg pdfImg;
|
||||||
|
private List<ImageData> selectedImages;
|
||||||
|
private string selectedDirectory;
|
||||||
|
private PdfColGroupTable pdfTable;
|
||||||
|
|
||||||
|
public Form1()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
pdfImg = new PdfImg();
|
||||||
|
selectedImages = new List<ImageData>();
|
||||||
|
pdfTable = new PdfColGroupTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnSelectImages_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
using (OpenFileDialog openFileDialog = new OpenFileDialog())
|
||||||
|
{
|
||||||
|
openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif";
|
||||||
|
openFileDialog.Multiselect = true;
|
||||||
|
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
foreach (string fileName in openFileDialog.FileNames)
|
||||||
|
{
|
||||||
|
selectedImages.Add(new ImageData { ImagePath = fileName });
|
||||||
|
lstImages.Items.Add(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnSelectDirectory_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||||||
|
{
|
||||||
|
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
selectedDirectory = folderBrowserDialog.SelectedPath;
|
||||||
|
lblDirectory.Text = "Selected Directory: " + selectedDirectory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnCreatePdf_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(txtDocumentTitle.Text) || selectedImages.Count == 0 || string.IsNullOrEmpty(selectedDirectory))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Please select images, directory, and enter a document title.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string fileName = Path.Combine(selectedDirectory, "output.pdf");
|
||||||
|
pdfImg.CreatePdfDocument(fileName, txtDocumentTitle.Text, selectedImages);
|
||||||
|
MessageBox.Show("PDF document created successfully!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
private void btnCreatePdfTable_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string selectDirTable = "";
|
||||||
|
|
||||||
|
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||||||
|
{
|
||||||
|
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
selectDirTable = folderBrowserDialog.SelectedPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string fileName = Path.Combine(selectDirTable, "output.pdf");
|
||||||
|
|
||||||
|
var generator = new PdfColGroupTable();
|
||||||
|
|
||||||
|
var data1 = new List<Person>
|
||||||
|
{
|
||||||
|
new Person { FirstName = "John", LastName = "Doe", Age = 30 },
|
||||||
|
new Person { FirstName = "Jane", LastName = "Smith", Age = 25 }
|
||||||
|
};
|
||||||
|
|
||||||
|
var headers = new List<string> { "First Name", "Last Name", "Age" };
|
||||||
|
var propertyNames = new List<string> { "FirstName", "LastName", "Age" };
|
||||||
|
var rowHeights = new List<double> { 20, 20 };
|
||||||
|
var mergeCells = new List<(int startRow, int endRow, int startColumn, int endColumn)>
|
||||||
|
{
|
||||||
|
(0, 0, 0, 1) // Îáúåäèíåíèå ïåðâûõ äâóõ ñòîëáöîâ â ïåðâîé ñòðîêå
|
||||||
|
};
|
||||||
|
|
||||||
|
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, propertyNames, data1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
126
ExexForm2/Form1.resx
Normal file
126
ExexForm2/Form1.resx
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="pdfImg1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="pdfColGroupTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>130, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
17
ExexForm2/Program.cs
Normal file
17
ExexForm2/Program.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace ExexForm2
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.Run(new Form1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Library14Petrushin/Classes/Person.cs
Normal file
9
Library14Petrushin/Classes/Person.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace Library14Petrushin
|
||||||
|
{
|
||||||
|
public class Person
|
||||||
|
{
|
||||||
|
public string FirstName { get; set; }
|
||||||
|
public string LastName { get; set; }
|
||||||
|
public int Age { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -7,4 +7,8 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="PDFsharp" Version="6.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.10.35013.160
|
VisualStudioVersion = 17.10.35013.160
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library14Petrushin", "Library14Petrushin.csproj", "{64A09BF4-7D97-49DE-8AB8-E9C23B75A62D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library14Petrushin", "Library14Petrushin.csproj", "{64A09BF4-7D97-49DE-8AB8-E9C23B75A62D}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExecForm", "..\ExecForm\ExecForm.csproj", "{6C3A0E39-ED7B-41D8-9253-023B1D35C935}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExecForm1", "..\ExecForm\ExecForm1.csproj", "{6C3A0E39-ED7B-41D8-9253-023B1D35C935}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExexForm2", "..\ExexForm2\ExexForm2.csproj", "{80D961BA-24BC-4B3E-A578-BAA90C6EED01}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -21,6 +23,10 @@ Global
|
|||||||
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Release|Any CPU.Build.0 = Release|Any CPU
|
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
36
Library14Petrushin/PdfColGroupTable.Designer.cs
generated
Normal file
36
Library14Petrushin/PdfColGroupTable.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
namespace Library14Petrushin
|
||||||
|
{
|
||||||
|
partial class PdfColGroupTable
|
||||||
|
{
|
||||||
|
/// <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
|
||||||
|
}
|
||||||
|
}
|
101
Library14Petrushin/PdfColGroupTable.cs
Normal file
101
Library14Petrushin/PdfColGroupTable.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using PdfSharp.Drawing;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Library14Petrushin
|
||||||
|
{
|
||||||
|
public partial class PdfColGroupTable : Component
|
||||||
|
{
|
||||||
|
public void GeneratePdf<T>(
|
||||||
|
string fileName,
|
||||||
|
string documentTitle,
|
||||||
|
List<(int startRow, int endRow, int startColumn, int endColumn)> mergeCells,
|
||||||
|
List<double> rowHeights,
|
||||||
|
List<string> headers,
|
||||||
|
List<string> propertyNames,
|
||||||
|
List<T> data)
|
||||||
|
{
|
||||||
|
// Проверка на заполненность входных данных
|
||||||
|
if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(documentTitle) ||
|
||||||
|
mergeCells == null || rowHeights == null || headers == null ||
|
||||||
|
propertyNames == null || data == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Все входные данные должны быть заполнены.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка на соответствие количества заголовков и свойств
|
||||||
|
if (headers.Count != propertyNames.Count)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Количество заголовков должно совпадать с количеством свойств.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка на соответствие количества строк и высот строк
|
||||||
|
if (rowHeights.Count != data.Count)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Количество высот строк должно совпадать с количеством строк данных.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создание документа
|
||||||
|
PdfDocument document = new PdfDocument();
|
||||||
|
PdfPage page = document.AddPage();
|
||||||
|
XGraphics gfx = XGraphics.FromPdfPage(page);
|
||||||
|
XFont font = new XFont("Verdana", 10);
|
||||||
|
|
||||||
|
// Отрисовка заголовка документа
|
||||||
|
gfx.DrawString(documentTitle, new XFont("Verdana", 16, XFontStyleEx.Bold), XBrushes.Black, new XRect(0, 0, page.Width, 50), XStringFormats.Center);
|
||||||
|
|
||||||
|
// Отрисовка таблицы
|
||||||
|
double margin = 50; // Отступ от краев страницы
|
||||||
|
double x = margin;
|
||||||
|
double y = 70;
|
||||||
|
double rowHeight = 20; // Фиксированная высота строки
|
||||||
|
double columnWidth = (page.Width - 2 * margin) / (headers.Count + 1); // Ширина столбца
|
||||||
|
|
||||||
|
// Отрисовка шапки
|
||||||
|
for (int col = 0; col < headers.Count; col++)
|
||||||
|
{
|
||||||
|
gfx.DrawString(headers[col], font, XBrushes.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight), XStringFormats.CenterLeft);
|
||||||
|
gfx.DrawRectangle(XPens.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight)); // Добавляем рамку
|
||||||
|
}
|
||||||
|
|
||||||
|
x += columnWidth;
|
||||||
|
|
||||||
|
// Отрисовка данных
|
||||||
|
for (int row = 0; row < data.Count; row++)
|
||||||
|
{
|
||||||
|
var item = data[row];
|
||||||
|
for (int col = 0; col < propertyNames.Count; col++)
|
||||||
|
{
|
||||||
|
var property = item.GetType().GetProperty(propertyNames[col]);
|
||||||
|
if (property != null)
|
||||||
|
{
|
||||||
|
var value = property.GetValue(item)?.ToString() ?? string.Empty;
|
||||||
|
gfx.DrawString(value, font, XBrushes.Black, new XRect(x + col * columnWidth, y + row * rowHeight, columnWidth, rowHeight), XStringFormats.CenterLeft);
|
||||||
|
gfx.DrawRectangle(XPens.Black, new XRect(x + col * columnWidth, y + row * rowHeight, columnWidth, rowHeight)); // Добавляем рамку
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Объединение ячеек
|
||||||
|
foreach (var (startRow, endRow, startColumn, endColumn) in mergeCells)
|
||||||
|
{
|
||||||
|
double mergeX = margin + (startColumn * columnWidth);
|
||||||
|
double mergeWidth = (endColumn - startColumn + 1) * columnWidth;
|
||||||
|
double mergeY = 70 + (startRow * rowHeight);
|
||||||
|
double mergeHeight = (endRow - startRow + 1) * rowHeight;
|
||||||
|
|
||||||
|
gfx.DrawRectangle(XPens.Black, XBrushes.White, new XRect(mergeX, mergeY, mergeWidth, mergeHeight));
|
||||||
|
gfx.DrawString(headers[startRow], font, XBrushes.Black, new XRect(mergeX, mergeY, mergeWidth, mergeHeight), XStringFormats.Center);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Сохранение документа
|
||||||
|
document.Save(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
Library14Petrushin/PdfImg.Designer.cs
generated
Normal file
36
Library14Petrushin/PdfImg.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
namespace Library14Petrushin
|
||||||
|
{
|
||||||
|
partial class PdfImg
|
||||||
|
{
|
||||||
|
/// <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
|
||||||
|
}
|
||||||
|
}
|
70
Library14Petrushin/PdfImg.cs
Normal file
70
Library14Petrushin/PdfImg.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.IO;
|
||||||
|
using PdfSharp.Drawing;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
|
|
||||||
|
namespace Library14Petrushin
|
||||||
|
{
|
||||||
|
public partial class PdfImg : Component
|
||||||
|
{
|
||||||
|
public PdfImg()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfImg(IContainer container)
|
||||||
|
{
|
||||||
|
container.Add(this);
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreatePdfDocument(string fileName, string documentTitle, List<ImageData> images)
|
||||||
|
{
|
||||||
|
// Проверка на заполненность входных данных
|
||||||
|
if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(documentTitle) || images == null || images.Count == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Все входные данные должны быть заполнены.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создание PDF-документа
|
||||||
|
PdfDocument document = new PdfDocument();
|
||||||
|
|
||||||
|
// Добавление заголовка документа на первую страницу
|
||||||
|
PdfPage firstPage = document.AddPage();
|
||||||
|
XGraphics gfxFirstPage = XGraphics.FromPdfPage(firstPage);
|
||||||
|
XFont font = new XFont("Arial", 20, XFontStyleEx.BoldItalic);
|
||||||
|
gfxFirstPage.DrawString(documentTitle, font, XBrushes.Black, new XRect(0, 0, firstPage.Width, 50), XStringFormats.Center);
|
||||||
|
|
||||||
|
// Добавление изображений в документ
|
||||||
|
foreach (var imageData in images)
|
||||||
|
{
|
||||||
|
PdfPage page = document.AddPage();
|
||||||
|
XGraphics gfx = XGraphics.FromPdfPage(page);
|
||||||
|
|
||||||
|
using (XImage img = XImage.FromFile(imageData.ImagePath))
|
||||||
|
{
|
||||||
|
// Определяем размеры изображения
|
||||||
|
double imageWidth = img.PixelWidth * 72 / img.HorizontalResolution;
|
||||||
|
double imageHeight = img.PixelHeight * 72 / img.VerticalResolution;
|
||||||
|
|
||||||
|
// Вычисляем масштаб, чтобы изображение поместилось на странице
|
||||||
|
double scale = Math.Min(page.Width / imageWidth, page.Height / imageHeight);
|
||||||
|
|
||||||
|
// Рисуем изображение на странице
|
||||||
|
gfx.DrawImage(img, 0, 0, imageWidth * scale, imageHeight * scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Сохранение документа
|
||||||
|
document.Save(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Класс для хранения данных об изображении
|
||||||
|
public class ImageData
|
||||||
|
{
|
||||||
|
public string ImagePath { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user