Forum How do I...?

Basic usage - converting docs to PDF

ArturoM
Hi,

I have a small company and I need to convert several .xml docs to PDF documents that my customers can actually read.

I have installed Prince on my Mac and now I'm trying to actually convert documents. I've tried several things but I just don't know what I'm doing wrong. I apologize for my questions being so "basic" but I have very little experience.

If I have a test.xml document on my desktop and I want to convert it to doc1.pdf and save it on my desktop, how should I run the command?

Here's what I've tried:

test.xml -o doc1.pdf


After that nothing seems to happen. Should I place the test.xml file inside the same folder where Prince is installed? Or how should I run the command?

Total newbie going crazy here! Thanks for the help. Regards.

Arturo M.
mikeday
Very close, but you need to actually run Prince:
prince test.xml -o doc1.pdf

If this succeeds, it will create doc1.pdf in the current folder, after which you can move it to the desktop or open it up from the finder. In the UNIX tradition, success is silent and prints no messages, while failure is noisy and prints lots of error messages. :)

If you get an error saying that it can't find "prince", try running /usr/local/bin/prince instead, or replace /usr/local in that command with wherever Prince was installed.

Sorry about all this, the command-line is not very friendly, but we haven't yet had time to create a graphical interface for MacOS X.
ArturoM
Thank you very much for the reply.

I installed Prince inside my home folder on a folder called prince-8.1. So from terminal I run it like this: prince-8.1/bin/prince

Inside the prince-8.1 folder I placed the document called text.xml. So inside that folder I now see the document called text.xml a folder called bin and another folder called lib.

From Terminal I ran:
prince-8.1/bin/prince text.xml -o doc1.pdf


And got this error message:

prince: warning: failed to load external entity "text.xml"
prince: text.xml: error: could not load input file
prince: error: no input documents to process


What am I doing wrong? Should I place the text.xml file elsewhere?

Thank you very much for your patience and for your help!
mikeday
You can place text.xml anywhere, it doesn't need to be copied into the Prince folder. Based on your current arrangement, you would need to run:
prince-8.1/bin/prince prince-8.1/text.xml -o doc1.pdf

If text.xml is in the current folder then you can just say "text.xml". Note that doc1.pdf will be created in the current folder, unless you explicitly give it another path, eg. foo/bar/doc1.pdf.
ArturoM
Thank you very much for your patience and help with this. I've tried a million things.

I tried to place the text.xml file on different locations and ended up with an error message. Here's what I ran from terminal with the text.xml file placed on my home folder (same thing happens if the file in inside the prince-8.1 folder):

prince-8.1/bin/prince text.xml -o doc1.pdf


Here's the error message:

prince: text.xml:2311: error: xmlParseEntityRef: no name
prince: text.xml:2339: error: xmlParseEntityRef: no name
prince: text.xml:2376: error: xmlParseEntityRef: no name
prince: text.xml:2404: error: xmlParseEntityRef: no name
prince: text.xml: error: could not load input file
prince: error: no input documents to process

Thank you very much!
mikeday
This means that on line 2311 there is an invalid entity, probably caused by an unescaped ampersand & character. Is the file actually XML, or HTML?
ArturoM
Ok thank you,

I revised the xml doc and found & characters which I took out. They were present on those lines like this: <Vehicle MRM="0" ModelCode="YF3H9CKNW" VehicleDescription="PILOT 2WD 4dr Wgn Touring w/RES & Navi">. I get the files as xml not HTML.

Could it be a problem with the file itself? I tried attaching the file to this post but the system wouldn't allow .xml nor .txt extensions.

Thanks for the help!!
mikeday
Technically that is not legal XML. The ampersand characters in the attribute need to be escaped as "&amp;" like this:
<Vehicle MRM="0" ModelCode="YF3H9CKNW" VehicleDescription="PILOT 2WD 4dr Wgn Touring w/RES &amp; Navi">

So you make these changes yourself, or ask whoever made the files to ensure that they actually generate well-formed XML.
ArturoM
Ok thanks I understand.

I made the changes myself, ran the command again and the PDF file was finally generated. But it was a blank PDF, only the Prince logo was present.

Does this "blank PDF" mean that the xml is very likely bad-formed?
mikeday
No, it means that the XML probably doesn't contain any text outside of the attributes. What kind of PDF are you trying to generate with this XML? You will need to write some CSS to style the data, but it may be easier to transform the data into appropriate HTML first.
ArturoM
Thanks for the reply.

The XML holds a data about cars: Model, brand, finance rate, specials, finance period, etc. All the info is contained inside this XML, like this for instance:

<Vehicle MRM="0" ModelCode="YF4H7CKNW" VehicleDescription="PILOT 4WD 4dr Wgn EX-L w/Navi">
<Term Residual="58" TermLength="24"/>
<Term Residual="57" TermLength="27"/>
<Term Residual="55" TermLength="30"/>
<Term Residual="53" TermLength="33"/>
<Term Residual="52" TermLength="36"/>
</Vehicle>


The idea is to get this data into a "readable" PDF format so that we don't have to be messing with xml files.
All I have at this point are the xml files in such format.

Thanks for the comments!
mikeday
You can use CSS to extract the text, but I suspect it's going to be easier if you write a little script or transform to convert this to HTML first. This will be easier if you or someone in your organisation is already writing JavaScript, or PHP, or ASP, or Java, or some other language.
ArturoM
Ok Mike,

Thank you very much, I will look into that.

Kindest regards.