Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PDF reports #347

Merged

Conversation

ZIMkaRU
Copy link
Member

@ZIMkaRU ZIMkaRU commented Feb 16, 2024

This PR adds support for PDF reports
This PR doesn't bring breaking changes for compatibility with the current UI implementation. Everything should work as earlier. And adds the migration step for using api methods of report file generation:

  • example
    // new method name
    getMultipleFile() {}
    
    // @deprecated method name
    getMultipleCsv (...args) { return this.getMultipleFile(...args) }

After several release iterations and UI migration, deprecated methods will be removed


Basic changes:

  • the minimum required refactoring in order to be able to add support for pdf to the current csv generation flow
  • for dev mode uses the local report-files folder instead of csv
  • uses https://github.com/bitfinexcom/bfx-ext-pdf-js Grenache service for pdf generation for the online part of the app
  • adds the main structure for extending logic to be able to generate PDF under Electronjs using the native api of Chromium
  • uses custom Inter fonts for PDF
  • adds the same test coverage for pdf report file generation as for csv implemented before

How PDF generation works

For PDF generation uses browser emulation with printing HTML to PDF format. We have to use two approaches:

  • on server would be used html-pdf (as Grenache microservice) with old browser emulation PhantomJS
  • on framework mode for dev mode there would be used the same html-pdf lib being added to npm dependency
  • under Electronjs there would be used the internal api which used via the IPC (between framework child process and main electronjs process) with the newest browser emulation Chromium

Feature has the following flow:

  • PUG templates which provide flexibility with inheritance and mixins
  • render PUG template to HTML + inline CSS + inline fonts in base64 to have everything in one HTML string
  • HTML converts to PDF uses browser emulation as described above

Request example where need to pass isPDFRequired flag:

{
  "auth": {
    "apiKey": "user-api-key",
    "apiSecret": "user-api-secret"
  },
  "method": "getMultipleFile",
  "params": {
    "language": "en",
    "multiExport": [
      {
        "method": "getTickersHistoryFile",
        "start": 1668564617000,
        "symbol": "tBTCUSD",
        "isPDFRequired": false
      },
      {
        "method": "getLedgersFile",
        "start": 1668564617000,
        "isPDFRequired": true
      }
    ]
  }
}

Request example with common isPDFRequired flag:

{
  "auth": {
    "apiKey": "user-api-key",
    "apiSecret": "user-api-secret"
  },
  "method": "getMultipleFile",
  "params": {
    "language": "en",
    "isPDFRequired": true,
    "multiExport": [
      {
        "method": "getTickersHistoryFile",
        "start": 1668564617000,
        "symbol": "tBTCUSD"
      },
      {
        "method": "getLedgersFile",
        "start": 1668564617000
      }
    ]
  }
}

Layout example

pdf-example

prdn and others added 30 commits November 28, 2023 08:22
Copy link
Contributor

@ezewer ezewer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants