chrome-php / chrome

Instrument headless chrome/chromium instances from PHP
MIT License
2.25k stars 274 forks source link

Translate PDF directly on the Google Translate server #639

Open richardsonoge opened 1 month ago

richardsonoge commented 1 month ago

Hi there!

I've been stuck on this project for several months. I'm trying to translate my visitors' PDFs directly into the Google Translate server and I'd like you to help me do it with your library please. Here's the link: Google Translate https://translate.google.com/?hl=en&sl=en&tl=fr&op=docs

Here is the beginning of my code:

<?php

require 'vendor/autoload.php';

// Path to your PDF file and download destination
$pdfPath = 'documents/con.pdf';
$downloadPath = 'save/translated.pdf';

use HeadlessChromium\BrowserFactory;
use HeadlessChromium\Page;

$browserFactory = new BrowserFactory();

$browser = $browserFactory->createBrowser();
try {
    $page = $browser->createPage();
    $page->navigate('https://translate.google.com/?hl=en&sl=en&tl=fr&op=docs')->waitForNavigation('networkIdle', 10000);

    $elem = $page->dom()->querySelector('.ZdLswd')->click();

    // screenshot - Say "Cheese"! 😄
    $page->screenshot()->saveToFile('save/bar.png');

    // pdf
    $page->pdf(['printBackground' => true])->saveToFile('save/bar.pdf');

} finally {
    $browser->close();
}

I'm extremely stuck and I don't know what to do... PLEASE! Any help will be appreciated.

enricodias commented 1 month ago

And what is the problem you are having, specifically?

richardsonoge commented 1 month ago

And what is the problem you are having, specifically?

I'll explain it more succinctly. My main goal is to use your library to submit my PDF directly to the Google Translate server https://translate.google.com/?hl=en&sl=en&tl=fr&op=docs for translation. But I can't do that with your library. Can you help me do this or give me a block of code that I can use to do it please?