Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / files / document / PhabricatorPDFDocumentEngine.php
blob1e85bd4ae5174dad6ea0be70c38ef26e5ddb1536
1 <?php
3 final class PhabricatorPDFDocumentEngine
4 extends PhabricatorDocumentEngine {
6 const ENGINEKEY = 'pdf';
8 public function getViewAsLabel(PhabricatorDocumentRef $ref) {
9 return pht('View as PDF');
12 protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) {
13 return 'fa-file-pdf-o';
16 protected function canRenderDocumentType(PhabricatorDocumentRef $ref) {
17 // Since we just render a link to the document anyway, we don't need to
18 // check anything fancy in config to see if the MIME type is actually
19 // viewable.
21 return $ref->hasAnyMimeType(
22 array(
23 'application/pdf',
24 ));
27 protected function newDocumentContent(PhabricatorDocumentRef $ref) {
28 $viewer = $this->getViewer();
30 $file = $ref->getFile();
31 if ($file) {
32 $source_uri = $file->getViewURI();
33 } else {
34 throw new PhutilMethodNotImplementedException();
37 $name = $ref->getName();
38 $length = $ref->getByteLength();
40 $link = id(new PhabricatorFileLinkView())
41 ->setViewer($viewer)
42 ->setFileName($name)
43 ->setFileViewURI($source_uri)
44 ->setFileViewable(true)
45 ->setFileSize(phutil_format_bytes($length));
47 $container = phutil_tag(
48 'div',
49 array(
50 'class' => 'document-engine-pdf',
52 $link);
54 return $container;