summaryrefslogtreecommitdiff
path: root/graphics/latexscreenshooter
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-06-28 03:02:21 +0000
committerNorbert Preining <norbert@preining.info>2024-06-28 03:02:21 +0000
commitdeb5f8017d5c10d779b3897635f50c317c7e5a63 (patch)
treedb18a3b41031074fc93c463a069c4e8dd1a9b8af /graphics/latexscreenshooter
parent5b8e253886fdaa622d831b69a8f791e10d068f23 (diff)
CTAN sync 202406280302
Diffstat (limited to 'graphics/latexscreenshooter')
-rw-r--r--graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter-exemple.tex8
-rw-r--r--graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter.sty32
-rw-r--r--graphics/latexscreenshooter/Code/src/LaTexScreenshooter/LaTeXScreenshooter.java43
-rw-r--r--graphics/latexscreenshooter/Code/src/LaTexScreenshooter/PathValidator.java32
-rw-r--r--graphics/latexscreenshooter/Code/src/LaTexScreenshooter/ScreenShooter.java81
-rw-r--r--graphics/latexscreenshooter/Code/src/LaTexScreenshooter/WaylandScreenshooter.java78
-rw-r--r--graphics/latexscreenshooter/README.md33
-rw-r--r--graphics/latexscreenshooter/latexscreenshooter.pdfbin0 -> 125117 bytes
8 files changed, 307 insertions, 0 deletions
diff --git a/graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter-exemple.tex b/graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter-exemple.tex
new file mode 100644
index 0000000000..fa455d8cac
--- /dev/null
+++ b/graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter-exemple.tex
@@ -0,0 +1,8 @@
+\documentclass{article}
+\usepackage[utf8]{inputenc}
+\usepackage{graphicx}
+\usepackage{screenshooter}
+
+\begin{document}
+ \screenshooter{https://google.com}{420}{262}{screenshot01}{C:/Users/Username/paths}
+\end{document}
diff --git a/graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter.sty b/graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter.sty
new file mode 100644
index 0000000000..19e117e997
--- /dev/null
+++ b/graphics/latexscreenshooter/Code/src-compiled/latexscreenshooter.sty
@@ -0,0 +1,32 @@
+%Authors : quentin.vaney@gmail.com;xavier.freléchoz@gmail.com%
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{screenshooter}[2024/05/06 Package that takes screenshot]
+
+\RequirePackage{graphicx}
+\RequirePackage{catchfile}
+
+\newcommand{\screenshooter}[5]{%
+ \immediate\write18{java -jar latexscreenshooter.jar #1 #2 #3 #4 #5}%
+ \IfFileExists{#5#4.png}{%
+ \begin{center}
+ \includegraphics[width=#2px, height=#3px]{#5#4.png}%
+ \end{center}
+ }{%
+ \IfFileExists{#5/#4.png}{%
+ \begin{center}
+ \includegraphics[width=#2px, height=#3px]{#5/#4.png}%
+ \end{center}
+ }{%
+ \IfFileExists{#4.png}{%
+ \begin{center}
+ \includegraphics[width=#2px, height=#3px]{#4.png}%
+ \end{center}
+ }{%
+ \begin{center}
+ \fbox{\textbf{Image not found}}%
+ \end{center}
+ }%
+ }%
+ }%
+}
+
diff --git a/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/LaTeXScreenshooter.java b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/LaTeXScreenshooter.java
new file mode 100644
index 0000000000..4e5bab08ca
--- /dev/null
+++ b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/LaTeXScreenshooter.java
@@ -0,0 +1,43 @@
+/**
+ * Authors : quentin.vaney@gmail.com;xavier.frelechoz@gmail.com
+ * Version : V1
+ */
+
+package LaTexScreenshooter;
+import java.util.Objects;
+
+public class LaTeXScreenshooter {
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ System.out.println("No arguments were passed.");
+ } else {
+ String url = args[0];
+ int width = args.length > 1 ? Integer.parseInt(args[1]) : 600;
+ int height = args.length > 2 ? Integer.parseInt(args[2]) : 600;
+ String fileName = args.length > 3 ? args[3] : "Screenshot";
+ String path = args.length > 3 ? args[4] : System.getProperty("user.dir");
+
+ String os = System.getProperty("os.name").toLowerCase();
+ String slash = "";
+ if (os.contains("win")) {
+ slash = "\\";
+ } else {
+ slash = "/";
+ }
+
+ if (!path.endsWith("\\") && !path.endsWith("/")) {
+ path = path + slash;
+ }
+
+ path = PathValidator.isPathValid(path) ? path : System.getProperty("user.dir") + slash;
+ System.out.println(path);
+ String sessionType = System.getenv("XDG_SESSION_TYPE");
+ if (Objects.equals(sessionType, "wayland")) {
+ WaylandScreenshooter.captureScreenshot(url, width, height, fileName, path);
+ } else {
+ System.out.println("Unable to determine the session type.");
+ ScreenShooter.captureScreenshot(url, width, height, fileName, path);
+ }
+ }
+ }
+}
diff --git a/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/PathValidator.java b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/PathValidator.java
new file mode 100644
index 0000000000..25bd2adce8
--- /dev/null
+++ b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/PathValidator.java
@@ -0,0 +1,32 @@
+/**
+ * Authors : quentin.vaney@gmail.com;xavier.frelechoz@gmail.com
+ * Version : V1
+ */
+
+package LaTexScreenshooter;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+ public class PathValidator {
+
+ public static boolean isPathValid(String pathString) {
+ try {
+ Path path = Paths.get(pathString);
+ if (Files.exists(path) && Files.isDirectory(path)) {
+ System.out.println("Success: Path is a valid directory.");
+ System.out.println(pathString);
+ return true;
+ } else {
+ System.out.println("Fail: Path exists but is not a directory.");
+ System.out.println(pathString);
+ return false;
+ }
+ } catch (InvalidPathException | NullPointerException ex) {
+ System.out.println("Fail: File path is incorrect.");
+ System.out.println(pathString);
+ return false;
+ }
+ }
+} \ No newline at end of file
diff --git a/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/ScreenShooter.java b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/ScreenShooter.java
new file mode 100644
index 0000000000..2a870f0743
--- /dev/null
+++ b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/ScreenShooter.java
@@ -0,0 +1,81 @@
+/**
+ * Authors : quentin.vaney@gmail.com;xavier.frelechoz@gmail.com
+ * Version : V1
+ */
+
+package LaTexScreenshooter;
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.event.KeyEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+public class ScreenShooter {
+
+ // Method to load a web page in a specified browser
+ private static void loadWebPage(String url) {
+ try {
+ Desktop.getDesktop().browse(new URL(url).toURI());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void closeWebPage(int delay) {
+ try {
+ Thread.sleep(delay);
+ Robot robot = new Robot();
+ robot.keyPress(KeyEvent.VK_CONTROL);
+ robot.keyPress(KeyEvent.VK_W);
+ robot.keyRelease(KeyEvent.VK_CONTROL);
+ robot.keyRelease(KeyEvent.VK_W);
+ } catch (InterruptedException | AWTException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // Method to capture the browser window and save the screenshot
+ public static void captureScreenshot(String url, int width, int height, String fileName, String path) {
+ try {
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ loadWebPage(url);
+
+ // Wait for a certain time for the page to load (adjust as needed)
+ try {
+ Thread.sleep(4000); // Wait for 4 seconds
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ Robot robot = new Robot();
+ Rectangle area = new Rectangle(screenSize.width, screenSize.height);
+ BufferedImage screenshot = robot.createScreenCapture(area);
+ ImageIO.write(screenshot, "png", new File(path + fileName + ".png"));
+ closeWebPage(2000);
+
+ System.out.println("Screenshot saved at: " + path + fileName + ".png");
+ System.out.println("Screenshot saved: " + fileName + ".png");
+ //resizeImage(width, height, fileName);
+ } catch (AWTException | IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void resizeImage(int scaledWidth, int scaledHeight, String fileName) throws IOException {
+ // Read the input image from the specified path
+ File inputFile = new File(System.getProperty("user.dir") + "/" + fileName + ".png");
+ BufferedImage inputImage = ImageIO.read(inputFile);
+
+ // Create a BufferedImage with the new dimensions
+ BufferedImage outputImage = new BufferedImage(scaledWidth, scaledHeight, inputImage.getType());
+
+ // Resize the image
+ Graphics2D graphics2D = outputImage.createGraphics();
+ graphics2D.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
+ graphics2D.dispose();
+
+ // Write the resized image to the specified path
+ ImageIO.write(outputImage, "png", new File(fileName + ".png"));
+ }
+}
diff --git a/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/WaylandScreenshooter.java b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/WaylandScreenshooter.java
new file mode 100644
index 0000000000..09672f2ea1
--- /dev/null
+++ b/graphics/latexscreenshooter/Code/src/LaTexScreenshooter/WaylandScreenshooter.java
@@ -0,0 +1,78 @@
+/**
+ * Authors : quentin.vaney@gmail.com;xavier.frelechoz@gmail.com
+ * Version : V1
+ */
+
+package LaTexScreenshooter;
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.awt.Desktop;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+
+public class WaylandScreenshooter {
+
+ // Opens a URL in the default browser
+ private static void openWebPage(String url) throws IOException {
+ System.out.println("Opening web page: " + url);
+ Desktop.getDesktop().browse(URI.create(url));
+ }
+
+ // Captures the screen and saves the image
+ private static void captureScreenshot(String fileName, String path, String s) throws IOException {
+ System.out.println("Capturing screenshot...");
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ String command = "gnome-screenshot -w -f " + path + fileName + ".png";
+ try {
+ Process process = Runtime.getRuntime().exec(command);
+ process.waitFor();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Screenshot saved at location: " + path + fileName + ".png");
+ }
+
+ // Closes the web page
+ private static void closeWebPage() {
+ System.out.println("Closing web page...");
+ try {
+ Runtime.getRuntime().exec("ydotool key ctrl+w");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Web page closed.");
+ }
+
+ // Captures the screen after opening a web page
+ public static void captureScreenshot(String url, int width, int height, String fileName, String path) {
+ try {
+ openWebPage(url);
+ Thread.sleep(4000); // Wait for 4 seconds for the page to load
+ captureScreenshot(fileName, path, path);
+ closeWebPage();
+ } catch (IOException | InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void resizeImage(int scaledWidth, int scaledHeight, String fileName) throws IOException {
+ // Read the input image from the specified path
+ File inputFile = new File(System.getProperty("user.dir") + "/" + fileName + ".png");
+ BufferedImage inputImage = ImageIO.read(inputFile);
+
+ // Create a BufferedImage with the new dimensions
+ BufferedImage outputImage = new BufferedImage(scaledWidth, scaledHeight, inputImage.getType());
+
+ // Resize the image
+ Graphics2D graphics2D = outputImage.createGraphics();
+ graphics2D.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
+ graphics2D.dispose();
+
+ // Write the resized image to the specified path
+ ImageIO.write(outputImage, "png", new File(fileName + ".png"));
+ }
+}
diff --git a/graphics/latexscreenshooter/README.md b/graphics/latexscreenshooter/README.md
new file mode 100644
index 0000000000..fba8e215a1
--- /dev/null
+++ b/graphics/latexscreenshooter/README.md
@@ -0,0 +1,33 @@
+# LaTeXScreenshooter
+
+## Description
+
+**LaTeXScreenshooter** is a Java-based application designed to capture screenshots of web pages specified within LaTeX documents. It supports both X11 and Wayland display servers, ensuring compatibility across different Linux environments and windows. The project includes several components to validate paths, read LaTeX files, and capture screenshots.
+
+## Location
+
+In the `Code/src-compiled` folder, you can find the `.jar` file, the `.sty` file, and a `.tex` test file that you can use. The `.sty` file is the package that you need to include in your LaTeX document. The `.jar` file is the application that you need to run to take the screenshots.
+
+In the `Code/src` folder, you can find the source code of the project.
+
+## Command .jar
+
+To execute the .jar file directly, open a shell and enter:
+
+`java -jar latexscreenshooter.jar <URL> <WIDTH> <HEIGHT> <NAME> <PATH>`
+
+## License
+
+The project is licensed under the The LaTeX Project Public License 1.3c.
+
+## Futur works
+
+- Allow "!" as in the LaTeX \resizebox command
+- Allow the indication of a path for latexscreenshooter.jar
+- Allow choice of the browser (instead of the system default)
+- Capture only the browser window rather than the entire screen
+- Send the LaTeX-PDF-viewer window to the front of the window stack
+
+## Authors
+
+The authors of the project are Quentin Vaney and Xavier Freléchoz. You can contact us by mail at `quentin.vaney@gmail.com` & `Xavier.freléchoz@gmail.com`
diff --git a/graphics/latexscreenshooter/latexscreenshooter.pdf b/graphics/latexscreenshooter/latexscreenshooter.pdf
new file mode 100644
index 0000000000..cfd4176713
--- /dev/null
+++ b/graphics/latexscreenshooter/latexscreenshooter.pdf
Binary files differ