You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "rawatsaurav01 (via GitHub)" <gi...@apache.org> on 2024/02/03 06:22:19 UTC

[PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

rawatsaurav01 opened a new pull request, #180:
URL: https://github.com/apache/pdfbox/pull/180

   
   Propose the addition of native Markdown extraction support in Apache PDFBox to simplify the conversion of PDF content to Markdown, eliminating the need for intermediate HTML conversion.
   
   **Description:**
   Currently, Apache PDFBox supports HTML extraction through `PdfText2HTML`. However, this requires an extra step of converting HTML to Markdown using external tools like CopyDown. To enhance efficiency, we suggest incorporating native Markdown extraction support within Apache PDFBox.**Sample Code Comparison:**
   
   **Current Process:**
   
   ```java
   File pdfFile = new File("sample/sample.pdf");
   File mdFile = new File("sample/sample.md");PDFText2HTML pdfText2HTML = new PDFText2HTML();
   CopyDown copyDown = new CopyDown();try (PDDocument pdDocument = Loader.loadPDF(pdfFile)) {
       Files.writeString(mdFile.toPath(), copyDown.convert(pdfText2HTML.getText(pdDocument)));
   }
   
   **Proposed Process:**
   ```java
   File pdfFile = new File("sample/sample.pdf");
   File mdFile = new File("sample/sample.md");PDFText2Markdown pdfText2Markdown = new PDFText2Markdown();try (PDDocument pdDocument = Loader.loadPDF(pdfFile)) {
       Files.writeString(mdFile.toPath(), pdfText2Markdown.getText(pdDocument));
   }
   
   **Benefits:**
   1. **Streamlined Workflow:** Direct PDF to Markdown conversion without relying on external tools.
   2. **Performance Improvement:** Reduced resource consumption, especially for large PDF files.
   3. **Enhanced User Experience:** Aligns with common use cases, improving overall usability.
   
   **Proposed Changes:**
   Introduce `PDFText2Markdown` in Apache PDFBox to provide native Markdown extraction.
   
   **Compatibility:**
   Ensure backward compatibility with existing PDFBox functionalities while seamlessly adding Markdown extraction.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1943386485

   Thank you @rawatsaurav01 I committed to the trunk with some minor changes. I'll commit to 3.0 and 2.0 later.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "rawatsaurav01 (via GitHub)" <gi...@apache.org>.
rawatsaurav01 commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1938036985

   @lehmi @THausherr Thanks a lot for your encouraging comments . I have encorporated the changes. Please review and let me know if some changes required.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1956613451

   Thank you, I've simplified this and committed it. If there isn't any further input then I'll commit to versions 2 and 3 in a few days.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "lehmi (via GitHub)" <gi...@apache.org>.
lehmi commented on code in PR #180:
URL: https://github.com/apache/pdfbox/pull/180#discussion_r1477059126


##########
tools/src/main/java/org/apache/pdfbox/tools/PDFText2Markdown.java:
##########
@@ -0,0 +1,375 @@
+//package com.pdfexample;
+
+package org.apache.pdfbox.tools;
+
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
+import org.apache.pdfbox.text.PDFTextStripper;
+import org.apache.pdfbox.text.TextPosition;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * Wrap stripped text in simple HTML, trying to form HTML paragraphs. Paragraphs
+ * broken by pages, columns, or figures are not mended.
+ *
+ * @author John J Barton
+ *
+ */
+public class PDFText2Markdown extends PDFTextStripper{
+    private static final int INITIAL_PDF_TO_HTML_BYTES = 8192;
+
+    private final FontState fontState = new FontState();
+    /**
+     * Constructor.
+     * @throws IOException If there is an error during initialization.
+     */
+    public PDFText2Markdown() throws IOException
+    {
+        setLineSeparator(LINE_SEPARATOR);
+        setParagraphStart(LINE_SEPARATOR);
+        setParagraphEnd(LINE_SEPARATOR);
+        setPageStart(LINE_SEPARATOR);
+        setPageEnd(LINE_SEPARATOR);
+        setArticleStart(LINE_SEPARATOR);
+        setArticleEnd(LINE_SEPARATOR);
+    }
+
+    @Override
+    protected void startDocument(PDDocument document) throws IOException
+    {
+        StringBuilder buf = new StringBuilder(INITIAL_PDF_TO_HTML_BYTES);
+
+        super.writeString(buf.toString());
+    }

Review Comment:
   IMHO, this doesn't make sense. The used StringBuilder is empty so that nothing is written at all.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "lehmi (via GitHub)" <gi...@apache.org>.
lehmi commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1925309963

   @rawatsaurav01 thanks for the contribution.  I've added some comments to your code and here are some more
   
   * add a apache license header to the file
   * remove/replace all HTML related comments/javadocs
   * remove commented code


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1944051450

   Sonar found a missing break in appendEscaped() which is no big deal, but then I realized that some of the code isn't needed. At the same some needed code should be added, i.e. handling of special characters like "*". See also 
   https://shadocs.netlify.app/markdown/escaping_character/


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "johmue (via GitHub)" <gi...@apache.org>.
johmue commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-2447855397

   @THausherr @rawatsaurav01 This is really helpful, especially now with LLMs trained on MarkDown formatted documents. Would it be a big effort to expose this option in the PDFBox App with a dedicated SubCommand i.e. `export:md` or with `export:text -md` (similar to -html)?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "rawatsaurav01 (via GitHub)" <gi...@apache.org>.
rawatsaurav01 commented on code in PR #180:
URL: https://github.com/apache/pdfbox/pull/180#discussion_r1485735631


##########
tools/src/main/java/org/apache/pdfbox/tools/PDFText2Markdown.java:
##########
@@ -0,0 +1,375 @@
+//package com.pdfexample;
+
+package org.apache.pdfbox.tools;
+
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
+import org.apache.pdfbox.text.PDFTextStripper;
+import org.apache.pdfbox.text.TextPosition;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * Wrap stripped text in simple HTML, trying to form HTML paragraphs. Paragraphs
+ * broken by pages, columns, or figures are not mended.
+ *
+ * @author John J Barton
+ *
+ */
+public class PDFText2Markdown extends PDFTextStripper{
+    private static final int INITIAL_PDF_TO_HTML_BYTES = 8192;
+
+    private final FontState fontState = new FontState();
+    /**
+     * Constructor.
+     * @throws IOException If there is an error during initialization.
+     */
+    public PDFText2Markdown() throws IOException
+    {
+        setLineSeparator(LINE_SEPARATOR);
+        setParagraphStart(LINE_SEPARATOR);
+        setParagraphEnd(LINE_SEPARATOR);
+        setPageStart(LINE_SEPARATOR);
+        setPageEnd(LINE_SEPARATOR);
+        setArticleStart(LINE_SEPARATOR);
+        setArticleEnd(LINE_SEPARATOR);
+    }
+
+    @Override
+    protected void startDocument(PDDocument document) throws IOException
+    {
+        StringBuilder buf = new StringBuilder(INITIAL_PDF_TO_HTML_BYTES);
+
+        super.writeString(buf.toString());
+    }

Review Comment:
   @lehmi I have removed line as per the suggestion.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "rawatsaurav01 (via GitHub)" <gi...@apache.org>.
rawatsaurav01 commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1957377183

   Thank you @THausherr for your acknowledgement.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1962396268

   All done in https://issues.apache.org/jira/browse/PDFBOX-5768 .


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1925264378

   Seems like a good idea. @lehmi do we need an ICLA for this one?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "lehmi (via GitHub)" <gi...@apache.org>.
lehmi commented on code in PR #180:
URL: https://github.com/apache/pdfbox/pull/180#discussion_r1477059422


##########
tools/src/main/java/org/apache/pdfbox/tools/PDFText2Markdown.java:
##########
@@ -0,0 +1,375 @@
+//package com.pdfexample;
+
+package org.apache.pdfbox.tools;
+
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
+import org.apache.pdfbox.text.PDFTextStripper;
+import org.apache.pdfbox.text.TextPosition;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * Wrap stripped text in simple HTML, trying to form HTML paragraphs. Paragraphs
+ * broken by pages, columns, or figures are not mended.
+ *
+ * @author John J Barton
+ *
+ */
+public class PDFText2Markdown extends PDFTextStripper{
+    private static final int INITIAL_PDF_TO_HTML_BYTES = 8192;
+
+    private final FontState fontState = new FontState();
+    /**
+     * Constructor.
+     * @throws IOException If there is an error during initialization.
+     */
+    public PDFText2Markdown() throws IOException
+    {
+        setLineSeparator(LINE_SEPARATOR);
+        setParagraphStart(LINE_SEPARATOR);
+        setParagraphEnd(LINE_SEPARATOR);
+        setPageStart(LINE_SEPARATOR);
+        setPageEnd(LINE_SEPARATOR);
+        setArticleStart(LINE_SEPARATOR);
+        setArticleEnd(LINE_SEPARATOR);
+    }
+
+    @Override
+    protected void startDocument(PDDocument document) throws IOException
+    {
+        StringBuilder buf = new StringBuilder(INITIAL_PDF_TO_HTML_BYTES);
+
+        super.writeString(buf.toString());
+    }
+
+
+    /**
+     * This method will attempt to guess the title of the document using
+     * either the document properties or the first lines of text.
+     *
+     * @return returns the title.
+     */
+    protected String getTitle()
+    {
+        String titleGuess = document.getDocumentInformation().getTitle();
+        if(titleGuess != null && titleGuess.length() > 0)
+        {
+            return titleGuess;
+        }
+        else
+        {
+            Iterator<List<TextPosition>> textIter = getCharactersByArticle().iterator();
+            float lastFontSize = -1.0f;
+
+            StringBuilder titleText = new StringBuilder();
+            while (textIter.hasNext())
+            {
+                for (TextPosition position : textIter.next())
+                {
+                    float currentFontSize = position.getFontSize();
+                    //If we're past 64 chars we will assume that we're past the title
+                    //64 is arbitrary
+                    if (Float.compare(currentFontSize, lastFontSize) != 0 || titleText.length() > 64)
+                    {
+                        if (titleText.length() > 0)
+                        {
+                            return titleText.toString();
+                        }
+                        lastFontSize = currentFontSize;
+                    }
+                    if (currentFontSize > 13.0f)
+                    { // most body text is 12pt
+                        titleText.append(position.getUnicode());
+                    }
+                }
+            }
+        }
+        return "";
+    }
+
+
+    /**
+     * Write out the article separator (div tag) with proper text direction
+     * information.
+     *
+     * @param isLTR true if direction of text is left to right
+     * @throws IOException
+     *             If there is an error writing to the stream.
+     */
+    @Override
+    protected void startArticle(boolean isLTR) throws IOException
+    {
+        if (isLTR)
+        {
+            super.writeString(LINE_SEPARATOR);
+        }
+        else
+        {
+            super.writeString(LINE_SEPARATOR);
+        }
+    }
+

Review Comment:
   Both cases are doing the same, so that the if/else can be removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-2448089442

   Yes sounds like a good idea, I'm gonna think about it tomorrow.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "rawatsaurav01 (via GitHub)" <gi...@apache.org>.
rawatsaurav01 commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1943387407

   Thank you @THausherr . 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #180: Enable Native Markdown Extraction in Apache PDFBox
URL: https://github.com/apache/pdfbox/pull/180


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "rawatsaurav01 (via GitHub)" <gi...@apache.org>.
rawatsaurav01 commented on code in PR #180:
URL: https://github.com/apache/pdfbox/pull/180#discussion_r1485735727


##########
tools/src/main/java/org/apache/pdfbox/tools/PDFText2Markdown.java:
##########
@@ -0,0 +1,375 @@
+//package com.pdfexample;
+
+package org.apache.pdfbox.tools;
+
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
+import org.apache.pdfbox.text.PDFTextStripper;
+import org.apache.pdfbox.text.TextPosition;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * Wrap stripped text in simple HTML, trying to form HTML paragraphs. Paragraphs
+ * broken by pages, columns, or figures are not mended.
+ *
+ * @author John J Barton
+ *
+ */
+public class PDFText2Markdown extends PDFTextStripper{
+    private static final int INITIAL_PDF_TO_HTML_BYTES = 8192;
+
+    private final FontState fontState = new FontState();
+    /**
+     * Constructor.
+     * @throws IOException If there is an error during initialization.
+     */
+    public PDFText2Markdown() throws IOException
+    {
+        setLineSeparator(LINE_SEPARATOR);
+        setParagraphStart(LINE_SEPARATOR);
+        setParagraphEnd(LINE_SEPARATOR);
+        setPageStart(LINE_SEPARATOR);
+        setPageEnd(LINE_SEPARATOR);
+        setArticleStart(LINE_SEPARATOR);
+        setArticleEnd(LINE_SEPARATOR);
+    }
+
+    @Override
+    protected void startDocument(PDDocument document) throws IOException
+    {
+        StringBuilder buf = new StringBuilder(INITIAL_PDF_TO_HTML_BYTES);
+
+        super.writeString(buf.toString());
+    }
+
+
+    /**
+     * This method will attempt to guess the title of the document using
+     * either the document properties or the first lines of text.
+     *
+     * @return returns the title.
+     */
+    protected String getTitle()
+    {
+        String titleGuess = document.getDocumentInformation().getTitle();
+        if(titleGuess != null && titleGuess.length() > 0)
+        {
+            return titleGuess;
+        }
+        else
+        {
+            Iterator<List<TextPosition>> textIter = getCharactersByArticle().iterator();
+            float lastFontSize = -1.0f;
+
+            StringBuilder titleText = new StringBuilder();
+            while (textIter.hasNext())
+            {
+                for (TextPosition position : textIter.next())
+                {
+                    float currentFontSize = position.getFontSize();
+                    //If we're past 64 chars we will assume that we're past the title
+                    //64 is arbitrary
+                    if (Float.compare(currentFontSize, lastFontSize) != 0 || titleText.length() > 64)
+                    {
+                        if (titleText.length() > 0)
+                        {
+                            return titleText.toString();
+                        }
+                        lastFontSize = currentFontSize;
+                    }
+                    if (currentFontSize > 13.0f)
+                    { // most body text is 12pt
+                        titleText.append(position.getUnicode());
+                    }
+                }
+            }
+        }
+        return "";
+    }
+
+
+    /**
+     * Write out the article separator (div tag) with proper text direction
+     * information.
+     *
+     * @param isLTR true if direction of text is left to right
+     * @throws IOException
+     *             If there is an error writing to the stream.
+     */
+    @Override
+    protected void startArticle(boolean isLTR) throws IOException
+    {
+        if (isLTR)
+        {
+            super.writeString(LINE_SEPARATOR);
+        }
+        else
+        {
+            super.writeString(LINE_SEPARATOR);
+        }
+    }
+

Review Comment:
   @lehmi Please check I have updated the source code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "rawatsaurav01 (via GitHub)" <gi...@apache.org>.
rawatsaurav01 commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1942054023

   @THausherr I have changed the author name to Axle . Can you please check it now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-2449554749

   Done  https://issues.apache.org/jira/browse/PDFBOX-5895 .
   It will soon be available at
   https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.33-SNAPSHOT/
   https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.4-SNAPSHOT/


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "johmue (via GitHub)" <gi...@apache.org>.
johmue commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-2451809340

   It works and creates good outcomes. Thanks for putting the effort and making it easily available in almost no time. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "lehmi (via GitHub)" <gi...@apache.org>.
lehmi commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1925308317

   @THausherr IMHO it is not needed as the class is more or less a copy of PDFText2HTML


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1951372205

   I don't see any additional commit, either add it or post the code change here. I assume it's in `appendEscaped()`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: [PR] Enable Native Markdown Extraction in Apache PDFBox [pdfbox]

Posted by "rawatsaurav01 (via GitHub)" <gi...@apache.org>.
rawatsaurav01 commented on PR #180:
URL: https://github.com/apache/pdfbox/pull/180#issuecomment-1951624412

   @THausherr I have added and pushed the code ,but it is not showing maybe the pr is closed.Here is the updated code.
   
   private static void appendEscaped(StringBuilder builder, char character) {
   
           switch (character) {
               case '*':
                   builder.append("\\" + character);
                   break;
               case '+':
                   builder.append("\\" + character);
                   break;
               case '-':
                   builder.append("\\" + character);
                   break;
               case '#':
                   builder.append("\\" + character);
                   break;
               case 34:
                   builder.append("\"");
                   break;
               case 38:
                   builder.append("&");
                   break;
               case 39:
                   builder.append("\'");
                   break;
               case 60:
                   builder.append("<");
                   break;
               case 62:
                   builder.append(">");
                   break;
               case 178:
                   builder.append("<sup>2</sup>");
                   break;
               case 179:
                   builder.append("<sup>3</sup>");
                   break;
   
               default:
                   builder.append(character);
                   break;
           }
       }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org