Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

678
Visualizações
How to export Google Sheets to PDF in a custom format with Google Api v3?

I am using the Google drive v3 and try to export a Google Spreadsheet file to PDF. Almost everything works like expected.

Exception:

the generated PDF is always in format LETTER and PORTRAIT, but i need the pdf in DIN A4 and landscape. I am not able to find any settings/parameters to submit to v3 to generate PDFs in other formats.

I have found solutions for Google drive v2 but not for Google drive v3.

Passing format or portrait as optional parameter results in an error :-(

    /**
     * Downloads a Google file in a specified mime type.
     *
     * @param string   $googleDriveFileId id of the drive file which should be downloaded
     * @param string   $mimeType          mime type
     * @param string[] $optParams
     *
     * @return Response
     *
     * @link https://developers.google.com/drive/api/v3/reference/files/export
     * @link https://developers.google.com/drive/api/v3/ref-export-formats
     */
    public function download(string $googleDriveFileId, string $mimeType, array $optParams= []): Response
    {
        /** @var Response $resonse */
        return $this->googleServiceProvider->getGoogleServiceDrive()->files->export(
            $googleDriveFileId,
            $mimeType,
            $optParams
        );
    }
    [...]
    "name": "google/apiclient",
    "version": "v2.11.0",
    [...]
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can use link to download the file.

https://docs.google.com/spreadsheets/d/[YOUR-ID]/export?format=pdf&portrait=false&size=A4

over 4 years ago · Santiago Trujillo Relatório

0

If you check the documentation for Files.export

enter image description here

You will find that it takes fileId as a path parameter and mimeType as a required parameter. Then their is an option of adding fields which is a standard optional parameter for this API.

To call the endpoint you would use.

var result = service.files.export(fileId, "application/pdf");

Google will then export the file as is. To export it within the the google sheets api itself is done via the print menu it reformats it at that time.

If you add the following to the url then it will change the format

var url_ext = 'export?exportFormat=pdf&format=pdf&portrait=false'

The issue is that im not sure if this is something you can add with the PHP client library or if this is something you may have to code yourself.

If you do decide to go this route just get the access token from the $client and then you can send that as a bearer token with your request. It may be worth asking a question on the Google api php client lbiary git hub page they will know if its posable to add something to the request.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda