Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This is my first post so excuse me if I'm breaking any conventions.

Well the thing is I'm developing a long term archive system in Ubuntu environment. For different reasons XML is a very strong format for long term archiving and there are numerous systems on the market today that's offering export functions to the XML format.

The XML format it self contains no graphical information what so ever of how, for instance a PDF-file looked like, just the written information and embedded pics it once contained.

So given I have a certain PDF-file it's possible to strip it down to XML and then rebuilt it once again to the PDF-file it once was - at least in theory.

In Linux you could do this from CLI with the help of XSLTPROC and FOP in two steps.

  1. xsltproc file.xsl file.xml > file.fo
  2. fop file.fo file.pdf

The absolutely crucial file here - if you want to rebuild it just the way it was - is the XSL-file.

I have found hundreds of posts discussing how to create XSL-files by hand but NONE regarding any software that could analyse the XSL-structure of a PDF-file.

I just reckon if it's possible to transform from XML-XSL-FO-PDF it must be possible to do this process backwards? Anyone has any ideas?

Paul

share|improve this question
    
You may also want to try asking in stackoverflow.com, or maybe some other, archival- or document-related stackexchange sub-site, you will get a better answer there as this is not Ubuntu-specific. –  roadmr Aug 20 '12 at 17:47
1  
@roadmr Questions that are not about computer programming should definitely not be asked on stackoverflow.com (see their FAQ). It's possible SuperUser might be a better place to ask about this (or maybe Unix.SE). In any case, though, I think this question is quite on-topic for our site (see our FAQ), and while those other SE sites might get as good answers, I doubt they'd do better. –  Eliah Kagan Aug 21 '12 at 5:58
    
BTW, @PaulBergstrom, if you do decide to post this on another Stack Exchange site, please note that cross-posting is frowned upon, so you should get it deleted or closed here first (or, if you feel the other site is far more appropriate, you could ask moderators to migrate it). –  Eliah Kagan Aug 21 '12 at 5:59

1 Answer 1

PDFs don't store or use XSLT information - they are a completely different markup language format, which does not have a strong division between formatting and content like XML/XSL.

The reason you haven't found any automatic way to convert from a PDF to an XML/XSL is because that would depend heavily on the specific files and formatting being used, and so it would be nearly impossible to write something generic that actually worked.

Your best bet would be to extract the text content from the PDF files using something like pstotext, then write a custom script to build an XML file from that which matches the original. This would essentially be a one-off solution, and would be fairly fragile and prone to breakage.

A better solution would be to just archive the PDFs.

share|improve this answer
    
Thank you for your answer. The main reason to try to solve this is the accumulating size of PDF-files. Say I have 10 000 PDF-files with the same graphical look. They will consume more than 100 times greater disk space than the same files in XML-format. Given I had one correct XSL-file, then all PDF-files would be available on a fraction of disk space. It's also that I find it strange that fop command could format a FO-file to PDF, but it seems impossible for any software to do it the other way around. –  Paul Bergstrom Aug 20 '12 at 17:48
    
@PaulBergstrom: there's nothing strange in the fact that you can convert XML to PDF but not the other way round. Think of a web page and a photo of a monitor displaying that page - it is easy to convert A to B, but converting B to A is almost impossible. XML contains information about document structure, PDF is just a "screenshot", it is not guaranteed it will contain any text information at all - some PDFs contain scanned pages or have characters converted to vector shapes. –  Sergey Aug 20 '12 at 21:08
    
If you have a specific workflow where all PDFs are generated from the same XML template and share the same look, you need to somehow intercept the data while it is still a structured document, before it is converted to PDF. But for a generic PDF archival system the only option is to store PDF files, and maybe store some metadata separately in XML or elsewhere. –  Sergey Aug 20 '12 at 21:12
    
All of you. Many thanks for your answers. –  Paul Bergstrom Aug 22 '12 at 21:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.