Example #1
0
 /**
  * Prepare the form objects
  *
  * @return void
  */
 protected function prepareForms()
 {
     $formRefs = '';
     foreach ($this->document->getForms() as $form) {
         $i = $this->lastIndex() + 1;
         $this->objects[$i] = Object\StreamObject::parse($form->getStream($i));
         $formRefs .= $i . ' 0 R ';
     }
     $formRefs = substr($formRefs, 0, -1);
     $this->root->setFormReferences($formRefs);
 }
Example #2
0
 /**
  * Parse the font data and create the font objects
  *
  * @throws Exception
  * @return void
  */
 public function parse()
 {
     if (null === $this->fontIndex || null === $this->fontObjectIndex || null === $this->fontDescIndex || null === $this->fontFileIndex) {
         throw new Exception('Error: The font indices are not set');
     }
     if ($this->font instanceof Type1) {
         $fontType = 'Type1';
         $fontName = $this->font->info->postscriptName;
         $fontFile = 'FontFile';
         $glyphWidths = ['encoding' => 'StandardEncoding', 'widths' => $this->font->glyphWidths];
         $unCompStream = $this->font->fontData;
         $length1 = $this->font->length1;
         $length2 = " /Length2 " . $this->font->length2 . " /Length3 0";
     } else {
         $fontType = 'TrueType';
         $fontName = $this->font->tables['name']->postscriptName;
         $fontFile = 'FontFile2';
         $glyphWidths = $this->getGlyphWidths($this->font->tables['cmap']);
         $unCompStream = $this->font->read();
         $length1 = strlen($unCompStream);
         $length2 = null;
     }
     $this->objects[$this->fontObjectIndex] = StreamObject::parse("{$this->fontObjectIndex} 0 obj\n<<\n    /Type /Font\n    /Subtype /{$fontType}\n    /FontDescriptor " . $this->fontDescIndex . " 0 R\n    /Name /TT{$this->fontIndex}\n    /BaseFont /" . $fontName . "\n    /FirstChar 32\n    /LastChar 255\n    /Widths [" . implode(' ', $glyphWidths['widths']) . "]\n    /Encoding /" . $glyphWidths['encoding'] . "\n>>\nendobj\n\n");
     $bBox = '[' . $this->font->bBox->xMin . ' ' . $this->font->bBox->yMin . ' ' . $this->font->bBox->xMax . ' ' . $this->font->bBox->yMax . ']';
     if ($this->compression && function_exists('gzcompress')) {
         $compStream = gzcompress($unCompStream, 9);
         $fontFileObj = "{$this->fontFileIndex} 0 obj\n<</Length " . strlen($compStream) . " /Filter /FlateDecode /Length1 " . $length1 . $length2 . ">>\nstream\n" . $compStream . "\nendstream\nendobj\n\n";
     } else {
         $fontFileObj = "{$this->fontFileIndex} 0 obj\n<</Length " . strlen($unCompStream) . " /Length1 " . $length1 . $length2 . ">>\nstream\n" . $unCompStream . "\nendstream\nendobj\n\n";
     }
     $this->objects[$this->fontDescIndex] = StreamObject::parse("{$this->fontDescIndex} 0 obj\n<<\n    /Type /FontDescriptor\n    /FontName /" . $fontName . "\n    /{$fontFile} {$this->fontFileIndex} 0 R\n    /MissingWidth {$this->font->missingWidth}\n    /StemV " . $this->font->stemV . "\n    /Flags " . $this->font->calcFlags() . "\n    /FontBBox {$bBox}\n    /Descent " . $this->font->descent . "\n    /Ascent {$this->font->ascent}\n    /CapHeight " . $this->font->capHeight . "\n    /ItalicAngle {$this->font->italicAngle}\n>>\nendobj\n\n");
     $this->objects[$this->fontFileIndex] = StreamObject::parse($fontFileObj);
 }
Example #3
0
 /**
  * Parse the JPG image data
  *
  * @throws Exception
  * @return void
  */
 protected function parseJpeg()
 {
     // Add the image to the objects array.
     $colorMode = strtolower($this->colorMode) == 'srgb' ? 'RGB' : $this->colorMode;
     $colorSpace = $this->colorMode == 'CMYK' ? "/DeviceCMYK\n    /Decode [1 0 1 0 1 0 1 0]" : "/Device" . $colorMode;
     $this->objects[$this->index] = StreamObject::parse("{$this->index} 0 obj\n<<\n    /Type /XObject\n    /Subtype /Image\n    /Width " . $this->width . "\n    /Height " . $this->height . "\n    /ColorSpace {$colorSpace}\n    /BitsPerComponent 8\n    " . "/Filter /DCTDecode\n    /Length {$this->imageDataLength}\n>>\nstream\n{$this->imageData}\nendstream\nendobj\n");
 }