Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: perl script to convert xml to pdf

by veerubiji (Sexton)
on Oct 20, 2011 at 09:48 UTC ( #932601=note: print w/ replies, xml ) Need Help??


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

Hi, Thanks for your reply I understand your code and I executed, its generating pdf with input xml data as I posted in the question. It printing XML data as it is in pdf. just like dumping. If I want to print XML data more readable in pdf. not like XMl data as it is. what should I do.


Comment on Re^2: perl script to convert xml to pdf
Re^3: perl script to convert xml to pdf
by roboticus (Canon) on Oct 20, 2011 at 10:54 UTC

    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.

      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://932601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-09-22 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (208 votes), past polls