Skip to content

Commit

Permalink
Merge pull request #147 from KorzhCom/dev
Browse files Browse the repository at this point in the history
Version 1.4.9
  • Loading branch information
korzh authored Jul 4, 2022
2 parents 060cf43 + 42f98ac commit 1bc840f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 28 deletions.
2 changes: 2 additions & 0 deletions easydata.js/packs/ui/src/grid/easy_grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ export class EasyGrid {

if (this.rowsOnPagePromise) {
this.rowsOnPagePromise.then(count => {
this.footerDiv.innerHTML = '';

this.footerPaginateDiv = this.renderPageNavigator();
this.footerDiv.appendChild(this.footerPaginateDiv);
const pageInfoBlock = this.renderPageInfoBlock(count);
Expand Down
8 changes: 4 additions & 4 deletions easydata.js/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.4.8",
"baseVersion": "1.4.8",
"assetVersion": "01_04_08",
"tag": "latest"
"version": "1.4.9",
"baseVersion": "1.4.9",
"assetVersion": "01_04_09",
"tag": "beta"
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Task WriteRowAsync(EasyDataRow row, bool isExtraRow = false,
}

cell.DataType = excelDataType;
cell.Value = value;
cell.Value = excelDataType == XLDataType.Text ? "'" + value : value;

// setting the cell's format
var cellFormat = GetCellFormat(excelDataType, column.DataType, mappedSettings, dfmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public PdfDataExportSettings() : base()
/// Initializes a new instance of the<see cref="PdfDataExportSettings"/> class.
/// </summary>
public PdfDataExportSettings(CultureInfo culture) : base(culture)
{

{
}

/// <summary>
Expand All @@ -40,5 +39,9 @@ public PdfDataExportSettings(CultureInfo culture) : base(culture)
/// </summary>
public PageFormat PageFormat { get; set; } = PageFormat.A4;

/// <summary>
/// Page margins (in milimiters)
/// </summary>
public (short Left, short Top, short Right, short Bottom) Margins { get; set; } = (25, 25, 25, 25);
}
}
80 changes: 62 additions & 18 deletions easydata.net/src/EasyData.Exporters.PdfSharp/Pdf/PdfDataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,32 @@ public Task ExportAsync(IEasyDataResultSet data, Stream stream, CancellationToke
/// <returns>Task.</returns>
public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExportSettings settings, CancellationToken ct = default)
{
var mappedSettings = MapSettings(settings);
var pdfSettings = MapSettings(settings);

var document = new Document();
document.Info.Title = mappedSettings.Title;
document.DefaultPageSetup.Orientation = mappedSettings.Orientation;
document.DefaultPageSetup.PageFormat = mappedSettings.PageFormat;
document.Info.Title = pdfSettings.Title;
document.DefaultPageSetup.Orientation = pdfSettings.Orientation;
document.DefaultPageSetup.PageFormat = pdfSettings.PageFormat;

ApplyStyles(document, mappedSettings);

ApplyStyles(document, pdfSettings);

var section = document.AddSection();
section.PageSetup.PageFormat = pdfSettings.PageFormat;

if (settings.ShowDatasetInfo) {
// TODO: render paragrap with info here
if (!string.IsNullOrWhiteSpace(mappedSettings.Title)) {
if (!string.IsNullOrWhiteSpace(pdfSettings.Title)) {
var p = section.AddParagraph();
p.Format.Alignment = ParagraphAlignment.Center;
p.Format.Font.Bold = true;
p.AddText(mappedSettings.Title);
p.AddText(pdfSettings.Title);
}

if (!string.IsNullOrWhiteSpace(mappedSettings.Description)) {
if (!string.IsNullOrWhiteSpace(pdfSettings.Description)) {
var p = section.AddParagraph();
p.Format.Alignment = ParagraphAlignment.Left;
p.AddText(mappedSettings.Description);
p.AddText(pdfSettings.Description);
}
}

Expand All @@ -128,16 +130,26 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor
// predefined formatters
var predefinedFormatters = GetPredefinedFormatters(data.Cols, settings);

// filling columns

//ignored columns
// getting ignored columns
var ignoredCols = GetIgnoredColumns(data, settings);

var pageSizes = GetPageSizes(pdfSettings.PageFormat);
var pageWidth = pdfSettings.Orientation == Orientation.Landscape
? pageSizes.Height
: pageSizes.Width;

//calculating the width of one column
var colCount = data.Cols.Count - ignoredCols.Count;
double pageContentWidth = pageWidth - pdfSettings.Margins.Left - pdfSettings.Margins.Right;
var colWidth = pageContentWidth / colCount;

// filling columns
int colsCount = 0;
for (int i = 0; i < data.Cols.Count; i++) {
if (ignoredCols.Contains(i))
continue;

var column = table.AddColumn(Unit.FromCentimeter(3));
var column = table.AddColumn(Unit.FromMillimeter(colWidth));
column.Format.Alignment = ParagraphAlignment.Center;
colsCount++;
}
Expand Down Expand Up @@ -192,7 +204,7 @@ Task WriteRowAsync(EasyDataRow row, bool isExtra = false,
value = string.Format(provider, dfmt, row[i]);
}
else {
value = Utils.GetFormattedValue(row[i], type, mappedSettings, dfmt);
value = Utils.GetFormattedValue(row[i], type, pdfSettings, dfmt);
}

if (!string.IsNullOrEmpty(value) && isExtra && !string.IsNullOrEmpty(gfct)) {
Expand All @@ -218,8 +230,8 @@ Task WriteRowAsync(EasyDataRow row, bool isExtra = false,

var currentRowNum = 0;
foreach (var row in rows) {
if (mappedSettings.BeforeRowInsert != null)
await mappedSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct);
if (pdfSettings.BeforeRowInsert != null)
await pdfSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct);

if (settings.RowLimit > 0 && currentRowNum >= settings.RowLimit)
continue;
Expand All @@ -229,8 +241,8 @@ Task WriteRowAsync(EasyDataRow row, bool isExtra = false,
currentRowNum++;
}

if (mappedSettings.BeforeRowInsert != null) {
await mappedSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct);
if (pdfSettings.BeforeRowInsert != null) {
await pdfSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct);
}

// rendering pdf
Expand All @@ -246,6 +258,38 @@ Task WriteRowAsync(EasyDataRow row, bool isExtra = false,
}
}

private (int Width, int Height) GetPageSizes(PageFormat pageFormat)
{
switch (pageFormat) {
case PageFormat.A0:
return (841, 1189);
case PageFormat.A1:
return (594, 841);
case PageFormat.A2:
return (420, 594);
case PageFormat.A3:
return (297, 420);
case PageFormat.A4:
return (210, 297);
case PageFormat.A5:
return (148, 210);
case PageFormat.A6:
return (105, 148);
case PageFormat.B5:
return (176, 250);
case PageFormat.Letter:
return (216, 279);
case PageFormat.Legal:
return (216, 356);
case PageFormat.Ledger:
return (279, 432);
case PageFormat.P11x17:
return (432, 279);
default:
return (210, 297); //return A4 sizes by default
}
}

private Dictionary<string, IFormatProvider> GetPredefinedFormatters(IReadOnlyList<EasyDataCol> cols, IDataExportSettings settings)
{
var result = new Dictionary<string, IFormatProvider>();
Expand Down
6 changes: 3 additions & 3 deletions easydata.net/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"assemblyVersion": "1.4.8.1",
"packageVersion": "1.4.8",
"assetVersion": "01_04_08"
"assemblyVersion": "1.4.9.3",
"packageVersion": "1.4.9",
"assetVersion": "01_04_09"
}

0 comments on commit 1bc840f

Please sign in to comment.