【解決方法】ブラウザに表示される PDF のページ数を制限する

プログラミングQA


私の問題は、PDF のダウンロードに支払う前に、モデル プレビューを使用してマーケットプレイスを開発しています。プレビューとしてユーザーに表示される PDF のページ数を制限する方法です (ファイル全体の 10% を表示します)。

ゴール

!([検査、印刷、ネットワーク]タブ) || 支払って完全な書類を入手

私が試したこと:

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')
    }

});

解決策 1

シンプル: 10% の PDF を作成し、それをプレビューします。
彼らが支払いをするときなどに、完全版へのダウンロード リンクを送ります。

コメント

タイトルとURLをコピーしました