Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addImage function can't recognize ImageCompression variable #3015

Closed
luancloudmis opened this issue Dec 1, 2020 · 3 comments
Closed

addImage function can't recognize ImageCompression variable #3015

luancloudmis opened this issue Dec 1, 2020 · 3 comments
Labels

Comments

@luancloudmis
Copy link

luancloudmis commented Dec 1, 2020

Hi, I'm using jsPDF version 2.1.1. When I try to reduce the size of pdf file by using ImageCompression, but the text editor returns a problem
No overload matches this call. Overload 1 of 3, '(imageData: string | HTMLImageElement | HTMLCanvasElement | Uint8Array, format: string, x: number, y: number, w: number, h: number, alias?: string, compression?: ImageCompression, rotation?: number): jsPDF', gave the following error. Argument of type 'string' is not assignable to parameter of type 'ImageCompression'. Overload 2 of 3, '(imageData: string | HTMLImageElement | HTMLCanvasElement | Uint8Array, x: number, y: number, w: number, h: number, alias?: string, compression?: ImageCompression, rotation?: number): jsPDF', gave the following error. Argument of type 'number' is not assignable to parameter of type 'string'.

Here is my code as an example:

convert(_objImage) {
    let doc = new jsPDF({compress: true});
    let imgData ="data:image/" + _objImage.extension + ";base64," + _objImage.content;
    let imageProps = doc.getImageProperties(imgData);
    let imageWidth = 0;
    let imageHeight = 0;
    if(this.getSizeInMM(imageProps.width) > doc.internal.pageSize.getWidth()){
      imageWidth = 0.9 * doc.internal.pageSize.getWidth();
      imageHeight = imageWidth * (this.getSizeInMM(imageProps.height) / this.getSizeInMM(imageProps.width));
    }
    doc.addImage(imgData, _objImage.extension, 15, 40, imageWidth , imageHeight, undefined,'FAST');
    let base64pdf = btoa(doc.output());
    return base64pdf;
  }

Hope you guys can solve this problem for me! Thanks so much

@HackbrettXXX
Copy link
Collaborator

That's a known issue and will be fixed with the next release.

@HackbrettXXX
Copy link
Collaborator

Closing this in favor of #3013.

@zerogravity2020
Copy link

@luancloudmis luancloudmis
interface ImageOptions {
imageData:
| string
| HTMLImageElement
| HTMLCanvasElement
| Uint8Array
| RGBAData;
x: number;
y: number;
width: number;
height: number;
alias?: string;
compression?: ImageCompression;
rotation?: number;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants