Skip to content

Generate a thumbnail version of the document #2255

@dadoonet

Description

@dadoonet

We could try to use an external API such as https://jina.ai/reader/:

curl "https://r.jina.ai/" \
  -H "Content-Type: application/json" \
  -H "X-Return-Format: screenshot" \
  -d @- <<EOFEOF
  {
    "url": "https://www.google.com",
    "pdf": "<BASE_64_OF_YOUR_PDF_FILE>"
  }
EOFEOF

Or in Java, something like:

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class CurlToJava {
    public static void main(String[] args) {
        String urlString = "https://r.jina.ai/";
        String jsonInputString = "{"
                + "\"url\": \"https://www.example.com\","
                + "\"pdf\": \"<BASE_64_OF_YOUR_PDF_FILE>\""
                + "}";

        try {
            URL url = new URL(urlString);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("X-Return-Format", "screenshot");
            connection.setDoOutput(true);

            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes("utf-8");
                os.write(input, 0, input.length);
            }

            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);
            // Optionally handle the response here...

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Or get a specific page:

curl 'https://r.jina.ai/' -XPOST -F 'file=@FILE_PATH' -F 'url=blob:_#2' -H 'x-return-format: screenshot'

Or use a similar approach of https://github.com/btimby/thumbnailer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions