|
|
|
@@ -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(); |
|
|
|
|