| @@ -39,5 +39,23 @@ namespace BlackRock.Reporting.API.Controllers | |||
| FileStream stream = new FileStream(path, FileMode.Open); | |||
| return File(stream, "application/pdf", fileName); | |||
| } | |||
| [HttpGet("isolate/{url}")] | |||
| public async Task<IActionResult> GetIsolated([FromQuery] OptionsForPdf pdfOptions,string url = "http://localhost:3000/#/dashboard") | |||
| { | |||
| if (string.IsNullOrEmpty(url)) | |||
| return BadRequest(); | |||
| var result = HttpUtility.UrlDecode(url); | |||
| // Temporary name of file which will be downloaded | |||
| var fileName = Guid.NewGuid().ToString() + ".pdf"; | |||
| // Path to wwwroot folder combined with name of pdf file | |||
| string path = Path.Combine(host.ContentRootPath, $"wwwroot/pdfs/{fileName}"); | |||
| var options = mapper.Map<OptionsForPdf,PdfOptions>(pdfOptions); | |||
| await generator.Isolate(result, path, options); | |||
| FileStream stream = new FileStream(path, FileMode.Open); | |||
| return File(stream, "application/pdf", fileName); | |||
| } | |||
| } | |||
| } | |||
| @@ -5,5 +5,6 @@ namespace BlackRock.Reporting.API.Core | |||
| public interface IGenerator | |||
| { | |||
| Task Generate(string url, string path,PdfOptions options); | |||
| Task Isolate(string url, string path,PdfOptions options); | |||
| } | |||
| } | |||
| @@ -37,6 +37,33 @@ namespace BlackRock.Reporting.API.Persistence | |||
| } | |||
| } | |||
| public async Task Isolate(string url, string path, PdfOptions options) | |||
| { | |||
| await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); | |||
| var opts = new LaunchOptions | |||
| { | |||
| Headless = true | |||
| }; | |||
| 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/main2.js"); | |||
| await page.PdfAsync(path,options | |||
| // new PdfOptions{ | |||
| // PrintBackground = true, | |||
| // Format = PuppeteerSharp.Media.PaperFormat.Letter | |||
| // } | |||
| ); | |||
| } | |||
| } | |||
| private async Task EvaluateScript(Page page, string fileName) | |||
| { | |||
| string path2 = Path.Combine(host.ContentRootPath, fileName); | |||
| @@ -17,23 +17,21 @@ namespace BlackRock.Reporting.API.Profiles | |||
| { | |||
| public PdfOptions Convert(OptionsForPdf source, PdfOptions destination, ResolutionContext context) | |||
| { | |||
| if (source == null) | |||
| { | |||
| return null; | |||
| } | |||
| destination = new PdfOptions() | |||
| { | |||
| DisplayHeaderFooter = source.DisplayHeaderFooter, | |||
| HeaderTemplate = source.HeaderTemplate, | |||
| Height = source.Height, | |||
| Landscape = source.Landscape, | |||
| OmitBackground = source.OmitBackground, | |||
| PageRanges = source.PageRanges, | |||
| PreferCSSPageSize = source.PreferCSSPageSize, | |||
| PrintBackground = source.PrintBackground, | |||
| Scale = source.Scale, | |||
| Width = source.Width | |||
| }; | |||
| if(source == null) return destination; | |||
| if(destination == null) | |||
| destination = new PdfOptions(); | |||
| destination.DisplayHeaderFooter = source.DisplayHeaderFooter; | |||
| destination.HeaderTemplate = source.HeaderTemplate; | |||
| destination.Height = source.Height; | |||
| destination.Landscape = source.Landscape; | |||
| destination.OmitBackground = source.OmitBackground; | |||
| destination.PageRanges = source.PageRanges; | |||
| destination.PreferCSSPageSize = source.PreferCSSPageSize; | |||
| destination.PrintBackground = source.PrintBackground; | |||
| destination.Scale = source.Scale; | |||
| destination.Width = source.Width; | |||
| destination.MarginOptions = new PuppeteerSharp.Media.MarginOptions() | |||
| { | |||
| Bottom = source.MarginBottom, | |||
| @@ -0,0 +1,6 @@ | |||
| const isolated = document.querySelector('[isolate="true"]'); | |||
| const root = document.getElementById('root'); | |||
| root.childNodes.forEach(element => { | |||
| element.remove() | |||
| }); | |||
| root.appendChild(isolated); | |||
| @@ -1,17 +1,17 @@ | |||
| { | |||
| "format": 1, | |||
| "restore": { | |||
| "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\BlackRock.Reporting.API\\BlackRock.Reporting.API.csproj": {} | |||
| "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\blackrock.reporting.api\\BlackRock.Reporting.API.csproj": {} | |||
| }, | |||
| "projects": { | |||
| "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\BlackRock.Reporting.API\\BlackRock.Reporting.API.csproj": { | |||
| "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\blackrock.reporting.api\\BlackRock.Reporting.API.csproj": { | |||
| "version": "1.0.0", | |||
| "restore": { | |||
| "projectUniqueName": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\BlackRock.Reporting.API\\BlackRock.Reporting.API.csproj", | |||
| "projectUniqueName": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\blackrock.reporting.api\\BlackRock.Reporting.API.csproj", | |||
| "projectName": "BlackRock.Reporting.API", | |||
| "projectPath": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\BlackRock.Reporting.API\\BlackRock.Reporting.API.csproj", | |||
| "projectPath": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\blackrock.reporting.api\\BlackRock.Reporting.API.csproj", | |||
| "packagesPath": "C:\\Users\\safet.purkovic\\.nuget\\packages\\", | |||
| "outputPath": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\BlackRock.Reporting.API\\obj\\", | |||
| "outputPath": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\blackrock.reporting.api\\obj\\", | |||
| "projectStyle": "PackageReference", | |||
| "configFilePaths": [ | |||
| "C:\\Users\\safet.purkovic\\AppData\\Roaming\\NuGet\\NuGet.Config", | |||
| @@ -1,8 +1,8 @@ | |||
| { | |||
| "version": 2, | |||
| "dgSpecHash": "CWZgWYM1eCSk38SuYkv3dxqETT/4ZhBGYJ0BC0Js2XjwANoY+dTh7urgBxbU/o5glmzspiqosf7ZSf+k+lOuyw==", | |||
| "dgSpecHash": "u5LCzMsSc98tqejgvIS7vh2sBsOKVmvwB91LkGNhpRK/OTJT4TBibJo14VN9KPzUL1djIsrbKAcg0IlFWE3yWg==", | |||
| "success": true, | |||
| "projectFilePath": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\BlackRock.Reporting.API\\BlackRock.Reporting.API.csproj", | |||
| "projectFilePath": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\blackrock.reporting.api\\BlackRock.Reporting.API.csproj", | |||
| "expectedPackageFiles": [ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\automapper\\10.1.1\\automapper.10.1.1.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\automapper.extensions.microsoft.dependencyinjection\\8.1.1\\automapper.extensions.microsoft.dependencyinjection.8.1.1.nupkg.sha512", | |||