Announcement

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

  • -putpdf- with -tempfile-

    Dear All,

    I am puzzled why the putpdf command requires the output file name to have specifically the extension as ".pdf".

    Consider the following example code:

    Code:
        clear all
        version 16.1
    
        tempfile tmp
        putpdf begin
        putpdf paragraph
        putpdf text ("Hello, World!")
        putpdf save `"`tmp'"'
    
    // end of file
    When executed it ends with an error 198:
    C:\Users\MYUSERNAME\AppData\Local\Temp\ST_79d8_000 001.tmp is not a pdf file


    I have reported earlier a similar problem related to the images that I tried to include into the report, where Hua Peng (StataCorp) has provided a workaround and which was later confirmed fixed by Zhao Xu (StataCorp) .

    Context: the report is created in PDF format, file is uploaded to a remote server with a proper name ending in ".pdf", then local copy is disposed of. I want to rely on Stata's tempfile facility to clean up the temporary file, which doesn't work in this case.

    Can anyone please check if Stata 17 behaves the same and results in an error with the above-shown code?

    I don't see any reason for a pdf-document to have a specific extension, just like we are creating temporary data files without bothering giving them the ".dta" extension. If anything, the current error message could be a warning for a novice user, but shouldn't be blocking, imho.

    Thank you, Sergiy

  • #2
    The same behaviour in Stata 17/BE:
    Code:
    . clear all
    .     version 16.1
    .     tempfile tmp
    .     putpdf begin
    .     putpdf paragraph
    .     putpdf text ("Hello, World!")
    .     putpdf save `"`tmp'"'
    C:\Users\marty\AppData\Local\Temp\ST_220c_000001.tmp is not a pdf file
    r(198);
    Martyn

    Comment


    • #3
      Originally posted by Martyn Sherriff View Post
      The same behaviour in Stata 17/BE:

      Martyn
      Dear Martyn,

      thank you very much for taking time to confirm this issue with a contemporary Stata version.

      Best, Sergiy

      Comment


      • #4
        Analogous code fails with a similar error with -putdocx-.

        Code:
        . tempfile myfile
        . putdocx begin
        . putdocx paragraph
        . putdocx text ("Hello world")
        . putdocx save `"`myfile'"', replace
        
        C:\tmp\ST_1a4c_000001.tmp is not a docx file

        Comment

        Working...
        X