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

JsPDF creating empty pdfs. #2833

Closed
subhapoduri opened this issue Aug 8, 2020 · 7 comments
Closed

JsPDF creating empty pdfs. #2833

subhapoduri opened this issue Aug 8, 2020 · 7 comments

Comments

@subhapoduri
Copy link

subhapoduri commented Aug 8, 2020

Hi,
Iam using Imagacapture API 's takePhoto() funtion which returns a image blob. Then iam converting this to base64 string and sending to jsPDF addimage . But when i say pdf. Save it creates pdf with correct no of pages but with no images in it. I didn't have this issue when i was using canvas to create images.

@subhapoduri subhapoduri changed the title JsPDF creating empty pdfs. Iam using Imagacapture API 's takePhoto() funtion which returns a image blob. Then iam converting this to base64 string and sending to jsPDF addimage . But when i say pdf. Save it creates pdf with orrect no of pages but with no image in it. JsPDF creating empty pdfs. Iam using Imagacapture API 's takePhoto() funtion which returns a image blob. Then iam converting this to base64 string and sending to jsPDF addimage . But when i say pdf. Save it creates pdf with correct no of pages but with no image in it. I dint have this issue when i was using canvas to create images. Aug 8, 2020
@subhapoduri subhapoduri changed the title JsPDF creating empty pdfs. Iam using Imagacapture API 's takePhoto() funtion which returns a image blob. Then iam converting this to base64 string and sending to jsPDF addimage . But when i say pdf. Save it creates pdf with correct no of pages but with no image in it. I dint have this issue when i was using canvas to create images. JsPDF creating empty pdfs. Aug 8, 2020
@HackbrettXXX
Copy link
Collaborator

Please share a code snippet to reproduce.

@subhapoduri
Copy link
Author

{
var width = window.doc.internal.pageSize.getWidth();
var height = window.doc.internal.pageSize.getHeight();
const img = document.getElementById("sI");

  this.props.imageCapture.takePhoto().then((blob) => {
    var reader = new FileReader();
    var imgDataURL;
    reader.readAsDataURL(blob);
    reader.onload = function () {
      imgDataURL = reader.result;
      console.log(imgDataURL);

      img.src = imgDataURL;
      this.props.updateImgList(imgDataURL);
      window.doc.addImage(
        imgDataURL.replace(/^data:image\/(png|jpg);base64,/, ""),
        "JPEG",
        0,
        0,
        width,
        height
      );
    };

for saving
window.doc.save(docTitle + ".pdf");

@HackbrettXXX
Copy link
Collaborator

Try using the data url directly without removing the data:...;base64, part. Also check out the new release.

@subhapoduri
Copy link
Author

Tried using data URL directly but still creating empty pdf.

@subhapoduri
Copy link
Author

Does the image size matter? when iam using imagecapture API to takePhoto base64 of the image is is close to 50kb could that cause problems? Also what is Compression in addImage() function for?

@Blunderchips
Copy link

@subhapoduri is this still an issue?

@subhapoduri
Copy link
Author

subhapoduri commented Sep 1, 2020

No ,it is not an issue anymore. I found a workaround.

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

No branches or pull requests

3 participants