@param $document Document
@param $header   Header
@param $content  string

@return PDFObject
486425
public static function factory(Document $document, Header $header, $content)
    {
        switch ($header->get('Type')->getContent()) {
            case 'XObject':
                switch ($header->get('Subtype')->getContent()) {
                    case 'Image':
                        return new Image($document, $header, $content);

                    case 'Form':
                        return new Form($document, $header, $content);

                    default:
                        return new PDFObject($document, $header, $content);
                }
                break;

            case 'Pages':
                return new Pages($document, $header, $content);

            case 'Page':
                return new Page($document, $header, $content);

            case 'Encoding':
                return new Encoding($document, $header, $content);

            case 'Font':
                $subtype   = $header->get('Subtype')->getContent();
                $classname = '\Smalot\PdfParser\Font\Font' . $subtype;

                if (class_exists($classname)) {
                    return new $classname($document, $header, $content);
                } else {
                    return new Font($document, $header, $content);
                }

            default:
                return new PDFObject($document, $header, $content);
        }
    }
441903
public function createResource(
        $uri = "",
        $content = null,
        $headers = []
    ) {
        $options = ['http_errors' => false];

        // Set content.
        $options['body'] = $content;

        // Set headers.
        $options['headers'] = $headers;

        return $this->client->request(
            'POST',
            $uri,
            $options
        );
    }
843311
public function getDocumentById($documentId)
    {
        /* @var $query SearchQuery */
        $query = $this->queryBuilder->newSearchQuery($documentId)->useQueryFields(QueryFields::fromString('id'))->getQuery();
        $response = $this->search->search($query, 0, 1);
        $parsedData = $response->getParsedData();
        $resultDocument = isset($parsedData->response->docs[0]) ? $parsedData->response->docs[0] : null;

        if (!$resultDocument instanceof Document) {
            throw new \UnexpectedValueException("Response did not contain a valid Document object");
        }

        return $this->searchResultBuilder->fromApacheSolrDocument($resultDocument);
    }
620092
public static Document buildPDFDocument (com.snowtide.pdf.Document pdf) throws IOException {
        return buildPDFDocument(pdf, DEFAULT_CONFIG);
    }
734671
public function create($content, $code = 200, $headers = [], $charset = null)
    {
        return $this->serializer->serialize(
            new Response($content, $code, $headers, $charset),
            'json'
        );
    }
503730
public function storeDocument(\Document $document)
  {
    $arrSet = $this->buildDocumentDataArray($document, false);
    
    $objDocument = $this->Database->prepare("INSERT INTO tl_dms_documents %s")->set($arrSet)->execute();
    
    $document->id = $objDocument->insertId;
    return $document;
  }
164493
protected function documentFragmentCreate($source, $charset = null)
    {
        $fake              = new DOMDocumentWrapper();
        $fake->contentType = $this->contentType;
        $fake->isXML       = $this->isXML;
        $fake->isHTML      = $this->isHTML;
        $fake->isXHTML     = $this->isXHTML;
        $fake->root        = $fake->document;
        if (!$charset) {
            $charset = $this->charset;
        }
        //	$fake->documentCreate($this->charset);
        if ($source instanceof DOMNODE && !($source instanceof DOMNODELIST)) {
            $source = array($source);
        }
        if (is_array($source) || $source instanceof DOMNODELIST) {
            // dom nodes
            // load fake document
            if (!$this->documentFragmentLoadMarkup($fake, $charset)) {
                return false;
            }
            $nodes = $fake->import($source);
            foreach ($nodes as $node)
                $fake->root->appendChild($node);
        } else {
            // string markup
            $this->documentFragmentLoadMarkup($fake, $charset, $source);
        }

        return $fake;
    }
796830
public function convert(DOMDocument $document)
    {
        // First
        $this->expandingConverter->convert($document);
        // Second
        $this->embedLinkingConverter->convert($document);

        return $document;
    }
266833
protected function createHttpStream($method, $header = '', $content = null, $protocolVersion = '1.1')
    {
        $stream = new HttpFileStream($this->url());

        $stream->setMethod($method)
            ->setHeader($header)
            ->setProtocolVersion($protocolVersion);

        if ($content !== null) {
            $stream->setContent($content);
        }

        foreach ($this->supportedOptions() as $key) {
            if ($key == 'timeout') {
                $stream->setTimeout($this->getOption($key));
                continue;
            }
            $stream->setOption($key, $this->getOption($key));
        }

        return $stream;

    }
404819
protected function document(Document $document = null): ?Document {
        if ($document === null) {
            return $this->document;
        }

        $this->document = $document;

        return $this->document;
    }
1161445
public static function parse($content, Document $document = null, &$offset = 0)
    {
        if (preg_match('/^\s*\<(?P<name>[A-F0-9]+)\>/is', $content, $match)) {
            $name    = $match['name'];
            $offset += strpos($content, '<' . $name) + strlen($name) + 2; // 1 for '>'
            // repackage string as standard
            $name    = '(' . self::decode($name, $document) . ')';
            $element = false;

            if (!($element = ElementDate::parse($name, $document))) {
                $element = ElementString::parse($name, $document);
            }

            return $element;
        }

        return false;
    }
337938
protected static function createDocumentWrapper($html, $contentType = null, $documentID = null) 
    {
        if (function_exists('domxml_open_mem')) {
            throw new Exception("Old PHP4 DOM XML extension detected. phpQuery won't work until this extension is enabled.");
        }
        //        $id = $documentID
        //            ? $documentID
        //            : md5(microtime());
        $document = null;
        if ($html instanceof DOMDOCUMENT) {
            if (self::getDocumentID($html)) {
                // document already exists in phpQuery::$documents, make a copy
                $document = clone $html;
            } else {
                // new document, add it to phpQuery::$documents
                $wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
            }
        } else {
            $wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
        }
        //        $wrapper->id = $id;
        // bind document
        phpQuery::$documents[$wrapper->id] = $wrapper;
        // remember last loaded document
        phpQuery::selectDocument($wrapper->id);
        return $wrapper->id;
    }
646484
public function addObject($object, Document $doc = null)
    {
        if (!isset($this->_serializer)) {
            throw new RuntimeException('No serializer defined');
        }

        $data = \call_user_func($this->_serializer, $object);
        if (!$doc) {
            $doc = new Document();
        }
        $doc->setData($data);

        return $this->addDocument($doc);
    }
937063
protected function sendHeader(string $header, string $content): void
    {
        if (!headers_sent() && self::$sendHeaders) {
            header(sprintf('%s: %s', $header, $content));
        }
    }
1320924
public function setDocument(Document $document): self
    {
        $this->_data = $document;

        $metadata = $this->_getMetadata($document);

        $this->setMetadata($metadata);

        return $this;
    }
1194630
private final void renderHeader(PdfWriter writer, Document document) throws DocumentException, VectorPrintException {
      if ((!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG))
          || (!failuresHereAfter && !getSettings().getBooleanProperty(false, DEBUG))) {
         
         writer.getDirectContent().addImage(getTemplateImage(template));
         
         if (getSettings().getBooleanProperty(false, DEBUG)) {
            ArrayList a = new ArrayList(2);
            a.add(PdfName.TOGGLE);
            a.add(elementProducer.initLayerGroup(DEBUG, writer.getDirectContent()));
            PdfAction act = PdfAction.setOCGstate(a, true);
            Chunk h = new Chunk("toggle debug info", DebugHelper.debugFontLink(writer.getDirectContent(), getSettings())).setAction(act);
            
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(h), 10, document.top() - 15, 0);
            Font f = DebugHelper.debugFontLink(writer.getDirectContent(), getSettings());
//            act = PdfAction.gotoLocalPage("debugpage", true);

            elementProducer.startLayerInGroup(DEBUG, writer.getDirectContent());
            
            h = new Chunk(getSettings().getProperty("go to debug legend", "debugheader"), f).setLocalGoto(BaseReportGenerator.DEBUGPAGE);
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(h), 10, document.top() - 3, 0);
            
            writer.getDirectContent().endLayer();
            
         }
      }
   }
499346
public function generateWithDocraptor( $pdf_profile, $document_content, $output_path ) {
		// Configure service
		$configuration = \DocRaptor\Configuration::getDefaultConfiguration();
		$configuration->setUsername( DOCRAPTOR_API_KEY );

		// Save PDF as file in exports folder
		$docraptor = new \DocRaptor\DocApi();
		$prince_options = new \DocRaptor\PrinceOptions();
		$prince_options->setHttpTimeout( max( ini_get( 'max_execution_time' ), 30 ) );
		$prince_options->setProfile( $pdf_profile );
		$retval = false;

		try {
			$doc = new \DocRaptor\Doc();
			if ( defined( 'WP_TESTS_MULTISITE' ) ) {
				// Unit tests
				$doc->setTest( true );
			} elseif ( defined( 'WP_ENV' ) && ( WP_ENV === 'development' ) ) {
				// Localhost
				$doc->setTest( true );
			} else {
				$doc->setTest( false );
			}
			$doc->setDocumentContent( $document_content );
			$doc->setName( get_bloginfo( 'name' ) . ' Cover' );
			$doc->setPrinceOptions( $prince_options );

			$create_response = $docraptor->createAsyncDoc( $doc );
			$done = false;
			while ( ! $done ) {
				$status_response = $docraptor->getAsyncDocStatus( $create_response->getStatusId() );
				switch ( $status_response->getStatus() ) {
					case 'completed':
						if ( ! function_exists( 'download_url' ) ) {
							require_once( ABSPATH . 'wp-admin/includes/file.php' );
						}
						$result = \download_url( $status_response->getDownloadUrl() );
						if ( is_wp_error( $result ) ) {
							\Pressbooks\add_error( __( 'Your PDF could not be retrieved.', 'pressbooks' ) );
						} else {
							copy( $result, $output_path );
							unlink( $result );
							$retval = true;
						}
						$done = true;
						break;
					case 'failed':
						wp_die( $status_response );
						$done = true;
						break;
					default:
						sleep( 1 );
				}
			}
		} catch ( \DocRaptor\ApiException $exception ) {
			$message = "<h1>{$exception->getMessage()}</h1><p>{$exception->getCode()}</p><p>{$exception->getResponseBody()}</p>";
			wp_die( $message );
		}

		return $retval;
	}