Skip to main content
Participating Frequently
October 23, 2017
Question

Help with PDF and Image importing via XML

  • October 23, 2017
  • 3 replies
  • 2330 views

Hello everyone,

I need some help with auto importing XML generated from a custom database?

I am very new to this and no expert so please go easy on me.

I am trying to import and place text, graphic, and PDF documents from one XML script into my InDesign CS5 application.

I have it working fine for just Jpeg image files, but as soon as the XML finds a PDF in the script, it comes up with all sorts of formatting errors and the import of data does not work.

What I am asking is the following...

- Is there is a way to auto place a PDF from XML script?

- If so, will this then work with a multi page PDF?

    This topic has been closed for replies.

    3 replies

    Kasyan Servetsky
    Legend
    October 24, 2017

    P.S. Are you able to place the PDFs manually? Probably they were created in a newer version which CS5 doesn't recognize, or damaged (e.g. while being downloaded from internet).

    Participating Frequently
    October 24, 2017

    My goodness! What a wonderful answer, Kas!

    Thank you so much for going to so much trouble and staying up so late.

    I have been trying to achieve the automatic import of multi page PDFs along with the text and the JPEGs.

    We managed to get the first page of multi-page PDFs to import automatically but not all the other pages of each and every PDF.

    I created the PDFs myself using my own scanners so they should all be fine (i.e. not corrupted).

    We found that there is a JavaScript script within InDesign CS5 (Window/Utilities/Scripts/PlaceMultipagePDF.jsx) for multi-page PDFs but we have not yet tried to work this into our Export XML script.

    We also had 2 items checked on the Import Options ("Clone repeating Text elements", as there are many text elements, and "Do not import contents of whitespace elements", as these had caused the Import to error).

    I will ask my two consultants (one an expert in coding and the other very good at InDesign) to see whether we can gain any help from all that you have so kindly sent us.

    What we are trying to do is to import a whole load of very structured but non-formatted text, photos and scanned documents into InDesign in order to do all of the formatting of our "Book" there.

    It is therefore very important for us to get all of the pages of the PDF into InDesign in one go and then be able to move them around and resize them easily.

    Otherwise, we would have to find and place the PDFs "manually" (i.e. not using a script) and this would be very time-consuming and especially so if the contents of the Book keep on changing (in the database, that holds all of the text, photos and scans prior to Export). This is why we want to get the XML export and import "just right".

    Kasyan Servetsky
    Legend
    October 24, 2017

    I have been trying to achieve the automatic import of multi page PDFs...

    It is therefore very important for us to get all of the pages of the PDF into InDesign in one go...

    No, it's impossible to do while the xml-file is being imported in one step.

    When you're importing a pdf manually, you can choose only one page and then, after placing, you can't change it. The same happens if you do this by script. So, you have to do this in two steps: maybe you'll be able to combine them into one script so for the user it would look like 'one go'.

    If I were you, I'd use the following approach:

    1. Right after placing the xml-file which results in only the first page placed ...

    ... for each pdf (or an xml element associated with pdf), place the next page until all the pages are placed.

    2. Then add it to the xml structure right after the 1st page element applying the file tag.

    3. Finally, make it anchored object. Manually I shift-dragged  it into the frame below the 1st page image to make it inline (you may want another option depending on your layout).

    I did this manually so it's possible to do by script.

    — Kas

    Kasyan Servetsky
    Legend
    October 23, 2017

    I've been writing scripts for InDesign since 2004, but here from you I hear about 'XML scripts' for the first time.

    As far as I know, Indy supports three scripting languages:

    1. JavaScript
    2. AppleScript
    3. Visual Basic

    Did you mean JavaScript (the most popular one)? If so, yes it's possible and here's the MultiPageImporter script. The code is open so you can see how it's done.

    — Kas

    Participating Frequently
    October 23, 2017

    Thank you so much for answering, Kasyan.

    The script produces an XML Export from the database: this contains a mixture of non-formatted text and (JPEG and PDF) files.


    We can get the text and image to import successfully, into InDesign CS5, however, when InDesign reads the XML, it throws back a formatting error. (something like "Bad Format: Line 10, Column 93")  I assume this because it cannot identify the .PDF file extension to place the content correctly within the frame using XML tags.

    Kasyan Servetsky
    Legend
    October 23, 2017

    I am afraid I can't help you here. I had experience in making scripts for working with XML in InDesign: placing, manipulating (mostly with xml-rules), exporting, etc. Also, I did some scripts using the XML Object. However, I have no experience with databases at all.

    I suggest you to post your question in the scripting forum providing more details: maybe relative code snippets and screenshots.

    — Kas

    deano1121
    Participant
    October 23, 2017

    Let me know if you find an answer for this.