{"action":"created","issue":{"url":"https://api.github.com/repos/Hopding/react-native-pdf-lib/issues/30","repository_url":"https://api.github.com/repos/Hopding/react-native-pdf-lib","labels_url":"https://api.github.com/repos/Hopding/react-native-pdf-lib/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/Hopding/react-native-pdf-lib/issues/30/comments","events_url":"https://api.github.com/repos/Hopding/react-native-pdf-lib/issues/30/events","html_url":"https://github.com/Hopding/react-native-pdf-lib/issues/30","id":370807797,"node_id":"MDU6SXNzdWUzNzA4MDc3OTc=","number":30,"title":"Array of Pages","user":{"login":"mrfambo","id":16781300,"node_id":"MDQ6VXNlcjE2NzgxMzAw","avatar_url":"https://avatars2.githubusercontent.com/u/16781300?v=4","gravatar_id":"","url":"https://api.github.com/users/mrfambo","html_url":"https://github.com/mrfambo","followers_url":"https://api.github.com/users/mrfambo/followers","following_url":"https://api.github.com/users/mrfambo/following{/other_user}","gists_url":"https://api.github.com/users/mrfambo/gists{/gist_id}","starred_url":"https://api.github.com/users/mrfambo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrfambo/subscriptions","organizations_url":"https://api.github.com/users/mrfambo/orgs","repos_url":"https://api.github.com/users/mrfambo/repos","events_url":"https://api.github.com/users/mrfambo/events{/privacy}","received_events_url":"https://api.github.com/users/mrfambo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-16T21:29:20Z","updated_at":"2018-10-17T14:48:51Z","closed_at":"2018-10-17T14:48:51Z","author_association":"NONE","body":"The library is great but i am very surprised to see that i need to define all pages first. What if my PDF can have multiple pages like sometimes 5, 10 or 20.\r\n\r\nIs there any way to create pages programmatically in an array and pass that array when creating the PDF file?"},"comment":{"url":"https://api.github.com/repos/Hopding/react-native-pdf-lib/issues/comments/430659117","html_url":"https://github.com/Hopding/react-native-pdf-lib/issues/30#issuecomment-430659117","issue_url":"https://api.github.com/repos/Hopding/react-native-pdf-lib/issues/30","id":430659117,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDY1OTExNw==","user":{"login":"Hopding","id":10351828,"node_id":"MDQ6VXNlcjEwMzUxODI4","avatar_url":"https://avatars0.githubusercontent.com/u/10351828?v=4","gravatar_id":"","url":"https://api.github.com/users/Hopding","html_url":"https://github.com/Hopding","followers_url":"https://api.github.com/users/Hopding/followers","following_url":"https://api.github.com/users/Hopding/following{/other_user}","gists_url":"https://api.github.com/users/Hopding/gists{/gist_id}","starred_url":"https://api.github.com/users/Hopding/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hopding/subscriptions","organizations_url":"https://api.github.com/users/Hopding/orgs","repos_url":"https://api.github.com/users/Hopding/repos","events_url":"https://api.github.com/users/Hopding/events{/privacy}","received_events_url":"https://api.github.com/users/Hopding/received_events","type":"User","site_admin":false},"created_at":"2018-10-17T14:48:51Z","updated_at":"2018-10-17T14:48:51Z","author_association":"OWNER","body":"Certainly. The following should do the trick:\r\n```js\r\nconst pages = [];\r\n\r\nfor (let i = 0; i < 5; i++) {\r\n  pages.push(\r\n    PDFPage\r\n      .create()\r\n      .setMediaBox(250, 250)\r\n      .drawText(`This is page number ${i + 1}`)\r\n  );\r\n}\r\n\r\nconst docsDir = await PDFLib.getDocumentsDirectory();\r\nconst pdfPath = `${docsDir}/sample.pdf`;\r\nPDFDocument\r\n  .create(pdfPath)\r\n  .addPages(...pages)\r\n  .write()\r\n  .then(path => {\r\n    console.log('PDF created at: ' + path);\r\n  });\r\n```\r\nYou could also do it this way:\r\n```js\r\nconst docsDir = await PDFLib.getDocumentsDirectory();\r\nconst pdfPath = `${docsDir}/sample.pdf`;\r\nconst pdfDoc = PDFDocument.create(pdfPath);\r\n\r\nfor (let i = 0; i < 5; i++) {\r\n  const page = PDFPage\r\n    .create()\r\n    .setMediaBox(250, 250)\r\n    .drawText(`This is page number ${i + 1}`);\r\n  pdfDoc.addPages(page);\r\n}\r\n\r\npdfDoc.write().then(path => {\r\n  console.log('PDF created at: ' + path);\r\n});\r\n```"}}
{"actor":{"display_login":"Hopding"}}