Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a marketplace with model preview before paying to download for pdf's my problem is how to restrict the number of pages of pdf showing to the user as preview(show 10% of the whole file).


Goal

!(Inspect, Print & Network tab) || Pay & get full document

What I have tried:

I tried to use pdfjs to render the pdf on canvas but when I see the network request the full file is downloadable. I store files on fs and path on sql db.


And also i tried read the pdf uploaded by user's and split it with hummusjs on the server then send it to the browser but this is not scalable for many files


JavaScript
<pre>app.get('/', (req, res) => {
    //hummusjs
    let readPdf = hum.createReader('./uploads/quote.pdf-1675405130171.pdf');
    let pageCount = readPdf.getPagesCount();
    writePdf = hum.createWriter('preview.pdf');
    writePdf
        .createPDFCopyingContext(readPdf)
        .appendPDFPageFromPDF(0);
    writePdf.end()


    const path = './preview.pdf';
    if (fs.existsSync(path)) {
        res.contentType("application/pdf");
        fs.createReadStream(path).pipe(res)
    } else {
        res.status(500)
        console.log('File not found')
        res.send('File not found')
    }

});
Posted
Updated 5-Feb-23 0:07am

1 solution

Simple: create a 10% PDF and preview that and that alone.
When they pay or whatever, send them a download link to the full version.
 
Share this answer
 
Comments
Natnael Tibebu 5-Feb-23 5:13am    
how can i create it can you please share me alink or suggest me some libraries

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900