Selaa lähdekoodia

Bugfixed / portrait and landscape isolated widget & scale logo for margin top height

Feature
Safet Purkovic 4 vuotta sitten
vanhempi
commit
90d710b9b8

+ 29
- 3
BlackRock.Reporting.API/Controllers/PDFGeneratorController.cs Näytä tiedosto

@@ -52,10 +52,21 @@ namespace BlackRock.Reporting.API.Controllers

// document.Close();

ModifyPDF(path);
var pixels = CalculatePixels(options.MarginOptions.Top);
ModifyPDF(path, pixels);
FileStream stream = new FileStream(path, FileMode.Open);
return File(stream, "application/pdf", fileName);
}

private double CalculatePixels(string v)
{
float Result;
if(float.TryParse(v,out Result))
return 2.83*Result;
var num = float.Parse(v.Split(' ')[0]);
return 2.83*num;
}

[HttpGet("isolate/{url}")]
public async Task<IActionResult> GetIsolated([FromQuery] OptionsForPdf pdfOptions, string url = "http://localhost:3000/#/dashboard")
{
@@ -71,6 +82,11 @@ namespace BlackRock.Reporting.API.Controllers
var options = mapper.Map<OptionsForPdf, PdfOptions>(pdfOptions);

await generator.Isolate(result, path, options);

var pixels = CalculatePixels(options.MarginOptions.Top);
ModifyPDF(path, pixels);


FileStream stream = new FileStream(path, FileMode.Open);
return File(stream, "application/pdf", fileName);
}
@@ -150,7 +166,7 @@ namespace BlackRock.Reporting.API.Controllers
reader.Close();
}

private void ModifyPDF(string path)
private void ModifyPDF(string path,double marginTop)
{
var filePath = path;
byte[] bytes = System.IO.File.ReadAllBytes(filePath);
@@ -171,7 +187,17 @@ namespace BlackRock.Reporting.API.Controllers
};
pdfData.SetGState(graphicsState);
Image image = Image.GetInstance(Path.Combine(host.ContentRootPath, "logo.png"));
image.SetAbsolutePosition(pageRectangle.Width/2-image.Width/2,pageRectangle.Height-image.Height-5);
var OriginalWidth = image.Width;
var OriginialHeight = image.Height;
var scale = OriginalWidth/OriginialHeight;
OriginialHeight = (float)marginTop-5;
OriginalWidth = OriginialHeight*scale;
// image.ScaleToFit(OriginalWidth, OriginialHeight);
//image.Width = OriginalWidth;
image.ScaleAbsoluteWidth(OriginalWidth);
image.ScaleAbsoluteHeight(OriginialHeight);
// image.SetAbsolutePosition(pageRectangle.Width/2-OriginalWidth/2,pageRectangle.Height-OriginialHeight-5);
image.SetAbsolutePosition(5,pageRectangle.Height-OriginialHeight-5);
pdfData.AddImage(image);
// pdfData.BeginText();

+ 1
- 1
BlackRock.Reporting.API/Core/Models/OptionsForPdf.cs Näytä tiedosto

@@ -74,7 +74,7 @@ namespace BlackRock.Reporting.API.Core.Models
/// Paper margins, defaults to none
/// </summary>
//public MarginOptions MarginOptions { get; set; } = new MarginOptions(){Top="3.0 mm",Right = "3.0 mm",Left="3.0 mm",Bottom="12.7 mm"};
public string MarginTop {get;set;} ="3.0 mm";
public string MarginTop {get;set;} ="6.0 mm";
public string MarginRight {get;set;} = "3.0 mm";
public string MarginLeft {get;set;} ="3.0 mm";
public string MarginBottom {get;set;} ="12.7 mm";

+ 5
- 2
BlackRock.Reporting.API/Persistence/PdfGenerator.cs Näytä tiedosto

@@ -29,7 +29,7 @@ namespace BlackRock.Reporting.API.Persistence
{
await page.GoToAsync(url, WaitUntilNavigation.DOMContentLoaded);

// await modifyPage(page,param);
var allResultsSelector = ".chartjs-render-monitor";
await page.WaitForSelectorAsync(allResultsSelector);
await EvaluateScript(page, "dist/main.js");
@@ -59,10 +59,13 @@ namespace BlackRock.Reporting.API.Persistence
using (var page = await browser.NewPageAsync())
{
await page.GoToAsync(url, WaitUntilNavigation.DOMContentLoaded);

var allResultsSelector = ".chartjs-render-monitor";
await page.WaitForSelectorAsync(allResultsSelector);
await page.EvaluateFunctionAsync("() => document.getElementById('sel').selectedIndex = "+((options.Landscape)?1:0));
await page.ClickAsync("button.dugme");
await EvaluateScript(page, "dist/main.js");
await EvaluateScript(page, "dist/main2.js");
await page.PdfAsync(path, options

+ 1
- 1
BlackRock.Reporting.API/dist/main.js
File diff suppressed because it is too large
Näytä tiedosto


Loading…
Peruuta
Tallenna