Skip to content

addImage adds garbled data to PDF #3126

Open
@wesionaire

Description

@wesionaire

We try to add the following image to a pdf file:
image

We need to use a base64 encoding because of CORS issues.

When I try to add it using addImage, I can't open it using Adobe (Insufficient data for an image), in Chrome the image looks garbled and in PDFjs the image is not showing up at all.

Minimal example:

<!DOCTYPE html>
<html style="height: 100%;">
<head>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.3.1/jspdf.umd.min.js" integrity="sha512-VKjwFVu/mmKGk0Z0BxgDzmn10e590qk3ou/jkmRugAkSTMSIRkd4nEnk+n7r5WBbJquusQEQjBidrBD3IQQISQ==" crossorigin="anonymous"></script>
</head>
<body style="height: 100%">
	<iframe style="width: 100%; height: 100%" id="preview"></iframe>
	<script type="text/javascript">
		const imageBase64 = "data:image/png;base64,...."; // truncated too long for github, find the image here: https://pastebin.com/RA4TFqsz

		const doc = new jspdf.jsPDF();
		doc.addImage(imageBase64, "JPEG", 15, 40, 37, 40.9);
		
		var iframeElementContainer = document.getElementById('preview');
		iframeElementContainer.src=doc.output("bloburl");
	</script>
</body>
</html>

https://jsfiddle.net/7s3kr6ae/

Of course I could just open the image with Gimp and save it again (it works then), but I would rather have this issue fixed in this library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions