diff --git a/Components/SaveToPdf.cs b/Components/SaveToPdf.cs index 7ac3f44..7663bf4 100644 --- a/Components/SaveToPdf.cs +++ b/Components/SaveToPdf.cs @@ -2,6 +2,7 @@ using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.Rendering; using Components.SaveToPdfHelpers; +using System.Text; namespace Components { @@ -13,6 +14,7 @@ namespace Components public void CreateDoc(string title, string path, List tables) { _document = new Document(); + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); DefineStyles(_document); _section = _document.AddSection(); diff --git a/TestingForm/FormMain.Designer.cs b/TestingForm/FormMain.Designer.cs index 05ec2ff..c7d5542 100644 --- a/TestingForm/FormMain.Designer.cs +++ b/TestingForm/FormMain.Designer.cs @@ -28,18 +28,35 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); + userControlTableDocument1 = new Components.UserControlTableDocument(components); + button1 = new Button(); SuspendLayout(); // + // button1 + // + button1.Location = new Point(12, 12); + button1.Name = "button1"; + button1.Size = new Size(188, 65); + button1.TabIndex = 0; + button1.Text = "Сохранить первый компонент"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(button1); Name = "FormMain"; - Text = "cB"; + Text = "Testing form"; ResumeLayout(false); } #endregion + + private Components.UserControlTableDocument userControlTableDocument1; + private Button button1; } } diff --git a/TestingForm/FormMain.cs b/TestingForm/FormMain.cs index 80839c4..6310531 100644 --- a/TestingForm/FormMain.cs +++ b/TestingForm/FormMain.cs @@ -6,5 +6,43 @@ namespace TestingForm { InitializeComponent(); } + + private void button1_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "pdf|*.pdf", + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + + List tables = new List(); + string[][] table1 = new string[2][]; + table1[0] = new string[] { "test", "test 2" }; + table1[1] = new string[] { "test next", "test next 2" }; + + string[][] table2 = new string[3][]; + table2[0] = new string[] { "ttt", "ttt 2", "ttt 3" }; + table2[1] = new string[] { "ttt next", "ttt next 2" }; + table2[2] = new string[] { "next" }; + + tables.Add(table1); + tables.Add(table2); + + try + { + userControlTableDocument1.SaveToDocument( + "Çàãîëîâîê äîêóìåíòà", + dialog.FileName, + tables + ); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + MessageBox.Show("Óñïåøíî"); + } } } diff --git a/TestingForm/FormMain.resx b/TestingForm/FormMain.resx index af32865..c5b82f3 100644 --- a/TestingForm/FormMain.resx +++ b/TestingForm/FormMain.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file