@napi-rs/svg2pdf
Convert SVG to PDF.
Usage
import { convert } from '@napi-rs/svg2pdf'
const pdf = convert(`
<svg width="800" height="400" viewBox="0 0 800 400" xmlns="http://www.w3.org/2000/svg"><rect x="0" y="0" width="800" height="400" fill="white"/><clipPath id="satori_bct-id-0"><path d="M306.3 137.2L306.3 137.2L290.8 137.2L290.8 93.5L306.4 93.5Q313.0 93.5 317.7 96.1Q322.5 98.7 325.0 103.6Q327.6 108.5 327.6 115.3L327.6 115.3Q327.6 122.1 325.0 127.0Q322.5 131.9 317.7 134.5Q312.9 137.2 306.3 137.2ZM300.0 101.4L300.0 129.3L305.9 129.3Q310.0 129.3 312.8 127.8Q315.6 126.3 317.0 123.3Q318.4 120.2 318.4 115.3L318.4 115.3Q318.4 110.5 317.0 107.4Q315.6 104.3 312.8 102.9Q310.0 101.4 305.9 101.4L305.9 101.4L300.0 101.4ZM347.2 137.8L347.2 137.8Q342.1 137.8 338.5 135.7Q334.9 133.7 332.9 129.9Q330.9 126.1 330.9 120.9L330.9 120.9Q330.9 115.9 332.9 112.1Q334.9 108.3 338.4 106.1Q342.0 104.0 346.8 104.0L346.8 104.0Q350.0 104.0 352.9 105.0Q355.7 106.1 357.8 108.1Q359.9 110.2 361.0 113.3Q362.2 116.5 362.2 120.6L362.2 120.6L362.2 123.1L334.6 123.1L334.6 117.5L353.7 117.5Q353.7 115.5 352.8 114.0Q351.9 112.5 350.4 111.6Q348.9 110.8 347.0 110.8L347.0 110.8Q344.9 110.8 343.3 111.7Q341.7 112.7 340.8 114.3Q339.9 115.9 339.9 117.8L339.9 117.8L339.9 123.1Q339.9 125.6 340.8 127.3Q341.7 129.1 343.4 130.1Q345.0 131.0 347.3 131.0L347.3 131.0Q348.8 131.0 350.1 130.6Q351.3 130.2 352.2 129.3Q353.1 128.5 353.6 127.2L353.6 127.2L362.0 127.8Q361.4 130.8 359.4 133.1Q357.4 135.3 354.3 136.6Q351.2 137.8 347.2 137.8ZM386.1 104.4L395.7 104.4L384.3 137.2L374.0 137.2L362.6 104.4L372.2 104.4L379.0 127.8L379.3 127.8L386.1 104.4ZM412.2 137.8L412.2 137.8Q407.1 137.8 403.5 135.7Q399.9 133.7 397.9 129.9Q396.0 126.1 396.0 120.9L396.0 120.9Q396.0 115.9 397.9 112.1Q399.9 108.3 403.4 106.1Q407.0 104.0 411.8 104.0L411.8 104.0Q415.1 104.0 417.9 105.0Q420.7 106.1 422.8 108.1Q424.9 110.2 426.0 113.3Q427.2 116.5 427.2 120.6L427.2 120.6L427.2 123.1L399.6 123.1L399.6 117.5L418.7 117.5Q418.7 115.5 417.8 114.0Q417.0 112.5 415.5 111.6Q414.0 110.8 412.0 110.8L412.0 110.8Q409.9 110.8 408.3 111.7Q406.7 112.7 405.8 114.3Q404.9 115.9 404.9 117.8L404.9 117.8L404.9 123.1Q404.9 125.6 405.8 127.3Q406.7 129.1 408.4 130.1Q410.1 131.0 412.3 131.0L412.3 131.0Q413.8 131.0 415.1 130.6Q416.4 130.2 417.3 129.3Q418.2 128.5 418.6 127.2L418.6 127.2L427.0 127.8Q426.4 130.8 424.4 133.1Q422.4 135.3 419.3 136.6Q416.2 137.8 412.2 137.8ZM431.1 93.5L440.2 93.5L440.2 137.2L431.1 137.2L431.1 93.5ZM460.2 137.8L460.2 137.8Q455.3 137.8 451.7 135.7Q448.1 133.6 446.1 129.8Q444.1 126.0 444.1 120.9L444.1 120.9Q444.1 115.9 446.1 112.1Q448.1 108.2 451.7 106.1Q455.3 104.0 460.2 104.0L460.2 104.0Q465.2 104.0 468.8 106.1Q472.4 108.2 474.4 112.1Q476.3 115.9 476.3 120.9L476.3 120.9Q476.3 126.0 474.4 129.8Q472.4 133.6 468.8 135.7Q465.2 137.8 460.2 137.8ZM460.3 130.8L460.3 130.8Q462.5 130.8 464.1 129.5Q465.6 128.2 466.3 126.0Q467.1 123.7 467.1 120.9L467.1 120.9Q467.1 118.0 466.3 115.8Q465.6 113.5 464.1 112.2Q462.5 110.9 460.3 110.9L460.3 110.9Q458.0 110.9 456.5 112.2Q454.9 113.5 454.1 115.8Q453.4 118.0 453.4 120.9L453.4 120.9Q453.4 123.7 454.1 126.0Q454.9 128.2 456.5 129.5Q458.0 130.8 460.3 130.8ZM489.3 149.4L480.3 149.4L480.3 104.4L489.2 104.4L489.2 109.9L489.6 109.9Q490.2 108.6 491.4 107.2Q492.5 105.9 494.3 104.9Q496.2 104.0 498.9 104.0L498.9 104.0Q502.5 104.0 505.5 105.9Q508.6 107.7 510.4 111.5Q512.2 115.2 512.2 120.8L512.2 120.8Q512.2 126.3 510.4 130.1Q508.7 133.8 505.7 135.8Q502.6 137.7 498.9 137.7L498.9 137.7Q496.3 137.7 494.4 136.8Q492.6 135.9 491.4 134.6Q490.2 133.3 489.6 131.9L489.6 131.9L489.3 131.9L489.3 149.4ZM489.2 120.8L489.2 120.8Q489.2 123.7 490.0 125.9Q490.8 128.1 492.3 129.3Q493.8 130.5 496.0 130.5L496.0 130.5Q498.3 130.5 499.8 129.2Q501.3 128.0 502.1 125.8Q502.9 123.7 502.9 120.8L502.9 120.8Q502.9 118.0 502.1 115.8Q501.3 113.7 499.8 112.4Q498.3 111.2 496.0 111.2L496.0 111.2Q493.8 111.2 492.3 112.4Q490.8 113.6 490.0 115.7Q489.2 117.9 489.2 120.8Z "/></clipPath><defs><linearGradient id="satori_biid-0_0" x1="0" y1="0" x2="1" y2="0"><stop offset="0%" stop-color="rgb(0,124,240)"/><stop offset="100%" stop-color="rgb(0,223,216)"/></linearGradient></defs><rect x="247" y="76" width="306" height="83" fill="url(#satori_biid-0_0)" clip-path="url(#satori_bct-id-0)"/><clipPath id="satori_bct-id-1"><path d="M303.0 220.2L293.8 220.2L293.8 176.5L311.0 176.5Q316.0 176.5 319.5 178.4Q323.0 180.3 324.8 183.6Q326.6 187.0 326.6 191.3L326.6 191.3Q326.6 195.7 324.8 199.0Q322.9 202.3 319.4 204.2Q315.8 206.0 310.8 206.0L310.8 206.0L299.8 206.0L299.8 198.6L309.3 198.6Q311.9 198.6 313.7 197.7Q315.4 196.8 316.3 195.1Q317.1 193.5 317.1 191.3L317.1 191.3Q317.1 189.1 316.3 187.5Q315.4 185.9 313.7 185.0Q311.9 184.1 309.2 184.1L309.2 184.1L303.0 184.1L303.0 220.2ZM339.6 220.2L330.5 220.2L330.5 187.4L339.3 187.4L339.3 193.1L339.6 193.1Q340.5 190.1 342.6 188.5Q344.7 187.0 347.5 187.0L347.5 187.0Q348.2 187.0 349.0 187.0Q349.7 187.1 350.3 187.3L350.3 187.3L350.3 195.3Q349.7 195.1 348.6 195.0Q347.4 194.8 346.5 194.8L346.5 194.8Q344.5 194.8 342.9 195.7Q341.4 196.6 340.5 198.1Q339.6 199.6 339.6 201.6L339.6 201.6L339.6 220.2ZM366.4 220.8L366.4 220.8Q361.3 220.8 357.7 218.7Q354.1 216.7 352.1 212.9Q350.2 209.1 350.2 203.9L350.2 203.9Q350.2 198.9 352.1 195.1Q354.1 191.3 357.6 189.1Q361.2 187.0 366.0 187.0L366.0 187.0Q369.3 187.0 372.1 188.0Q374.9 189.1 377.0 191.1Q379.1 193.2 380.2 196.3Q381.4 199.5 381.4 203.6L381.4 203.6L381.4 206.1L353.8 206.1L353.8 200.5L372.9 200.5Q372.9 198.5 372.0 197.0Q371.2 195.5 369.7 194.6Q368.2 193.8 366.2 193.8L366.2 193.8Q364.1 193.8 362.5 194.7Q360.9 195.7 360.0 197.3Q359.1 198.9 359.1 200.8L359.1 200.8L359.1 206.1Q359.1 208.6 360.0 210.3Q360.9 212.1 362.6 213.1Q364.3 214.0 366.5 214.0L366.5 214.0Q368.1 214.0 369.3 213.6Q370.6 213.2 371.5 212.3Q372.4 211.5 372.8 210.2L372.8 210.2L381.2 210.8Q380.6 213.8 378.6 216.1Q376.6 218.3 373.5 219.6Q370.4 220.8 366.4 220.8ZM405.3 187.4L414.9 187.4L403.5 220.2L393.3 220.2L381.8 187.4L391.4 187.4L398.2 210.8L398.5 210.8L405.3 187.4ZM426.7 220.2L417.6 220.2L417.6 187.4L426.7 187.4L426.7 220.2ZM422.1 183.2L422.1 183.2Q420.1 183.2 418.7 181.9Q417.2 180.5 417.2 178.6L417.2 178.6Q417.2 176.7 418.7 175.4Q420.1 174.0 422.1 174.0L422.1 174.0Q424.2 174.0 425.6 175.4Q427.0 176.7 427.0 178.6L427.0 178.6Q427.0 180.5 425.6 181.9Q424.2 183.2 422.1 183.2ZM446.8 220.8L446.8 220.8Q441.8 220.8 438.1 218.7Q434.5 216.7 432.5 212.9Q430.6 209.1 430.6 203.9L430.6 203.9Q430.6 198.9 432.5 195.1Q434.5 191.3 438.1 189.1Q441.6 187.0 446.4 187.0L446.4 187.0Q449.7 187.0 452.5 188.0Q455.3 189.1 457.4 191.1Q459.5 193.2 460.7 196.3Q461.8 199.5 461.8 203.6L461.8 203.6L461.8 206.1L434.2 206.1L434.2 200.5L453.3 200.5Q453.3 198.5 452.4 197.0Q451.6 195.5 450.1 194.6Q448.6 193.8 446.6 193.8L446.6 193.8Q444.5 193.8 442.9 194.7Q441.4 195.7 440.5 197.3Q439.6 198.9 439.5 200.8L439.5 200.8L439.5 206.1Q439.5 208.6 440.5 210.3Q441.4 212.1 443.0 213.1Q444.7 214.0 447.0 214.0L447.0 214.0Q448.5 214.0 449.7 213.6Q451.0 213.2 451.9 212.3Q452.8 211.5 453.2 210.2L453.2 210.2L461.6 210.8Q461.0 213.8 459.0 216.1Q457.1 218.3 454.0 219.6Q450.9 220.8 446.8 220.8ZM481.5 220.2L472.0 220.2L463.0 187.4L472.2 187.4L477.3 209.4L477.6 209.4L482.9 187.4L491.9 187.4L497.3 209.3L497.5 209.3L502.5 187.4L511.7 187.4L502.8 220.2L493.2 220.2L487.6 199.6L487.2 199.6L481.5 220.2Z "/></clipPath><defs><linearGradient id="satori_biid-1_0" x1="0" y1="0" x2="1" y2="0"><stop offset="0%" stop-color="rgb(121,40,202)"/><stop offset="100%" stop-color="rgb(255,0,128)"/></linearGradient></defs><rect x="250" y="159" width="300" height="82" fill="url(#satori_biid-1_0)" clip-path="url(#satori_bct-id-1)"/><clipPath id="satori_bct-id-2"><path d="M374.3 271.1L365.5 271.1Q365.2 268.5 363.3 267.1Q361.3 265.6 358.0 265.6L358.0 265.6Q355.7 265.6 354.2 266.3Q352.6 266.9 351.8 268.0Q351.0 269.1 351.0 270.5L351.0 270.5Q351.0 271.7 351.5 272.6Q352.0 273.4 353 274.1Q354.0 274.7 355.2 275.2Q356.5 275.6 357.9 275.9L357.9 275.9L361.8 276.9Q364.7 277.5 367.1 278.6Q369.4 279.6 371.2 281.2Q372.9 282.7 373.9 284.9Q374.9 287.0 374.9 289.7L374.9 289.7Q374.9 293.7 372.9 296.6Q370.9 299.6 367.1 301.2Q363.3 302.8 358.0 302.8L358.0 302.8Q352.7 302.8 348.8 301.2Q344.9 299.5 342.7 296.4Q340.5 293.2 340.4 288.5L340.4 288.5L349.3 288.5Q349.5 290.7 350.6 292.1Q351.7 293.6 353.6 294.3Q355.5 295.0 357.9 295.0L357.9 295.0Q360.2 295.0 361.9 294.4Q363.7 293.7 364.6 292.5Q365.6 291.3 365.6 289.7L365.6 289.7Q365.6 288.2 364.7 287.2Q363.9 286.2 362.2 285.5Q360.6 284.8 358.2 284.2L358.2 284.2L353.4 283.0Q347.9 281.7 344.7 278.8Q341.5 276.0 341.5 271.1L341.5 271.1Q341.5 267.2 343.7 264.2Q345.8 261.3 349.5 259.6Q353.3 257.9 358.1 257.9L358.1 257.9Q362.9 257.9 366.6 259.6Q370.2 261.3 372.2 264.2Q374.2 267.2 374.3 271.1L374.3 271.1ZM388.0 283.2L388.0 283.2L388.0 302.2L378.9 302.2L378.9 258.5L387.7 258.5L387.7 275.2L388.1 275.2Q389.2 272.3 391.7 270.7Q394.2 269.0 397.9 269.0L397.9 269.0Q401.3 269.0 403.9 270.5Q406.4 272.0 407.8 274.7Q409.2 277.5 409.2 281.3L409.2 281.3L409.2 302.2L400.1 302.2L400.1 282.9Q400.2 279.9 398.6 278.2Q397.1 276.5 394.3 276.5L394.3 276.5Q392.4 276.5 391.0 277.3Q389.6 278.1 388.8 279.6Q388.0 281.1 388.0 283.2ZM423.4 302.2L414.4 302.2L414.4 269.4L423.4 269.4L423.4 302.2ZM418.9 265.2L418.9 265.2Q416.9 265.2 415.5 263.9Q414.0 262.5 414.0 260.6L414.0 260.6Q414.0 258.7 415.5 257.4Q416.9 256.0 418.9 256.0L418.9 256.0Q421.0 256.0 422.4 257.4Q423.8 258.7 423.8 260.6L423.8 260.6Q423.8 262.5 422.4 263.9Q421.0 265.2 418.9 265.2ZM437.8 314.4L428.7 314.4L428.7 269.4L437.6 269.4L437.6 274.9L438.0 274.9Q438.6 273.6 439.8 272.2Q440.9 270.9 442.8 269.9Q444.6 269.0 447.4 269.0L447.4 269.0Q450.9 269.0 454.0 270.9Q457.0 272.7 458.8 276.5Q460.6 280.2 460.6 285.8L460.6 285.8Q460.6 291.3 458.9 295.1Q457.1 298.8 454.1 300.8Q451.1 302.7 447.3 302.7L447.3 302.7Q444.7 302.7 442.8 301.8Q441.0 300.9 439.8 299.6Q438.7 298.3 438.0 296.9L438.0 296.9L437.8 296.9L437.8 314.4ZM437.6 285.8L437.6 285.8Q437.6 288.7 438.4 290.9Q439.2 293.1 440.7 294.3Q442.3 295.5 444.5 295.5L444.5 295.5Q446.7 295.5 448.2 294.2Q449.7 293.0 450.5 290.8Q451.3 288.7 451.3 285.8L451.3 285.8Q451.3 283.0 450.6 280.8Q449.8 278.7 448.2 277.4Q446.7 276.2 444.5 276.2L444.5 276.2Q442.2 276.2 440.7 277.4Q439.2 278.6 438.4 280.7Q437.6 282.9 437.6 285.8Z "/></clipPath><defs><linearGradient id="satori_biid-2_0" x1="0" y1="0" x2="1" y2="0"><stop offset="0%" stop-color="rgb(255,77,77)"/><stop offset="100%" stop-color="rgb(249,203,40)"/></linearGradient></defs><rect x="298" y="241" width="204" height="83" fill="url(#satori_biid-2_0)" clip-path="url(#satori_bct-id-2)"/></svg>
`)
Install this test package
yarn add @napi-rs/svg2pdf
Support matrix
Operating Systems
node14 | node16 | node18 | |
---|---|---|---|
Windows x64 | ✓ | ✓ | ✓ |
Windows x32 | ✓ | ✓ | ✓ |
Windows arm64 | ✓ | ✓ | ✓ |
macOS x64 | ✓ | ✓ | ✓ |
macOS arm64 | ✓ | ✓ | ✓ |
Linux x64 gnu | ✓ | ✓ | ✓ |
Linux x64 musl | ✓ | ✓ | ✓ |
Linux arm gnu | ✓ | ✓ | ✓ |
Linux arm64 gnu | ✓ | ✓ | ✓ |
Linux arm64 musl | ✓ | ✓ | ✓ |
Android arm64 | ✓ | ✓ | ✓ |
Android armv7 | ✓ | ✓ | ✓ |
FreeBSD x64 | ✓ | ✓ | ✓ |