yes, it can be possible using compressing and decompressing data algorithms, So many algorithms for that but I recement use DEFLATE algorithm for compressing data.
and in JavaScript zlib library is used for compressing data, it's based on DEFLATE algorithm you can install that library using npm or yarn.
npm install zlib
after that you create code that compresseszlib.deflate()
your pdf size ;
here it's example:-
const zlib = require('zlib');
const buffer = Buffer.from(base64String, 'base64');
zlib.deflate(buffer, (err, compressedBuffer) => {
if (err) {
console. Error(err);
return;
}
const compressedBase64String = compressedBuffer.toString('base64');
// Store the compressed base-64 string in Firestore
firestore.collection('myCollection').doc('myDoc').set({
compressedPdf: compressedBase64String
});
});
and for decompress for use zlib.inflate()
example:-
const compressedBuffer = Buffer.from(compressedBase64String, 'base64');
// Decompress the buffer using the zlib library
zlib.inflate(compressedBuffer, (err, decompressedBuffer) => {
if (err) {
console. Error(err);
return;
}
const decompressedBase64String = decompressedBuffer.toString('base64');
});