|
|
@@ -164,9 +164,11 @@ $driveService->files->update($driveFile->getId(), null, [
|
|
|
'removeParents' => $driveFile->getParents()[0],
|
|
|
]);
|
|
|
|
|
|
-// Create PDF
|
|
|
-$pdfFile = new Google_Service_Drive_DriveFile(['name' => $file_name . '.pdf']);
|
|
|
-$pdfFile = $driveService->files->copy($driveFile->getId(), $pdfFile, ['mimeType' => 'application/pdf']);
|
|
|
+// Export the Google Doc as a PDF using the Drive export endpoint.
|
|
|
+// files->copy() with a mimeType option does not convert formats — export() must be used instead.
|
|
|
+$pdfResponse = $driveService->files->export($driveFile->getId(), 'application/pdf', ['alt' => 'media']);
|
|
|
+$pdfBytes = $pdfResponse->getBody()->getContents();
|
|
|
+file_put_contents($file_name . '.pdf', $pdfBytes);
|
|
|
|
|
|
|
|
|
echo 'Letter copied, variables replaced, and saved in the client folder.';
|