diff --git a/pom.xml b/pom.xml
index e10310f..7dcd738 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.github.moritzfl
mathematicallatexhelper
- 2.2.0.0
+ 2.2.1.0
mathematicallatexhelper
3
diff --git a/src/main/java/de/moritzf/latexhelper/Export.java b/src/main/java/de/moritzf/latexhelper/Export.java
index 28c9e71..7126828 100644
--- a/src/main/java/de/moritzf/latexhelper/Export.java
+++ b/src/main/java/de/moritzf/latexhelper/Export.java
@@ -15,6 +15,7 @@
import java.awt.*;
+import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
@@ -32,14 +33,17 @@
import javax.swing.filechooser.FileSystemView;
-import com.itextpdf.text.Document;
-import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.*;
import de.moritzf.latexhelper.util.SteganographyUtil;
+import gutenberg.itext.Emitter;
import gutenberg.itext.ITextContext;
import gutenberg.itext.PygmentsAdapter;
import gutenberg.itext.Styles;
+import gutenberg.itext.emitter.RichTextEmitter;
import gutenberg.itext.emitter.SourceCodeLaTeXExtension;
+import gutenberg.itext.model.Markdown;
+import gutenberg.itext.model.RichText;
import gutenberg.itext.model.SourceCode;
import gutenberg.pygments.Pygments;
import gutenberg.pygments.styles.DefaultStyle;
@@ -161,8 +165,17 @@ private static void generatePdf(String expression, File file) throws IOException
SourceCodeLaTeXExtension extension = new SourceCodeLaTeXExtension(pygmentsAdapter);
SourceCode sourceCode = new SourceCode("latex", expression);
+ com.itextpdf.text.Font font = new com.itextpdf.text.Font();
+ font.setColor(BaseColor.WHITE);
+ font.setSize(0.001f);
+ Chunk chunk = new Chunk("\\##latex##\\" + expression + "\\##latex##\\");
+ chunk.setFont(font);
+
+ document.add(chunk);
+
extension.emit(sourceCode, iTextContext);
- iTextContext.getDocument().addHeader("latex", expression);
+ document.addHeader("latex", expression);
+
iTextContext.close();
} catch (DocumentException e) {
diff --git a/src/main/java/de/moritzf/latexhelper/LatexImportingTextArea.java b/src/main/java/de/moritzf/latexhelper/LatexImportingTextArea.java
index 5fbbba9..c38ecb7 100644
--- a/src/main/java/de/moritzf/latexhelper/LatexImportingTextArea.java
+++ b/src/main/java/de/moritzf/latexhelper/LatexImportingTextArea.java
@@ -2,6 +2,7 @@
import com.itextpdf.text.pdf.PdfReader;
+import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import de.moritzf.latexhelper.util.ImageFileUtil;
import de.moritzf.latexhelper.util.SteganographyUtil;
import mathpix.MathPix;
@@ -30,6 +31,8 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Text area that can work with images that have content hidden by steganography. If such content is detected, it
@@ -124,6 +127,16 @@ private String extractFromPdf(File pdfFile) {
try {
reader = new PdfReader(pdfFile.getAbsolutePath());
latex = reader.getInfo().get("latex");
+ if (latex == null || latex.isEmpty()) {
+ String text = PdfTextExtractor.getTextFromPage(reader, 1);
+ LOGGER.log(Level.INFO, text);
+ Pattern pattern = Pattern.compile("\\\\##latex##\\\\(?.*)\\\\##latex##\\\\");
+ Matcher matcher = pattern.matcher(text);
+ if (matcher.find()) {
+ latex = matcher.group("latex");
+ }
+
+ }
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Could not read pdf. Perhaps the file used was not a valid pdf file.");
}