I know how make a PDF from LaTeX. Is there a way to extract the LaTeX-code from a PDF I created earlier? How about if someone sends me a PDF and I like the formatting. Can I extract the LaTeX from it?
相关问题
- Correctly parse PDF paragraphs with Python
- Set BaseUrl of an existing Pdf Document
- Library to convert latex to png in Java
- How can I get all text from a PDF in Swift?
- Renaming named destinations in PDF files
相关文章
- Python Sendgrid send email with PDF attachment fil
- C# MVC website PDF file in stored in byte array, d
- How To Programmatically Enable/Disable 'Displa
- How to reduce PDF file size programmatically in Ja
- Search and replace placeholder text in PDF with Py
- ITextSharp 4.1.6. PDF Table - how to remove whites
- Markdown: How to reference an item in a numbered l
- jsPDF justify text
Inkscape can import PDFs and then save as "LaTeX with PSTricks macros" which essentially works by embedding PostScript into the LaTeX source. It's more trouble than its worth, and the resulting Latex source has to be preprocessed before it can be output as a PDF again.
Anyway, even with some hypothetical PDF to LaTeX compiler, at best you'd get something where the position of and size each character or word is separately specified -- the opposite of what you want, which I'm guessing is for a denominator to be one half of a fraction, rather than some number below a horizontal line.
LaTeX does not have a one-to-one conversion to PDF. With regards to your first question, I believe such a conversion may be technically possible, but I do not believe an application to do so yet exists. Similar to the way assembler can be decompiled back into high level language, there is probably a way to do it. However -- a pdf is allowed to contain all matter of kinds of data -- AutoCAD drawings, JPEG graphics, font files, forms, digital signatures, etc. LaTeX has no idea what these things are. So in answer to the second question is no -- there's not a way to extract equivalent LaTeX from any PDF document.
It is possible to convert your PDF to HTML and your HTML to TEX using pdftohtml and gnuhtml2latex.
In effect, you are doing PDF to LaTeX conversion in 2 steps. The result still is like "making a cow out of a hamburger", but in combination with some cleanup scripts the result can be pretty decent.
The blog post "Rudimentary PDF to LaTeX conversion in Linux" on GlobalBlindSpot has an example Bash script that converts a .pdf to a .tex file and that one to a .pdf file again.
The best way for data mining from pdf files (due to its complicated format) is to open them with adobe illustrator. Then convert the pdf file to svg file and use a svg parser library writing some tricky code on yourself.
One efficient svg parser lib is batik
(For Linux it is quite a bit complex for converting pdf to svg: calcmaster.net/personal_projects/pdf2svg/)
PS I've been trying since a lot to find a solution to your second part of your question but I've figured out in books such "Visualizing Data, Ben Fry, O’Reilly" that pdf especially Adobe pdf is to complex to parse, so instead use a svg parser lib.
Short version: No.
Long version: It's a lot like decompiling: You technically could, but it would involve lots of guessing and heuristics.
I'm not familiar with the PDF innards, but it will likely set fonts/sizes/position directly, instead of defining a format and applying it to headers and such, like in LaTeX.
There is a Tool that reads PDF-Files like an OCR and tries to recreate the Latex-Code. It's nearly perfect and called "Infty Reader"! Because Latex is quite extensible I don't think it get's all the neat formats right.