question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto-size page from image

See original GitHub issue

Would it be possible to add an option to grab width and height from an image and then doc.addPage(x: 0, y:0, width: myImageWidth, height: myImageHeight) ?

PDFKit already reads image size and it would save some complexity (adding image-size dependency)

My use case is adding several compressed scanned JPEGs to a PDF. I’d venture to say auto-sizing the pages is an expected convenience.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

34reactions
alafrcommented, Apr 7, 2018

You can achieve this with the openImage function added in v0.8.1:

var doc = new PDFDocument({autoFirstPage:false});
var img = doc.openImage(image_path_or_buffer);
doc.addPage({size: [img.width, img.height]});
doc.image(img, 0, 0);
1reaction
dilincolncommented, Feb 5, 2022

Não disponível para Typescript. Alguma ideia de quando será?

on @types folder create a file named pdfkit.d.ts and place this content below:

type OpenImageProps = {
  label: string
  image: {
    data: Blob
    pos: number
    palette: unknown[]
    imgData: Blob
    transparency: unknown
    text: unknown
    width: number
    height: number
    bits: number
    colorType: number
    compressionMethod: number
    interlaceMethod: number
    colors: number
    hasAlphaChannel: boolean
    pixelBitlength: number
    colorSpace: string
  }
  width: number
  height: number
  imgData: Blob
  obj: unknown
}

declare namespace PDFKit {
  interface PDFDocument {
    openImage(path: string): OpenImageProps
  }
}

this types was made by me and not contain all types. Be careful

Read more comments on GitHub >

github_iconTop Results From Across the Web

Free Image Resizer: Resize Photos Online | Adobe Express
Resize your photos easily with the Adobe Express free image resizer. Simply upload your pictures, change the photo size, and download your new...
Read more >
Free Image Resizer | Resize Your Images Online - Promo.com
Instant image resizer for all web and social media formats with one click. Free photo resizer for multiple sizes at the same time...
Read more >
Resize, rotate, and flip objects in Pages on Mac - Apple Support
To choose whether the object resizes freely or proportionally, in the Format sidebar, click the Arrange tab, then do one of the following:...
Read more >
How to resize an image in HTML? - ImageKit.io
One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag....
Read more >
Resize your image or photo online - It's easy, it's free!
Resize your image online in three simple steps: · Use the top left button to select and upload your picture. Resize Your Image...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found