Просмотр исходного кода

Added button for dispach

master
Safet Purkovic 4 лет назад
Родитель
Сommit
091e1cace2

+ 1
- 0
BlackRock.Reporting.API/Controllers/PDFGeneratorController.cs Просмотреть файл



namespace BlackRock.Reporting.API.Controllers namespace BlackRock.Reporting.API.Controllers
{ {

[Route("api/[controller]")] [Route("api/[controller]")]
public class PDFGeneratorController : Controller public class PDFGeneratorController : Controller
{ {

+ 13
- 10
BlackRock.Reporting.API/Core/Models/OptionsForPdf.cs Просмотреть файл

{ {
public Guid Id { get; set; } public Guid Id { get; set; }
} }
public enum PaperFormatType{
A4 = 0,
A3 = 1,
Letter = 2
}
public enum PaperFormatType
{
A4 = 0,
A3 = 1,
Letter = 2
}
public class OptionsForPdf public class OptionsForPdf
{ {
public string user { get; set; }
public bool IsLogged { get; set; }
/// <summary> /// <summary>
/// Scale of the webpage rendering. Defaults to <c>1</c>. Scale amount must be between 0.1 and 2. /// Scale of the webpage rendering. Defaults to <c>1</c>. Scale amount must be between 0.1 and 2.
/// </summary> /// </summary>
/// <summary> /// <summary>
/// Paper format. If set, takes priority over <see cref="Width"/> and <see cref="Height"/> /// Paper format. If set, takes priority over <see cref="Width"/> and <see cref="Height"/>
/// </summary> /// </summary>
public PaperFormatType PaperFormatType {get; set;} = PaperFormatType.A4; // Paper format from client side
public PaperFormatType PaperFormatType { get; set; } = PaperFormatType.A4; // Paper format from client side


/// <summary> /// <summary>
/// Paper width, accepts values labeled with units /// Paper width, accepts values labeled with units
/// Paper margins, defaults to none /// Paper margins, defaults to none
/// </summary> /// </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 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;} ="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";
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";


/// <summary> /// <summary>
/// Give any CSS <c>@page</c> size declared in the page priority over what is declared in <c>width</c> and <c>height</c> or <c>format</c> options. /// Give any CSS <c>@page</c> size declared in the page priority over what is declared in <c>width</c> and <c>height</c> or <c>format</c> options.

+ 17
- 10
BlackRock.Reporting.API/Persistence/PdfGenerator.cs Просмотреть файл

{ {
Headless = true Headless = true
}; };
using (var browser = await Puppeteer.LaunchAsync(opts))
using (var page = await browser.NewPageAsync())
try
{ {
await page.GoToAsync(url, WaitUntilNavigation.DOMContentLoaded);

using (var browser = await Puppeteer.LaunchAsync(opts))
using (var page = await browser.NewPageAsync())
{
await page.GoToAsync(url, WaitUntilNavigation.DOMContentLoaded);


var allResultsSelector = ".chartjs-render-monitor";
await page.WaitForSelectorAsync(allResultsSelector);
await EvaluateScript(page, "dist/main.js");


await page.PdfAsync(path, options);
var allResultsSelector = ".chartjs-render-monitor";
await page.WaitForSelectorAsync(allResultsSelector);
await EvaluateScript(page, "dist/main.js");
// await page.ClickAsync("button#btnLogin");
await page.PdfAsync(path, options);


var pixels = CalculatePixels(options.MarginOptions.Top);
ModifyPDF(path, pixels);
var pixels = CalculatePixels(options.MarginOptions.Top);
ModifyPDF(path, pixels);
}
}
catch (Exception ex)
{
var e = ex.Message;
} }
} }
public async Task Isolate(string url, string path, PdfOptions options) public async Task Isolate(string url, string path, PdfOptions options)

Загрузка…
Отмена
Сохранить