-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathengine.php
More file actions
60 lines (60 loc) · 1.85 KB
/
Copy pathengine.php
File metadata and controls
60 lines (60 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// if you are using composer, just use this
include 'vendor/autoload.php';
// CONFIGURACION DEL CONVERTIDOR A HTML
use Gufy\PdfToHtml\Config;
Config::set('pdftohtml.bin', 'C:/poppler-0.51/bin/pdftohtml.exe');
Config::set('pdfinfo.bin', 'C:/poppler-0.51/bin/pdfinfo.exe');
move_uploaded_file($_FILES['src-pdf']['tmp_name'], 'document.pdf');
$pdf = new Gufy\PdfToHtml\Pdf('document.pdf');
$total_pages = $pdf->getPages();
// HASTA AQUÍ
// CONFIGURACION CONVERTIDOR A PDF
use mikehaertl\wkhtmlto\Pdf;
$pdf2 = new Pdf(array(
'binary' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe',
'ignoreWarnings' => true,
'commandOptions' => array(
'useExec' => true, // Can help if generation fails without a useful error message
'procEnv' => array(
// Check the output of 'locale' on your system to find supported languages
'LANG' => 'en_US.utf-8',
),
),
));
// HASTA AQUÍ
use Stichoza\GoogleTranslate\TranslateClient;
$page='1';
do
{
$html = $pdf->html($page);
$html = str_replace('<br>', ' AAAA ', $html);
$dom = new DOMDocument;
$dom->loadHTML('<?xml version="1.0" encoding="UTF-8"?>' . $html);
unset($html);
$b = $dom->getElementsByTagName('p');
foreach ($b as $p)
{
$tr = new TranslateClient(null, $_POST["lang"]);
$p->nodeValue = $tr->translate($p->nodeValue);
}
$html2 = $dom->saveHTML();
$html2 = str_replace('AAAA', ' <br> ', $html2);
file_put_contents('translated' . $page . '.html', $html2);
$pdf2->addPage('localhost/TRAPdf/translated' . $page . '.html');
$page++;
}
while ($page <= $total_pages);
unset($pdf);
$pdf2->saveAs('TRAPdf-translated.pdf');
$clean='1';
while ($clean <= $total_pages)
{
unlink('translated' . $clean . '.html');
$clean++;
}
unlink('document.pdf');
exec('rd C:\xampp\htdocs\TRAPdf\output\ /S /Q');
exec('md C:\xampp\htdocs\TRAPdf\output\ ');
header("Location: descargado.html");
?>