How to Merge a PDF Document from an External Website with a Document from Google Drive that Lacks a .PDF URL?

This topic was automatically generated from Slack. You can find the original thread here.

How do i merge document from google drive and another pdf document from other website?

the other website pdf have a .pdf link which works. but google drive url does not have a .pdf url link that causing the issue

To merge a document from Google Drive with another PDF document from a different website, you can follow these steps using Pipedream: 1. Download the PDF from Google Drive: You need to access the Google Drive API to download the file. Since Google Drive URLs don’t directly link to the PDF file, you’ll need to use the Google Drive API to get the file content. 2. Download the PDF from the other website: You can use the direct URL to download the PDF file using an HTTP request. 3. Merge the PDFs: Use a library or service that can merge PDF files. You can use a Node.js library like pdf-lib to merge the PDFs within a Pipedream workflow. Here’s an example of how you might set up a Pipedream component to perform these steps: import { axios } from "@pipedream/platform"; import { PDFDocument } from "pdf-lib"; export default defineComponent({ props: { google: { type: "app", app: "google", }, otherPdfUrl: { type: "string", label: "Other PDF URL", }, }, async run({ steps, $ }) { // Step 1: Download the PDF from Google Drive const googleDriveFileId = "YOUR_GOOGLE_DRIVE_FILE_ID"; // Replace with your file ID const googleDriveResponse = await axios($, { url: `https://www.googleapis.com/drive/v3/files/${googleDriveFileId}?alt=media`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, responseType: "arraybuffer", }); // Step 2: Download the PDF from the other website const otherPdfResponse = await axios($, { url: this.otherPdfUrl, responseType: "arraybuffer", }); // Step 3: Merge the PDFs const pdfDoc = await PDFDocument.create(); const googleDrivePdf = await PDFDocument.load(googleDriveResponse); const otherPdf = await PDFDocument.load(otherPdfResponse); const [googleDrivePage] = await pdfDoc.copyPages(googleDrivePdf, [0]); const [otherPdfPage] = await pdfDoc.copyPages(otherPdf, [0]); pdfDoc.addPage(googleDrivePage); pdfDoc.addPage(otherPdfPage); const mergedPdfBytes = await pdfDoc.save(); // Return the merged PDF as a base64 string return { mergedPdf: mergedPdfBytes.toString('base64'), }; }, }); ### Notes: - Replace "YOUR_GOOGLE_DRIVE_FILE_ID" with the actual file ID from Google Drive. - Ensure you have the necessary OAuth scopes for Google Drive API access. - The pdf-lib library is used to merge the PDFs. You can install it by importing it at the top of your component. - The merged PDF is returned as a base64 string. You can modify the code to save it to a file or perform other actions as needed. If you encounter any issues or need further assistance, please visit Pipedream Support.

this code work after some minor adjustment. I now want to upload to Signnow using Google Doc URL. But when i try to run it, it saying error during upload with code error 21004000. How to make this work

Here the Google Doc URL: https://drive.google.com/file/d/asdjkxzckzxlkjasoidjasjd/view?usp=drivesdk

Here my code:
import axios from “axios”;

export default defineComponent({
name: “Upload Document to SignNow”,
version: “0.0.1”,
type: “action”,
key: “upload_document_signnow”,
description: “Uploads a document to SignNow from a URL and assigns a signer without sending.”,
props: {
signnow: {
type: “app”,
app: “signnow”,
},
fileUrl: {
type: “string”,
label: “File URL”,
description: “Enter the URL of the document to upload.”,
},
signerEmail: {
type: “string”,
label: “Signer Email”,
description: “Enter the email address of the signer.”,
},
signerRole: {
type: “string”,
label: “Signer Role”,
description: “Enter the role of the signer (e.g., ‘Customer’, ‘Recipient 1’).”,
default: “Customer”, // Default role, update as needed
},
checkFields: {
type: “boolean”,
label: “Check Fields”,
description: “Set to true to check fields in the document.”,
default: true,
},
},
async run({ steps, $ }) {
// Get OAuth token from Pipedream account store
const authToken = this.signnow.$auth.oauth_access_token;

const headers = {
  Authorization: `Bearer ${authToken}`,
  "Content-Type": "application/json",
  Accept: "application/json",
};

const payload = {
  url: this.fileUrl,
  check_fields: this.checkFields,
  signers: [
    {
      email: this.signerEmail, // Assign the email
      role: this.signerRole, // Assign the role (e.g., 'Customer' or 'Recipient 1')
      order: 1, // Ensures signing order
    },
  ],
};

try {
  const response = await [axios.post](http://axios.post)(
    "https://api.signnow.com/v2/documents/url",
    payload,
    { headers }
  );

  return response.data;
} catch (error) {
  return { error: error.response?.data || error.message };
}

},
});