Method: RBPDF#Output
- Defined in:
- lib/rbpdf.rb
#Output(name = '', dest = '') ⇒ Object Also known as: output
Send the document to a given destination: string, local file or browser. In the last case, the plug-in may be used (if present) or a download (“Save as” dialog box) may be forced. The method first calls Close() if necessary to terminate the document.
- @param string :name
-
The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
- @param string :dest
-
Destination where to send the document. It can take one of the following values:
-
I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the “Save as” option on the link generating the PDF.
-
D: send to the browser and force a file download with the name given by name.
-
F: save to a local server file with the name given by name.
-
S: return the document as a string. name is ignored.
-
FI: equivalent to F + I option
-
FD: equivalent to F + D option
-
- @access public
- @since 1.0
- @see
-
Close()
5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 |
# File 'lib/rbpdf.rb', line 5564 def Output(name='', dest='') #Output PDF to some destination #Finish document if necessary lastPage() if (@state < 3) Close(); end #Normalize parameters # Boolean no longer supported # if (dest.is_a?(Boolean)) # dest = dest ? 'D' : 'F'; # end dest = dest.upcase if (dest=='') if (name=='') name='doc.pdf'; dest='I'; else dest='F'; end end case (dest) when 'I' # This is PHP specific code ##Send to standard output # if (ob_get_contents()) # Error('Some data has already been output, can\'t send PDF file'); # end # if (php_sapi_name()!='cli') # #We send to a browser # header('Content-Type: application/pdf'); # if (headers_sent()) # Error('Some data has already been output to browser, can\'t send PDF file'); # end # header('Content-Length: ' + @buffer.length); # header('Content-disposition: inline; filename="' + name + '"'); # end return getBuffer when 'D' # PHP specific #Download file # if (ob_get_contents()) # Error('Some data has already been output, can\'t send PDF file'); # end # if (!_SERVER['HTTP_USER_AGENT'].nil? && SERVER['HTTP_USER_AGENT'].include?('MSIE')) # header('Content-Type: application/force-download'); # else # header('Content-Type: application/octet-stream'); # end # if (headers_sent()) # Error('Some data has already been output to browser, can\'t send PDF file'); # end # header('Content-Length: '+ @buffer.length); # header('Content-disposition: attachment; filename="' + name + '"'); return getBuffer when 'F', 'FI', 'FD' # Save PDF to a local file if @diskcache FileUtils.copy(@buffer.path, name) else open(name,'wb') do |f| f.write(@buffer) end end if dest == 'FI' # This is PHP specific code # # send headers to browser # header('Content-Type: application/pdf') # header('Cache-Control: public, must-revalidate, max-age=0') # HTTP/1.1 # header('Pragma: public') # header('Expires: Sat, 26 Jul 1997 05:00:00 GMT') # Date in the past # header('Last-Modified: ' + gmdate('D, d M Y H:i:s') + ' GMT') # header('Content-Length: ' + filesize(name)) # header('Content-Disposition: inline; filename="' + File.basename(name) + '";') # send document to the browser data = '' open(name) do |f| data<< f.read ;end return data elsif dest == 'FD' # This is PHP specific code # # send headers to browser # if ob_get_contents() # Error('Some data has already been output, can\'t send PDF file') # end # header('Content-Description: File Transfer') # if headers_sent()) # Error('Some data has already been output to browser, can\'t send PDF file') # end # header('Cache-Control: public, must-revalidate, max-age=0') # HTTP/1.1 # header('Pragma: public') # header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); # Date in the past # header('Last-Modified: ' + gmdate('D, d M Y H:i:s') + ' GMT') # # force download dialog # header('Content-Type: application/force-download') # header('Content-Type: application/octet-stream', false) # header('Content-Type: application/download', false) # header('Content-Type: application/pdf', false) # # use the Content-Disposition header to supply a recommended filename # header('Content-Disposition: attachment; filename="' + File.basename(name) + '";') # header('Content-Transfer-Encoding: binary') # header('Content-Length: ' + filesize(name)) # send document to the browser data = '' open(name) do |f| data<< f.read ;end return data end when 'S' # Returns PDF as a string return getBuffer else Error('Incorrect output destination: ' + dest); end return ''; ensure destroy(true) end |