Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using MATA to create a PDF, how to set the Page Size (correctly)?

    Hi, in Stata 14, it is now possible to create a PDF using mata, something I appreciate very much.
    But, I am struggling to get the 'basics' to work. For example, with this code, from the documentation:
    Code:
    mata:
    pdf = PdfDocument()
    
    p = PdfParagraph()
    p.addString("This is our first example of a paragraph. ")
    p.addString("Let's add another sentence. ")
    p.addString("Now we will conclude our first paragraph.")
    pdf.addParagraph(p)
    
    pdf.save("WorkingExample1.pdf")
    pdf.close()
    * clean up
    mata drop p
    mata drop pdf
    end
    Mata does create a PDF in the current working directory. This is straightforward.
    So, now I want to set some document specifics, like the page size, which requires the PdfDocument class command setPageSize(sz)which I have coded as:
    Code:
    pdf.setPageSize(A4)
    Code:
    mata:
    pdf = PdfDocument()
    
    p = PdfParagraph()
    p.addString("This is our first example of a paragraph. ")
    p.addString("Let's add another sentence. ")
    p.addString("Now we will conclude our first paragraph.")
    pdf.addParagraph(p)
    
    pdf.setPageSize(A4)
    pdf.save("WorkingExample1.pdf")
    pdf.close()
    * clean up
    mata drop p
    mata drop pdf
    end
    But this results in an error:
    <istmt>: 3499 A4 not found
    (5 lines skipped)


    Does anyone know what goes wrong here, or if am not correctly coding?

    Best regards,
    Eric
    http://publicationslist.org/eric.melse

  • #2
    Random guess based on the documentation: have you tried putting quotation marks about A4
    Code:
    pdf.setPageSize("A4")
    Can't test it myself, still on version 13.1.

    Note that you may not get many other answers to this question, because it is (I realize now) posted in the "Forums for learning to use the Forum Software > Using the Forum" forum rather than the "Forums for Discussing Stata > Mata" forum.
    Last edited by William Lisowski; 23 May 2015, 12:09.

    Comment


    • #3
      Dear William,

      I have tried your suggestion, but, now I get the error:
      invalid expression
      (2 lines skipped)


      http://publicationslist.org/eric.melse

      Comment


      • #4
        I'm at a loss, then. I do believe that the quotation marks are required for the PdfDocument size command, by analogy to the PdfDocument save command - both require a string scalar argument. I think that's what your initial error message was trying to tell you - it couldn't find a scalar named A4. I just can't guess what the current error message is trying to tell you.

        I suggest you repost to the Mata forum including the additional results from our discussion and see if anyone else has any ideas. Good luck!

        Comment


        • #5
          Right, but the manual states: setPageSize(sz) sets the page size of the PDF file. The possible values for size are Letter, Legal, A3, A4, A5, B4, and B5.
          http://publicationslist.org/eric.melse

          Comment


          • #6
            Eric - I see that your reply at #3 is timestamped before my last edit on #2, so you may not have seen this note I added during editing:
            Note that you may not get many other answers to this question, because it is (I realize now) posted in "Forums for learning to use the Forum Software > Using the Forum" rather than in "Forums for Discussing Stata > Mata".

            Comment


            • #7
              This question was answered in the Mata forum.

              http://www.statalist.org/forums/foru...size-correctly

              Comment

              Working...
              X