в слитых ячейках могут быть не те значения

This commit is contained in:
GokaPek 2024-10-01 10:59:06 +04:00
parent 4e81c3f101
commit f6990cd5a6
2 changed files with 66 additions and 16 deletions

View File

@ -70,6 +70,7 @@ namespace ExexForm2
private void btnCreatePdfTable_Click(object sender, EventArgs e)
{
string selectDirTable = "";
string fileName = "";
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
{
@ -79,27 +80,41 @@ namespace ExexForm2
}
}
string fileName = Path.Combine(selectDirTable, "output2.pdf");
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
saveFileDialog.DefaultExt = "pdf";
saveFileDialog.InitialDirectory = selectDirTable;
saveFileDialog.FileName = "output2.pdf";
var generator = new PdfColGroupTable();
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
fileName = saveFileDialog.FileName;
}
}
var data1 = new List<Person>
if (!string.IsNullOrEmpty(fileName))
{
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 commonHeaders = new List<string> { "Name", "", "" };
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)>
var headers = new List<string> { "First Name", "Last Name", "Age" };
var commonHeaders = new List<string> { "Name", "", "" };
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, 1, 0, 0), // 0 è 1 ÿ÷åéêè ïî âåðòèêàëè ïåðâîé êîëîíêè
(2, 2, 0, 1)
};
};
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, commonHeaders, propertyNames, data1);
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, commonHeaders, propertyNames, data1);
}
}
@ -109,6 +124,7 @@ namespace ExexForm2
private void btnCreatePdfCircl_Click(object sender, EventArgs e)
{
string selectDir = "";
string fileName = "";
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
{
@ -118,11 +134,24 @@ namespace ExexForm2
}
}
string fileName = Path.Combine(selectDir, "output3.pdf");
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
saveFileDialog.DefaultExt = "pdf";
saveFileDialog.InitialDirectory = selectDir;
saveFileDialog.FileName = "output3.pdf";
var pdfCirclDiagr = new PdfCirclDiagr();
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
fileName = saveFileDialog.FileName;
}
}
List<ChartData> chartData = new List<ChartData>
if (!string.IsNullOrEmpty(fileName))
{
var pdfCirclDiagr = new PdfCirclDiagr();
List<ChartData> chartData = new List<ChartData>
{
new ChartData { SeriesName = "Series 1", Value = 10 },
new ChartData { SeriesName = "Series 2", Value = 20 },
@ -130,7 +159,8 @@ namespace ExexForm2
new ChartData { SeriesName = "Series 4", Value = 40 }
};
pdfCirclDiagr.GeneratePdf(fileName, "Document Title", "Chart Title", LegendPosition.Right, chartData);
pdfCirclDiagr.GeneratePdf(fileName, "Document Title", "Chart Title", LegendPosition.Right, chartData);
}
}
}
}

View File

@ -32,14 +32,34 @@ namespace Library14Petrushin
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)
// Добавляем изображение на первую страницу
if (images.Count > 0)
{
using (XImage img = XImage.FromFile(images[0].ImagePath))
{
double imageWidth = img.PixelWidth * 72 / img.HorizontalResolution;
double imageHeight = img.PixelHeight * 72 / img.VerticalResolution;
double scale = Math.Min(firstPage.Width / imageWidth, (firstPage.Height - 50) / imageHeight); // Учитываем высоту заголовка
double imageX = (firstPage.Width - imageWidth * scale) / 2; // Центрируем изображение по горизонтали
double imageY = 50; // Начинаем рисовать изображение под заголовком
gfxFirstPage.DrawImage(img, imageX, imageY, imageWidth * scale, imageHeight * scale);
}
}
// Добавляем остальные изображения на новые страницы
for (int i = 1; i < images.Count; i++)
{
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
using (XImage img = XImage.FromFile(imageData.ImagePath))
using (XImage img = XImage.FromFile(images[i].ImagePath))
{
double imageWidth = img.PixelWidth * 72 / img.HorizontalResolution;
double imageHeight = img.PixelHeight * 72 / img.VerticalResolution;