mirror of
https://github.com/24eme/signaturepdf
synced 2024-05-21 23:26:38 +02:00
first test compression ok (#66)
This commit is contained in:
parent
d316eabaed
commit
234781c754
31
app.php
31
app.php
|
@ -390,12 +390,39 @@ $f3->route('GET /metadata',
|
|||
|
||||
$f3->route('GET /compress',
|
||||
function($f3) {
|
||||
$f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')))));
|
||||
|
||||
echo View::instance()->render('compress.html.php');
|
||||
}
|
||||
);
|
||||
|
||||
$f3->route ('POST /compress',
|
||||
function($f3) {
|
||||
$filename = null;
|
||||
$tmpfile = tempnam($f3->get('UPLOADS'), 'pdfsignature_sign');
|
||||
unlink($tmpfile);
|
||||
|
||||
$files = Web::instance()->receive(function($file,$formFieldName) {
|
||||
if ($formFieldName == "pdf" && strpos(Web::instance()->mime($file['tmp_name'], true), 'application/pdf') !== 0) {
|
||||
$f3->error(403);
|
||||
}
|
||||
});
|
||||
|
||||
$arrayPath = array_keys($files);
|
||||
$filePath = reset($arrayPath);
|
||||
$outputFileName = str_replace(".pdf", "_compressed.pdf", $filePath);
|
||||
|
||||
$returnCode = shell_exec(sprintf("gs -sDEVICE=pdfwrite -dPDFSETTINGS=/screen -dQUIET -o %s %s", $outputFileName, $filePath));
|
||||
|
||||
if ($returnCode !== false) {
|
||||
header('Content-Type: application/pdf');
|
||||
header("Content-Disposition: attachment; filename=$outputFileName");
|
||||
readfile($outputFileName);
|
||||
unlink($outputFileName);
|
||||
} else {
|
||||
echo "PDF compression failed. Please try again.";
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function getCommit() {
|
||||
if(!file_exists(__DIR__.'/.git/HEAD')) {
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
const inputFileElement = document.getElementById('input_pdf_upload');
|
||||
const compressBtn = document.getElementById('compressBtn');
|
||||
|
||||
compressBtn.addEventListener('click', async () => {
|
||||
const inputPdfFile = inputFileElement.files[0];
|
||||
|
||||
if (inputPdfFile) {
|
||||
console.log("ping");
|
||||
} else {
|
||||
alert('Please select a PDF file to compress.');
|
||||
}
|
||||
})
|
|
@ -44,18 +44,20 @@
|
|||
<a class="nav-link active" href="<?php echo $REVERSE_PROXY_URL; ?>/compress"> <?php echo sprintf(_("%s Compress"), '<i class="bi bi-chevron-bar-contract"></i>'); ?></a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="px-4 py-4 text-center">
|
||||
<h1 class="display-5 fw-bold mb-0 mt-3"> <?php echo sprintf(_("%s Compress a PDF"), '<i class="bi bi-chevron-bar-contract"></i>'); ?></h1>
|
||||
<p class="fw-light mb-3 subtitle text-dark text-nowrap" style="overflow: hidden; text-overflow: ellipsis;"><?php echo _("Reduce the size of a PDF"); ?></p>
|
||||
<div class="col-md-6 col-lg-5 col-xl-4 col-xxl-3 mx-auto">
|
||||
<form method="post" action="<?php echo $REVERSE_PROXY_URL; ?>/compress" enctype="multipart/form-data">
|
||||
<div class="px-4 py-4 text-center">
|
||||
<h1 class="display-5 fw-bold mb-0 mt-3"> <?php echo sprintf(_("%s Compress a PDF"), '<i class="bi bi-chevron-bar-contract"></i>'); ?></h1>
|
||||
<p class="fw-light mb-3 subtitle text-dark text-nowrap" style="overflow: hidden; text-overflow: ellipsis;"><?php echo _("Reduce the size of a PDF"); ?></p>
|
||||
<div class="col-12">
|
||||
<label class="form-label mt-3" for="input_pdf_upload"><?php echo _("Choose a PDF"); ?></label>
|
||||
<input id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" />
|
||||
<input name="input_pdf_upload" id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" />
|
||||
<p class="mt-2 small fw-light text-dark"> </p>
|
||||
</div>
|
||||
</div>
|
||||
<button id="compressBtn" class="btn btn-primary"><?php echo _("Compress"); ?></button>
|
||||
</div>
|
||||
<div class="col-md-6 col-lg-5 col-xl-4 col-xxl-3 mx-auto">
|
||||
<button type="submit" id="compressBtn" class="btn btn-primary"><?php echo _("Compress"); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
<footer class="text-center text-muted mb-2 fixed-bottom opacity-75">
|
||||
<small><?php echo _("Free open-source software"); ?> <span class="d-none d-md-inline"><?php echo _("under AGPL-3.0 license"); ?></span> : <a href="https://github.com/24eme/signaturepdf"><?php echo _("see the source code"); ?></a><?php if($COMMIT): ?> <span class="d-none d-md-inline small">[<a href="https://github.com/24eme/signaturepdf/tree/<?php echo $COMMIT ?>"><?php echo $COMMIT ?></a>]</span><?php endif; ?></small>
|
||||
</footer>
|
||||
|
@ -113,6 +115,6 @@
|
|||
<script>
|
||||
var defaultFields = <?php echo json_encode(isset($METADATA_DEFAULT_FIELDS) ? $METADATA_DEFAULT_FIELDS : array()); ?>;
|
||||
</script>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/js/compress.js?<?php echo ($COMMIT) ? $COMMIT : filemtime($ROOT."/public/js/compress.js") ?>"></script>
|
||||
</body>
|
||||
<!--<script src="<?php /*echo $REVERSE_PROXY_URL; */?>/js/compress.js?<?php /*echo ($COMMIT) ? $COMMIT : filemtime($ROOT."/public/js/compress.js") */?>"></script>
|
||||
--></body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue