> ## Documentation Index
> Fetch the complete documentation index at: https://www.studyfetch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PDF Generator

> Generate PDF presentations from topics

## Overview

The PDF Generator service allows you to create PDF presentations on any topic. This is useful for:

* Generating educational presentation slides
* Creating topic-specific presentations
* Producing multilingual presentations
* Building quick presentation outlines

## Create PDF Presentation

Generate a new PDF presentation on a specific topic.

<CodeGroup>
  ```javascript JavaScript theme={null}
  import StudyfetchSDK from '@studyfetch/sdk';

  const client = new StudyfetchSDK({
    apiKey: 'your-api-key',
    baseURL: 'https://studyfetchapi.com',
  });

  const pdfResponse = await client.v1.pdfGenerator.create({
    topic: 'Biology Chapter 1 Summary',
    numberOfSlides: 10,
    locale: 'en'
  });

  console.log('PDF created:', pdfResponse.presentation?._id);
  console.log('Success:', pdfResponse.success);
  ```

  ```python Python theme={null}
  from studyfetch_sdk import StudyfetchSDK

  client = StudyfetchSDK(
      api_key="your-api-key",
      base_url="https://studyfetchapi.com",
  )

  pdf_response = client.v1.pdf_generator.create({
      "topic": "Biology Chapter 1 Summary",
      "number_of_slides": 10,
      "locale": "en"
  })

  print(f"PDF created: {pdf_response.presentation._id if pdf_response.presentation else 'None'}")
  print(f"Success: {pdf_response.success}")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.pdfgenerator.PdfGeneratorCreateParams;
  import com.studyfetch.javasdk.models.v1.pdfgenerator.PdfGeneratorCreateResponse;
  import java.util.List;

  StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
      .apiKey(System.getenv("STUDYFETCH_API_KEY"))
      .baseUrl("https://studyfetchapi.com")
      .build();

  PdfGeneratorCreateParams params = PdfGeneratorCreateParams.builder()
      .topic("Biology Chapter 1 Summary")
      .numberOfSlides(10)
      .locale("en")
      .build();

  PdfGeneratorCreateResponse pdfResponse = client.v1().pdfGenerator().create(params);

  System.out.println("PDF created: " + pdfResponse.presentation()._id());
  System.out.println("Success: " + pdfResponse.success());
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.PdfGenerator;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;

  public class CreatePdfPresentation
  {
      public static async Task CreatePdf()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          var pdfResponse = await client.V1.PdfGenerator.Create(new()
          {
              Topic = "Biology Chapter 1 Summary",
              NumberOfSlides = 10,
              Locale = "en"
          });

          Console.WriteLine($"PDF created: {pdfResponse.Presentation?._ID}");
          Console.WriteLine($"Success: {pdfResponse.Success}");
      }
  }
  ```
</CodeGroup>

## Get All PDFs

Retrieve a list of all generated PDFs.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const pdfs = await client.v1.pdfGenerator.getAll();

  pdfs.forEach(pdf => {
    console.log(`${pdf.topic} - ${pdf.createdAt}`);
    console.log(`ID: ${pdf._id}`);
    console.log(`Slides: ${pdf.numberOfSlides}`);
  });
  ```

  ```python Python theme={null}
  pdfs = client.v1.pdf_generator.get_all()

  for pdf in pdfs:
      print(f"{pdf.topic} - {pdf.created_at}")
      print(f"ID: {pdf._id}")
      print(f"Slides: {pdf.number_of_slides}")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.models.v1.pdfgenerator.PdfResponse;
  import java.util.List;

  List<PdfResponse> pdfs = client.v1().pdfGenerator().getAll();

  for (PdfResponse pdf : pdfs) {
      System.out.println(pdf.topic() + " - " + pdf.createdAt());
      System.out.println("ID: " + pdf._id());
      System.out.println("Slides: " + pdf.numberOfSlides());
  }
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.PdfGenerator;
  using StudyfetchSDK.Models.V1.PdfGenerator.Get;
  using System;
  using System.Threading.Tasks;

  public class GetAllPdfs
  {
      public static async Task GetAll()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          var pdfs = await client.V1.PdfGenerator.GetAll();

          foreach (var pdf in pdfs)
          {
              Console.WriteLine($"{pdf.Topic} - {pdf.CreatedAt}");
              Console.WriteLine($"ID: {pdf._ID}");
              Console.WriteLine($"Slides: {pdf.NumberOfSlides}");
          }
      }
  }
  ```
</CodeGroup>

## Get PDF by ID

Retrieve details of a specific PDF presentation.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const pdfId = 'pdf_123abc';
  const pdf = await client.v1.pdfGenerator.getById({
    id: pdfId
  });

  console.log('Topic:', pdf.topic);
  console.log('Created:', pdf.createdAt);
  console.log('ID:', pdf._id);
  console.log('Slides:', pdf.numberOfSlides);
  console.log('Locale:', pdf.locale);
  ```

  ```python Python theme={null}
  pdf_id = "pdf_123abc"
  pdf = client.v1.pdf_generator.get_by_id({
      "id": pdf_id
  })

  print(f"Topic: {pdf.topic}")
  print(f"Created: {pdf.created_at}")
  print(f"ID: {pdf._id}")
  print(f"Slides: {pdf.number_of_slides}")
  print(f"Locale: {pdf.locale}")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.models.v1.pdfgenerator.PdfGeneratorGetByIdParams;
  import com.studyfetch.javasdk.models.v1.pdfgenerator.PdfResponse;

  String pdfId = "pdf_123abc";
  PdfGeneratorGetByIdParams params = PdfGeneratorGetByIdParams.builder()
      .id(pdfId)
      .build();

  PdfResponse pdf = client.v1().pdfGenerator().getById(params);

  System.out.println("Topic: " + pdf.topic());
  System.out.println("Created: " + pdf.createdAt());
  System.out.println("ID: " + pdf._id());
  System.out.println("Slides: " + pdf.numberOfSlides());
  System.out.println("Locale: " + pdf.locale());
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.PdfGenerator;
  using StudyfetchSDK.Models.V1.PdfGenerator.Get;
  using System;
  using System.Threading.Tasks;

  public class GetPdfById
  {
      public static async Task GetById()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          string pdfId = "pdf_123abc";
          var pdf = await client.V1.PdfGenerator.GetByID(new()
          {
              ID = pdfId
          });

          Console.WriteLine($"Topic: {pdf.Topic}");
          Console.WriteLine($"Created: {pdf.CreatedAt}");
          Console.WriteLine($"ID: {pdf._ID}");
          Console.WriteLine($"Slides: {pdf.NumberOfSlides}");
          Console.WriteLine($"Locale: {pdf.Locale}");
      }
  }
  ```
</CodeGroup>

## Delete PDF

Delete a PDF presentation.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const pdfId = 'pdf_123abc';
  const response = await client.v1.pdfGenerator.delete({
    id: pdfId
  });

  console.log('PDF deleted:', response.success);
  ```

  ```python Python theme={null}
  pdf_id = "pdf_123abc"
  response = client.v1.pdf_generator.delete({
      "id": pdf_id
  })

  print(f"PDF deleted: {response.success}")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.models.v1.pdfgenerator.PdfGeneratorDeleteParams;
  import com.studyfetch.javasdk.models.v1.pdfgenerator.PdfGeneratorDeleteResponse;

  String pdfId = "pdf_123abc";
  PdfGeneratorDeleteParams params = PdfGeneratorDeleteParams.builder()
      .id(pdfId)
      .build();

  PdfGeneratorDeleteResponse response = client.v1().pdfGenerator().delete(params);

  System.out.println("PDF deleted: " + response.success());
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.PdfGenerator;
  using System;
  using System.Threading.Tasks;

  public class DeletePdf
  {
      public static async Task Delete()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          string pdfId = "pdf_123abc";
          var response = await client.V1.PdfGenerator.Delete(new()
          {
              ID = pdfId
          });

          Console.WriteLine($"PDF deleted: {response.Success}");
      }
  }
  ```
</CodeGroup>

## Complete Example

Here's a complete example that creates a PDF presentation and retrieves its details:

<CodeGroup>
  ```javascript JavaScript theme={null}
  import StudyfetchSDK from '@studyfetch/sdk';
  import fs from 'fs';
  import https from 'https';

  async function createAndCheckPdf() {
    const client = new StudyfetchSDK({
      apiKey: process.env.STUDYFETCH_API_KEY,
      baseURL: 'https://studyfetchapi.com',
    });

    // 1. Create PDF presentation
    const pdfResponse = await client.v1.pdfGenerator.create({
      topic: 'Complete Biology Study Guide',
      numberOfSlides: 15,
      locale: 'en'
    });

    console.log('PDF created:', pdfResponse.presentation?._id);
    console.log('Success:', pdfResponse.success);

    // 2. Check the created presentation
    if (pdfResponse.presentation) {
      const pdf = await client.v1.pdfGenerator.getById({ 
        id: pdfResponse.presentation._id 
      });
      
      console.log('Presentation details:');
      console.log('- Topic:', pdf.topic);
      console.log('- Slides:', pdf.numberOfSlides);
      console.log('- Locale:', pdf.locale);
    }
  }

  createAndCheckPdf();
  ```

  ```python Python theme={null}
  import time
  import requests
  from studyfetch_sdk import StudyfetchSDK

  def create_and_check_pdf():
      client = StudyfetchSDK(
          api_key=os.environ.get("STUDYFETCH_API_KEY"),
          base_url="https://studyfetchapi.com",
      )

      # 1. Create PDF presentation
      pdf_response = client.v1.pdf_generator.create({
          "topic": "Complete Biology Study Guide",
          "number_of_slides": 15,
          "locale": "en"
      })

      print(f"PDF created: {pdf_response.id}")

      # 2. Wait for processing to complete
      pdf = client.v1.pdf_generator.get_by_id({"id": pdf_response.id})
      while pdf.status == "processing":
          time.sleep(2)
          pdf = client.v1.pdf_generator.get_by_id({"id": pdf_response.id})

      if pdf.status == "completed":
          print(f"PDF ready for download: {pdf.download_url}")
          
          # 3. Download the PDF
          response = requests.get(pdf.download_url)
          with open("study-guide.pdf", "wb") as f:
              f.write(response.content)
          print("PDF downloaded successfully")
      else:
          print("PDF generation failed")

  create_and_check_pdf()
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.pdfgenerator.*;
  import java.io.*;
  import java.net.URL;
  import java.nio.file.*;
  import java.util.List;

  public class CreateAndCheckPdf {
      public static void main(String[] args) throws Exception {
          StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
              .apiKey(System.getenv("STUDYFETCH_API_KEY"))
              .baseUrl("https://studyfetchapi.com")
              .build();

          // 1. Create PDF presentation
          PdfGeneratorCreateParams createParams = PdfGeneratorCreateParams.builder()
              .topic("Complete Biology Study Guide")
              .numberOfSlides(15)
              .locale("en")
              .build();

          PdfGeneratorCreateResponse pdfResponse = client.v1().pdfGenerator().create(createParams);
          System.out.println("PDF created: " + pdfResponse.id());

          // 2. Wait for processing to complete
          PdfResponse pdf = client.v1().pdfGenerator().getById(
              PdfGeneratorGetByIdParams.builder().id(pdfResponse.id()).build()
          );
          
          while ("processing".equals(pdf.status())) {
              Thread.sleep(2000);
              pdf = client.v1().pdfGenerator().getById(
                  PdfGeneratorGetByIdParams.builder().id(pdfResponse.id()).build()
              );
          }

          if ("completed".equals(pdf.status())) {
              System.out.println("PDF ready for download: " + pdf.downloadUrl());
              
              // 3. Download the PDF
              try (InputStream in = new URL(pdf.downloadUrl()).openStream()) {
                  Files.copy(in, Paths.get("study-guide.pdf"), 
                      StandardCopyOption.REPLACE_EXISTING);
              }
              System.out.println("PDF downloaded successfully");
          } else {
              System.err.println("PDF generation failed");
          }
      }
  }
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.PdfGenerator;
  using StudyfetchSDK.Models.V1.PdfGenerator.Get;
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Net.Http;
  using System.Threading;
  using System.Threading.Tasks;

  public class CreateAndCheckPdf
  {
      public static async Task Main()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          // 1. Create PDF presentation
          var pdfResponse = await client.V1.PdfGenerator.Create(new()
          {
              Topic = "Complete Biology Study Guide",
              NumberOfSlides = 15,
              Locale = "en"
          });

          Console.WriteLine($"PDF created: {pdfResponse.Presentation?._ID}");

          // 2. Check the created presentation
          if (pdfResponse.Presentation != null)
          {
              var pdf = await client.V1.PdfGenerator.GetByID(new() { 
                  ID = pdfResponse.Presentation._ID 
              });
              
              Console.WriteLine("Presentation details:");
              Console.WriteLine($"- Topic: {pdf.Topic}");
              Console.WriteLine($"- Slides: {pdf.NumberOfSlides}");
              Console.WriteLine($"- Locale: {pdf.Locale}");
          }
      }
  }
  ```
</CodeGroup>
