This code will share images, try to edit it using jspdf
for create and share pdf
import domtoimage from 'dom-to-image';
import { Share } from '@capacitor/share';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { Capacitor } from '@capacitor/core';
import { Camera, CameraResultType } from '@capacitor/camera';
async shareImage() {
let receiptName = 'Receipt N:' + this.invoice?.invoiceNumber + '.png';
const div = this.screenshotElement.nativeElement;
const divHeight = div.clientHeight;
const divWidth = div.clientWidth;
const options = { background: '#ffffff', width: divWidth, height: divHeight };
await Filesystem.requestPermissions();
let base64Data = await domtoimage.toPng(div, options);
// browser download
this.downloadImgElement.nativeElement.src = base64Data;
this.downloadLinkElement.nativeElement.href = base64Data;
this.downloadLinkElement.nativeElement.download = receiptName;
this.downloadLinkElement.nativeElement.click();
// device shareing
await Filesystem.writeFile({
path: receiptName,
data: base64Data,
directory: Directory.Cache
});
let fileResult = await Filesystem.getUri({
directory: Directory.Cache,
path: receiptName
});
let imageLink = Capacitor.convertFileSrc(fileResult.uri);
Share.share({
title: receiptName,
text: receiptName,
url: fileResult.uri,
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing ::: ', error));
}