I am trying to include images into the PDF output produced in Stata. I am getting an error, which I believe I should not be getting. Consider the following example:
Code:
clear all sysuse auto graph matrix weight mpg price, half // 11111111111111111111111111111111111111111111111111111111111 graph export "C:\temp\scatter.png", replace as(png) putpdf begin putpdf paragraph, halign(center) putpdf image "C:\temp\scatter.png", width(4) linebreak putpdf text ("Figure 1. Scatterplots") putpdf save "C:\temp\example1.pdf", replace erase "C:\temp\scatter.png" // 22222222222222222222222222222222222222222222222222222222222 graph export "C:\temp\scatter.png", replace as(png) putpdf begin putpdf paragraph, halign(center) putpdf image "C:\temp\scatter.png", width(4) linebreak erase "C:\temp\scatter.png" putpdf text ("Figure 1. Scatterplots") putpdf save "C:\temp\example2.pdf", replace display "OK"
The first method
- saves the image,
- adds it to the document,
- saves the document, then
- deletes the image file.
- saves the image,
- adds it to the document,
- deletes the image file.
- saves the document
It seems that the image is not immediately embedded into the pdf document, but is delayed until the document is saved. This presents a problem for me, since my procedure needs to append a large number of graphs to a pdf document and is not ready to close it, since some other content must follow, yet the temporary images must be deleted.
In addition, this may present a problem to other users, which may be difficult to diagnose, as the following example demonstrates:
Code:
clear all sysuse auto putpdf begin foreach v in weight length { twoway scatter price `v' graph export "C:\temp\scatter.png", replace as(png) putpdf paragraph, halign(center) putpdf image "C:\temp\scatter.png", width(4) linebreak putpdf text ("Figure X. `v'") } putpdf save "C:\temp\exampleZ.pdf", replace erase "C:\temp\scatter.png" display "OK"
The documentation is silent about timing of when the embedding actually occurs, so I believe it is ok to imply that it happens at the time the putpdf image command is executed, but the actual behavior is consistent with the image being embedded at saving of the document.
I am looking for a way to put the image into the pdf document and disposing of the image without finalizing the document, or a confirmation that this is not possible in Stata. (It would also be ok to save and reopen the pdf to continue adding more content, but as far as I know this is not possible, though very much desirable - just add pages to an existing PDF document, e.g. generated in another system).
Stata 16.0 for Windows.
Thank you, Sergiy
0 Response to Temporary image in PDF output
Post a Comment