by Lazy Sloth
Convert PDF to Google Doc
import os
from flask import Flask, request, redirect, url_for, render_template_string
from werkzeug.utils import secure_filename
from googleapiclient.http import MediaIoBaseUpload
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
from abilities import acquire_user_oauth_tokens
# Flask app setup
app = Flask(__name__)
# Define the allowed extensions, only 'pdf' files are allowed
ALLOWED_EXTENSIONS = {'pdf'}
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
return redirect(request.url)
Created: | Last Updated:
Introduction to the Convert PDF to Google Doc Template
Welcome to the Convert PDF to Google Doc template guide. This template is designed to help you create an application that allows users to upload PDF files and convert them into Google Docs. The application will authenticate users with Google and save the converted Google Docs to the user's Google Drive. This guide will walk you through the steps to set up and use this template on the Lazy platform.
Getting Started
To begin using this template, click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy or paste any code manually.
Initial Setup
Before testing the application, you need to ensure that you have the necessary credentials for Google API access. This involves setting up OAuth 2.0 credentials in the Google Cloud Console and obtaining the client ID and client secret. Here are the steps to acquire these credentials:
- Go to the Google Cloud Console.
- Select or create a new project.
- Navigate to the "Credentials" page.
- Click on "Create credentials" and select "OAuth client ID".
- Configure the consent screen if prompted.
- Set the application type to "Web application" and add the authorized redirect URIs as provided by Lazy.
- Click "Create" and take note of the client ID and client secret.
Once you have the client ID and client secret, you will need to enter these as environment secrets in the Lazy Builder:
- Go to the Environment Secrets tab within the Lazy Builder.
- Add a new secret with the key `GOOGLE_CLIENT_ID` and the value as your Google client ID.
- Add another secret with the key `GOOGLE_CLIENT_SECRET` and the value as your Google client secret.
Test: Pressing the Test Button
After setting up the environment secrets, you can test the application by clicking the "Test" button. This will deploy the app and launch the Lazy CLI.
Entering Input
If the application requires user input, the Lazy CLI will prompt you to provide it after pressing the "Test" button. Follow the instructions in the CLI to enter the necessary information.
Using the App
Once the application is running, you can use the web interface to upload a PDF file. The interface will guide you through the process of uploading the file, authenticating with Google, and converting the file into a Google Doc.
Integrating the App
After the PDF is converted to a Google Doc, the document will be saved to the user's Google Drive. You can integrate this functionality into other services or frontends by using the server link provided by Lazy. If you need to use the API endpoints in an external tool, make sure to set the appropriate scopes for Google Drive access when configuring your OAuth consent screen.
Remember, all the deployment and environment setup is handled by Lazy, so you can focus on building your application without worrying about the underlying infrastructure.
That's it! You now have a functional application that converts PDF files to Google Docs and saves them to Google Drive, all with the help of the Lazy platform.