Closed andy-twosticks closed 6 years ago
Yes you can. The write
method accepts any kind of IO object.
strio = StringIO.new
PDF.new.write(strio)
p strio.string
# "%PDF-1.0\n1 0 obj\n<<\n\t/Pages 2 0 R\n\t/Type /Catalog\n>>\nendobj\n2 0 obj\n<<\n\t/Count 1\n\t/Kids [3 0 R]\n\t/Type /Pages\n>>\nendobj\n3 0 obj\n<<\n\t/Parent 2 0 R\n\t/Resources <<\n\t\t/Font <<\n\t\t\t/F1 <<\n\t\t\t\t/Type /Font\n\t\t\t\t/Subtype /Type1\n\t\t\t\t/BaseFont /Helvetica\n\t\t\t>>\n\t\t>>\n\t>>\n\t/Type /Page\n\t/MediaBox [0 0 595 842]\n>>\nendobj\nxref\n0 4\n0000000000 65535 f \n0000000009 00000 n \n0000000060 00000 n \n0000000120 00000 n \ntrailer\n<<\n\t/Root 1 0 R\n\t/Size 4\n>>\nstartxref\n306\n%%EOF\n"
I'd like to be able to generate a PDF and print it without saving it as a file. Perhaps it's just me, but I can't see how to do that?
In the code I can see
PDF#output
, but it's a private method, so I don't want to use that.