{"id":19560096,"url":"https://github.com/plotdb/print","last_synced_at":"2025-08-11T15:14:02.586Z","repository":{"id":79658065,"uuid":"568390798","full_name":"plotdb/print","owner":"plotdb","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-23T03:19:24.000Z","size":1519,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-23T05:23:25.131Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plotdb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-20T11:47:22.000Z","updated_at":"2025-07-23T03:19:28.000Z","dependencies_parsed_at":"2025-02-26T08:30:18.948Z","dependency_job_id":"82f61224-0fd1-4da6-99ce-a4f43a3f95de","html_url":"https://github.com/plotdb/print","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/plotdb/print","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plotdb","download_url":"https://codeload.github.com/plotdb/print/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fprint/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269909743,"owners_count":24494815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T05:05:55.460Z","updated_at":"2025-08-11T15:14:02.576Z","avatar_url":"https://github.com/plotdb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @plotdb/print\n\npdf printer based on puppeteer.\n\n\n## Usage\n\nInstall:\n\n    npm install --save @plotdb/print\n\n\n`@plotdb/print` uses puppeteer to generate PDF from html or link. You can run `@plotdb/print` as a print server in Docker (called 'Cloud Mode') and request PDF via API calls, or run puppeteer directly in your server (called 'Local Mode').\n\n\n## Usage: Local Mode\n\nSince you won't need puppeteer in local server when calling @plotdb/print in cloud mode, puppeteer related modules are optional and listed in peer dependencies and can be installed via:\n\n    npm install puppeteer@^23.11.1 easy-pdf-merge@^0.2.6 tmp@^0.2.1\n\nThen, in your code:\n\n    # Get a printer instance \n    printer.get!\n      .then -\u003e\n        # Print some html\n        printer.print {html: \"my html to be printed ...\"}\n      .then (buf) -\u003e\n        # Print via link\n        printer.print {link: \"https://to-your-website...\"}\n      .then ({buf}) -\u003e # return a Buffer object of the desired PDF\n\n\n## Usage: Cloud Mode\n\nYou will have first setup api endpoint that can generate PDF for you. Check `setup API endpoint` section below.\n\nOnce you have prepared the api endpoint, in your code:\n\n    my-printer = new printer {server: {key: \"your-api-key\", url: \"api-endpoint\"}}\n    my-printer.init!\n      .then -\u003e\n        my-printer.print {link: \"https://to-your-website...\"}\n      .then ({stream}) -\u003e \n        # return a Stream object of the desired PDF, you can then e.g.:\n        stream.pipe response\n\n\n### setup API endpoint\n\nTo run @plotdb/print in cloud mode, a simple server exposing an API endpoint `/pdf` is available as `server.js`, which can be used independently or used with docker.\n\nNote Puppeteer requires certain libraries in order to run with node:20-slim, which is listed in docker/Dockerfile; however based on versions this may vary so you should modify it if necessary.\n\nAdditionally, it might have issues running puppeteer in docker under MacOS, yet it will work in places such as Cloud Run.\n\nYou can find a Dockerfile under `docker` folder, which can be built by:\n\n    cd \u003crepo-root\u003e\n    docker buildx build --platform=linux/amd64 -t \u003cyour-tag\u003e docker\n\n\n### Run a Local Server\n\nYou can run the prepared local server via:\n\n    cd \u003crepo-root\u003e\n    node dist/server.js\n\nYou probably will want to create your owner version of print server, in this case you can refe to src/server.ls or web/server.ls for a minimal example of creating a print server.\n\nThese server script read `APIKEY` environment variable which will be set via `secret.key` file in npm script `print-server` and `start`, which contains a single line of secret code. You can generate a random secret code with `crypto`:\n\n    require(\"crypto\").randomBytes(32).toString(\"base64\")\n\n\n### Deploy in Google Cloud Run with Docker Image\n\nTo build and push directly to Google Artifact Repository for later user:\n\n    docker buildx build --platform=linux/amd64 \\\n           -t [your-region]-docker.pkg.dev/[project-id]/[repo-name]/[image-name]:latest \\\n           --push docker\n\nFor example:\n    docker buildx build --platform=linux/amd64 \\\n           -t asia-east1-docker.pkg.dev/my-project/puppeteer-pdf/puppeteer-pdf:latest \\\n           --push docker\n\nTo deploy (use above name as example), you will need first create a secret:\n\n    # create: note, this only need to be run once.\n    gcloud secrets create APIKEY --data-file=\u003c(echo \"your-secret-key\")\n    # update: when you need to update your key. note old key won't be deleted automatically\n    gcloud secrets versions add APIKEY --data-file=\u003c(echo \"new-key\")\n\n    # to allow cloud run access this secret, find out your service account:\n    gcloud run services describe my-pdf-service --platform=managed --region=asia-east1 \\\n      --format=\"value(spec.template.spec.serviceAccountName)\"\n    # then grant access to it:\n    gcloud projects add-iam-policy-binding \u003cproject-id\u003e \\\n      --member=\"serviceAccount:\u003cthe-account-returned-in-previous-command\u003e\" \\\n      --role=\"roles/secretmanager.secretAccessor\"\n\n    gcloud run deploy my-pdf-service \\\n      --image=asia-east1-docker.pkg.dev/my-project/puppeteer-pdf/puppeteer-pdf:latest \\\n      --platform=managed \\\n      --region=asia-east1 \\\n      --allow-unauthenticated \\\n      --memory=512Mi \\\n      --cpu=1 \\\n      --update-secrets=APIKEY=APIKEY:latest\n\nOnce deployed, you can test it with the dummy api endpoint `ping` which should respond with a simple `pong` string:\n\n    curl https://\u003cyour-cloud-run-domain\u003e/ping\n\n\nAnd you can use the secret key you used and the url provided by google cloud run to prepare the configuration for `@plotdb/print`:\n\n    my-printer = new print {server: {key: \"your-secret-key\", url: \"path-to-cloud-run-api\"}\n    my-printer.init!then -\u003e ... \n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplotdb%2Fprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fprint/lists"}