Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Think about Loose Coupling
 
PerlMonks  

Re^3: perl script to convert xml to pdf

by roboticus (Canon)
on Oct 20, 2011 at 10:54 UTC ( #932621=note: print w/ replies, xml ) Need Help??


in reply to Re^2: perl script to convert xml to pdf
in thread perl script to convert xml to pdf

veerubiji:

Yes, that's exactly what it does. You didn't specify *any* requirements on the output, so I did the minimum I could to satisfy them. Of course, PerlMonks isn't a code writing service, so had you put any nontrivial requirements in, I probably would have passed over this thread.

In any case, I can't imagine that there's a "general purpose XML to PDF" procedure that would be useful, as there are myriad forms of XML documents, and even more ways to present the data. So you're going to have to get more detailed requirements from your user(s), and figure out how to turn them into code.

First you must figure out what you want:

  1. Get to know the XML data you've got as input. (What elements are there? What are the rules specifying when an element is present or absent? What types of data and/or attributes can/will exist?)
  2. Figure out what you want the output to look like (Here you need to determine formatting, spacing, and everything else. Which elements indicate the start of a new page? Which elements need bold/underline/italics/colored text/background? Which sections are formatted as tables? Which as plaintext? etc.).
  3. Then figure out how to transform bits of your input to bits of your output. (For example: <FROB> element introduces a table where <Gragnar> introduces a row and <Plook> indicates a data cell. If the Plook element has an attribute="snog", then add a red background, otherwise use blue. The first row is a header which we ..... etc.)

Now that you know what sorts of transformations you need to perform, you need to:

  1. Read the XML document (using your favorite XML parser),
  2. Perform the transformations you figured out (you can use XSLT, perl, or whatever),
  3. Then write the transformed bits to the PDF pages.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


Comment on Re^3: perl script to convert xml to pdf
Download Code
Re^4: perl script to convert xml to pdf
by veerubiji (Sexton) on Oct 20, 2011 at 12:11 UTC

    hi please can you provide any example for me because I am very new to this type of concepts and I am very beginner to Perl. I have XMl data like above question ,I need to print in pdf file like this

    student number: 24 address: house number="128", street name= "xxxx", studeent number: 26 address: house number="179", street name= "xxxx",

      veerubiji:

      Sorry, I can't. The example I gave you earlier is the first time I've ever created a PDF document using PDF::API2. I just read the first page of the documentation, and slapped something together afterwards. It's pretty easy, so give it a try.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-04-17 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls