This sample shows you how to process a PDF document using Gemini.

## Code sample

### C#


Before trying this sample, follow the C# setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI C# API
reference documentation](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.html;
    using System;
    using System.Threading.Tasks;

    public class PdfInput
    {
        public async Task<string> SummarizePdf(
            string projectId = "your-project-id",
            string location = "us-central1",
            string publisher = "google",
            string model = "gemini-2.0-flash-001")
        {

            var predictionServiceClient = new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.PredictionServiceClientBuilder.html
            {
                Endpoint = $"{location}-aiplatform.googleapis.com"
            }.Build();

            string prompt = @"You are a very professional document summarization specialist.
    Please summarize the given document.";

            var generateContentRequest = new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.GenerateContentRequest.html
            {
                Model = $"projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}",
                Contents =
                {
                    new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Content.html
                    {
                        Role = "USER",
                        Parts =
                        {
                            new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Part.html { Text = prompt },
                            new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Part.html { FileData = new() { MimeType = "application/pdf", FileUri = "gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf" }}
                        }
                    }
                }
            };

            https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.GenerateContentResponse.html response = await predictionServiceClient.GenerateContentAsync(generateContentRequest);

            string responseText = response.https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.GenerateContentResponse.html#Google_Cloud_AIPlatform_V1_GenerateContentResponse_Candidates[0].https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Content.html.Parts[0].Text;
            Console.WriteLine(responseText);

            return responseText;
        }
    }

### Node.js


Before trying this sample, follow the Node.js setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI Node.js API
reference documentation](https://docs.cloud.google.com/nodejs/docs/reference/aiplatform/latest).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    const {GoogleGenAI} = require('@google/genai');

    /**
     * TODO(developer): Update these variables before running the sample.
     */
    async function analyze_pdf(
      projectId = 'PROJECT_ID',
      model = 'gemini-2.5-flash'
    ) {
      const client = new GoogleGenAI({
        vertexai: true,
        project: projectId,
        location: 'us-central1',
      });

      const filePart = {
        fileData: {
          fileUri: 'gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
          mimeType: 'application/pdf',
        },
      };

      const textPart = {
        text: `
        You are a very professional document summarization specialist.
        Please summarize the given document.`,
      };

      const response = await client.models.generateContent({
        model: model,
        contents: [filePart, textPart],
      });

      console.log(response.text);
    }

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=generativeaionvertexai).