0

I want to generate a dynamic pdf with javascript (node or deno).

I have variable data on request coming into API.

The part I can't figure out is,

For example, an array with 20 objects came from the API. I will print these values to pdf with certain shaping. But since the data coming from the API will be variable, I need to dynamically print the incoming data.

For example, another object should come just below the first object I have printed. If the object's fields exceed one page, the next page should be passed.

In accordance with any data that may come from the API.

I searched here in detail, but could not find a clear solution. (https://pdf-lib.js.org/docs/api/)

I came across a similar question in the past (Create PDF with multiple pages) But I think the situation here is a little different.

I would be very grateful if someone could enlighten me on this.

  • 1
    I looked at my PDF code that does this and the basic idea is to add a new page in between if you're getting close to the bottom of the current one (i.e. you check [https://pdf-lib.js.org/docs/api/classes/pdfpage#gety] after each object). Sounds obvious but is all I can tell you with the information you provide. –  Jul 26 '22 at 08:26
  • [{ "key":"1000 character string", "key2": "1000 character string", . } { "key":"1000 character string", "key2": "1000 character string", . }] consider such data or even more. I can't understand that I'm getting closer to the bottom of the page because the data is large and can take up more than 1 page. – Taha Yıldırım Jul 26 '22 at 08:31
  • What do you get if you simply ignore pages and just output the data? –  Jul 26 '22 at 08:32
  • a single page where most of the data is not visible – Taha Yıldırım Jul 26 '22 at 08:38
  • 1
    That's bad. If you use a fixed width font you can calculate how much space a string occupies maybe? Or split it beforehand.+ –  Jul 26 '22 at 08:39
  • I can use a way like you said. calculate the space occupied by the string and if it's more than page width and height, skip to the next page like ... idk – Taha Yıldırım Jul 26 '22 at 08:45
  • Is the PDF for printing? If so: have you considered instead generating HTML with a print style sheet? I'd be surprised to hear about a modern browser which can't save to PDF from its print menu, and print style sheets offer incredible layout control for printed pages. – jsejcksn Jul 26 '22 at 09:31

0 Answers0