Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Review request for PDF::API2 Tutorial

by BigLug (Chaplain)
on Aug 17, 2004 at 04:05 UTC ( #383548=perlmeditation: print w/ replies, xml ) Need Help??

Fellow monks,
Some time ago I promised to write a tutorial on PDF::API2. Since then I've suffered from a severe lack of tuits -- especially round ones! But finally I found enough and now I'm posting here (before it's finished) in order to get some feedback on the direction/format of the tutorial.

If you've time, please take a look at my work to date. I've elected to use the tried-and-true explaination-of-a-working-script method of tutoring. Does that work well for you?

The tutorial is not meant as a manual for the modules, but is meant to show how do do all the basic things.

Take a look at the tutorial as it stands at the moment and leave your comments below.

Sorry that it's offsite but it contains images and formatting that aren't quite possible on PM. Once I've written it, I might have a go at reformatting it for PM. Thanks and Cheers! Rick

If this is a root node: Before responding, please ensure your clue bit is set.
If this is a reply: This is a discussion group, not a helpdesk. You post something, we discuss its implications. If the discussion happens to answer a question you've asked, that's incidental.

Comment on Review request for PDF::API2 Tutorial
Re: Review request for PDF::API2 Tutorial
by graff (Chancellor) on Aug 17, 2004 at 06:22 UTC
    I realize this is probably something beyond your control, but the version dependency of the tutorial comes across as a rather a serious deficit -- this quote from the fourth paragraph makes it sound like you are providing instructions with a very short life-span:
    This document refers to version 0.03.77 of PDF::API2. If you have an older version, I recommend that you upgrade. It may still work, but I'm not guaranteeing it. If you've downloaded version 0.40 or greater you should be aware that it is only a developer release and that the API has changed considerably. This tutorial is guaranteed not to work with version 0.40+.
    (emphasis in the original)

    Apart from that, I'd feel better about the example code if it included "use strict" and "use warnings". I wanted to check that out for myself, but when I followed the link labeled "You can download the source code here: pdf_api2_tutorial_1.pl.txt", I got a page that said "We can't find your document... We've just upgraded our website and have moved things around..." (seems like your source code may have been "moved" into oblivion).

    Minor nit-picks: You open a file named "$0.pdf" -- that's probably not a good idea, because $0 can (often will) include the path along with the script name (i.e. where the script itself is located in the file system, which might not be the CWD, and/or might not be write-accessible to the user). Also, I couldn't tell where, or whether, you were checking for failure to open or write the output file. Does the module handle that for you, and if so, what is the best/easiest/safest way for the module user to handle its behavior on failure? (Your sample code should show how to do that.)

    It's obvious that the part at the end is "under construction", which makes the "conclusion" of the tutorial a bit of a puzzle, but for the part that is fleshed out, I think it looks very clear and nicely organized -- I actually know next to nothing about creating pdf content from scratch, and your tutorial (what there is of it) leads me to believe that I could learn in very short time how to use this module to good advantage (provided I start with the particular release that you are writing about ;). To me, that's the mark of true success in a tutorial, and you are definitely on the right track in terms of approach.

    Regarding the content of the example text for the pdf page... um, why in Latin?

      Graff!

      Thanks for your excellent feedback.

      the version dependency of the tutorial comes across as a rather a serious deficit
      Unfortunately the version requirement has nothing to do with me. Version 0.4 of the module will have a new API which the developer hasn't settled yet. Once he has, it should just be a case of replacing the code.

      I'd feel better about the example code if it included "use strict" and "use warnings"
      You're right, I should have both strict and warnings in there.

      a file named "$0.pdf" -- that's probably not a good idea
      I'll take that under advisement and probably change it.
      checking for failure to open or write the output file
      Another excellent point. I have never thought to handle it and I've never had it fail to write in my main project. I'd better do some research, document it in the tutorial and then fix the application here at work!!
      your tutorial ... leads me to believe that I could learn in very short time how to use this module
      Excellent! That's the aim, so I'm pleased to hear it.
      Regarding the content of the example text for the pdf page... um, why in Latin?
      It's a typographic convention for when the text doesn't matter. (And it's not quite in latin -- it just looks like it is) See: lorem ipsum
      If this is a root node: Before responding, please ensure your clue bit is set.
      If this is a reply: This is a discussion group, not a helpdesk ... If the discussion happens to answer a question you've asked, that's incidental.
Re: Review request for PDF::API2 Tutorial
by ctilmes (Priest) on Aug 17, 2004 at 11:34 UTC
    I would take your text_block() subroutine, and either submit it to the PDF::API2 author for inclusion in that module, or submit it to CPAN as "PDF::API2::TextBlock" or some such.

    That would give it wider exposure, put it under real version control, provide a central place for storing/updating it, etc. (all the advantages of CPAN.)

    It would also simplify your tutorial, since you can concentrate on the use of the subroutine rather than its internals.

      The tutorial won't actually cover the text_block subroutine, just like it doesn't cover the bit between lines 10 and 30 :)

      I might put it on CPAN though, not a bad idea.


      If this is a root node: Before responding, please ensure your clue bit is set.
      If this is a reply: This is a discussion group, not a helpdesk ... If the discussion happens to answer a question you've asked, that's incidental.
Re: Review request for PDF::API2 Tutorial
by clscott (Friar) on Aug 17, 2004 at 14:00 UTC

    I've been wanting a tutorial like this for generating PDFs. This is fanastic, and easy to understand thank you

    I really like the part where you explain the co-ordinate systems and then show the code ( that's very legible!) for using alternate units.

    However I'm not sure why you have two sets of units in one equation on line or switch back and forth between pt and mm:

    -h     =>  110/mm - 7/pt

    ++
    --
    Clayton
      Not fair! You're reading ahead!!!

      I'll get to that bit soon. I was rather proud of the /mm convention for converting units on the fly. Looks better than mm2pt().

      I have the two units in one line in order to accurately measure a position. I'd have to take a look but it looks like I have a text box that needed shortening by one line. I might change that when I get down to it. The text block is 100mm tall, but each line is 7pt apart.

      Thanks for the feedback!
      Rick


      If this is a root node: Before responding, please ensure your clue bit is set.
      If this is a reply: This is a discussion group, not a helpdesk ... If the discussion happens to answer a question you've asked, that's incidental.
Re: Review request for PDF::API2 Tutorial
by Aragorn (Curate) on Aug 17, 2004 at 14:08 UTC
    Very nice!

    One thing that annoyed me a bit is the small size of the picture that explains the (Media|Bleed|Crop|Art)Box concepts.

    Arjen

Re: Review request for PDF::API2 Tutorial
by revdiablo (Prior) on Aug 17, 2004 at 17:25 UTC

    Hi! This is a nice tutorial. It's simple, and easy to follow. I have a somewhat off-topic question, though. Do you have any experience parsing PDFs? I've looked at PDF::Parse, and frankly, it seems incomplete. I was wondering if you have any advice for using this, or another module. Maybe you could write another tutorial! :-) (Ok, I'm probably asking too much. But hey, it's worth a shot.)

      Parsing PDFs ... what are you parsing them for? Are you attempting to extract the text and pictures?

      More information please.


      If this is a root node: Before responding, please ensure your clue bit is set.
      If this is a reply: This is a discussion group, not a helpdesk ... If the discussion happens to answer a question you've asked, that's incidental.

        First, I want to say thanks for the reply! I know the question is off topic, and one could make the case that I should start a new top-level node, but I thought you might have some advice off the top of your head.

        what are you parsing them for?

        I was trying to extract the text, and regenerate a new PDF with page numbers. It's been a while since I tried this, and I went with a different solution, but it's been bothering me ever since. PDF::Parse seems like it will get me the pages, but after that, I can't see how to get any data from them.

Re: Review request for PDF::API2 Tutorial
by Jaap (Curate) on Aug 18, 2004 at 12:22 UTC
    Very nice, BigLug! Thank you for the time you spent on it. Now i finally onderstand all the boxes in pdf. You really do explain it very well, in an easy-to-understand way.
Re: Review request for PDF::API2 Tutorial
by zachzippo (Initiate) on Sep 15, 2004 at 20:14 UTC
    Looked good, but was unable to retreive the sourcecode, something at your site was preventing it.
Re: Review request for PDF::API2 Tutorial
by k2 (Scribe) on Oct 13, 2004 at 11:10 UTC
    Nice work!
    I think I have tried to write a tutorial for the PDF::API2 about 3-4 times now,
    but haven't managed to finish the work, and when compared to the work you have done
    I think we should all be greatful for that. ;-)
    Nice with the professional explanation of media/crop/bleed/art-boxes.

    /K2
Re: Review request for PDF::API2 Tutorial
by RatArsed (Monk) on Apr 20, 2005 at 21:05 UTC

    Just been following the tutorial with v0.40 -- as a working example I was seeing how hard it would be to build a Cissiculum Vitae (Resumé) out of a DB straight to PDF.

    I certainly think it's worth CPANing the text_block functionality. Other comments I'd make would be to fix the link up for the full source, and maybe even have a linky to the final result. Of course, you could go a step further and have the example code write the tutorial as a PDF file :)

    If you do CPAN the text_block -- make it take a font handle and a font size -- then you can have a default line-height of (say) 1.2em.

      I haven't worked with PDF::API2 for 6 months now .. changed jobs and about to change again. The tutorial mentioned is still a work-in-progress and maybe I'll have some more time on my hands to go back to it.

      I'd like to get it working properly with 0.4x, but I think that 0.4x has some sort of advanced text block already... not too sure though. How well did the existing tutorial work for you in the newer release?


      Cheers!
      Rick
      If this is a root node: Before responding, please ensure your clue bit is set.
      If this is a reply: This is a discussion group, not a helpdesk ... If the discussion happens to answer a question you've asked, that's incidental.

        Worked fine so far; to be honest, I haven't had a great deal of time to do more with it -- I was considering do kind of bizarre reimplmentation of FOP in Perl, but that would be excessive :)

Re: Review request for PDF::API2 Tutorial
by GhodMode (Pilgrim) on Jan 13, 2006 at 14:08 UTC
    In the text_block subroutine, doesn't the following line give the width of the digits used to identify the hanging indent rather than the actual size of the hanging indent? ...
    my $hang_width = $text_object->advancewidth($arg{'-hang'});
    ... from pod2text Content.pm ...
    $width = $txt->advancewidth $string [, %textstate] Returns the width of the string based on all currently set text-attributes or on those overridden by %textstate.
    So, if I call the subroutine with -hang => 30, intending to have a 30 PS point hanging indent, it'll actually set it to the width of the string "30".

    Did I find an error, or did I just misunderstand something?

    Thanks,
    -- Ghodmode

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-11-23 15:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (132 votes), past polls