Exemplo n.º 1
0
 function __sleep()
 {
     $buf = new java("java.io.ByteArrayOutputStream");
     $out = new java("java.io.ObjectOutputStream", $buf);
     $out->writeObject($this->java);
     $out->close();
     $this->serialID = base64_encode(java_cast($buf->toByteArray(), "S"));
     return array("serialID");
 }
Exemplo n.º 2
0
$j_tf = $j_tfClass->newInstance();
// create a svg picture with an ellipse in it
// and print it out
$FactoryClass = new JavaClass("javax.xml.parsers.DocumentBuilderFactory");
$factory = $FactoryClass->newInstance();
$builder = $factory->newDocumentBuilder();
$myDocument = $builder->newDocument();
$svgElement = $myDocument->createElementNS("http://www.w3.org/2000/svg", "svg");
$myDocument->appendChild($svgElement);
$svgElement->setAttribute("width", "4cm");
$svgElement->setAttribute("height", "8cm");
$ellipseElement = $myDocument->createElementNS("http://www.w3.org/2000/svg", "ellipse");
$ellipseElement->setAttribute("cx", "2cm");
$ellipseElement->setAttribute("cy", "4cm");
$ellipseElement->setAttribute("rx", "2cm");
$ellipseElement->setAttribute("ry", "1cm");
$svgElement->appendChild($ellipseElement);
$TransformerFactory = new JavaClass("javax.xml.transform.TransformerFactory");
$transFactory = $TransformerFactory->newInstance();
$myTransformer = $transFactory->newTransformer();
$src = new java("javax.xml.transform.dom.DOMSource", $myDocument);
// print the picture to a memory buffer and return the contents of the
// buffer to the client.
$memoryStream = new java("java.io.ByteArrayOutputStream");
$streamResult = new java("javax.xml.transform.stream.StreamResult", $memoryStream);
$myTransformer->transform($src, $streamResult);
$data = $memoryStream->toByteArray();
echo java_values($data) . "\n";
$fp = fopen("ellipse.svg", "w");
fwrite($fp, java_values($data));
fclose($fp);
Exemplo n.º 3
0
            $fmt->setImageHandler($ih);
            header("Content-type: text/html");
            break;
        case "msword":
            $fmt = new java("org.eclipse.birt.report.engine.api.RenderOption");
            $fmt->setOutputFormat("doc");
            header("Content-type: application/msword");
            break;
        case "xls":
            $fmt = new java("org.eclipse.birt.report.engine.api.RenderOption");
            $fmt->setOutputFormat("xls");
            header("Content-type: application/vnd.ms-excel");
            break;
        default:
            die("unknown output format {$format}");
    }
    return $fmt;
}
try {
    $engine = $birtReportEngine->openReportDesign("{$here}/{$myReport}");
    $task = $birtReportEngine->createRunAndRenderTask($engine);
    $fmt = getOutputFormat($myFormat);
    $fmt->setOutputStream($out = new java("java.io.ByteArrayOutputStream"));
    $task->setRenderOption($fmt);
    $task->run();
    $task->close();
} catch (JavaException $e) {
    echo $e;
}
echo java_values($out->toByteArray());
#!/usr/bin/php

<?php 
include_once "java/Java.inc";
$file_encoding = "ASCII";
java_set_file_encoding($file_encoding);
$out = new java("java.io.ByteArrayOutputStream");
$stream = new java("java.io.PrintStream", $out);
$str = new java("java.lang.String", "Cześć! -- שלום -- Grüß Gott", "UTF-8");
$stream->print($str);
echo "Stream: " . $out->__toString() . "\n";
echo "Stream as {$file_encoding} string: " . java_values($out->toString()) . "\n";
echo "Stream as binary data: " . java_cast($out->toByteArray(), "S") . "\n";
  /**
   * @inheritdoc
   */
  public function populateWithFieldData(FillPdfFormInterface $pdf_form, array $field_mapping, array $context) {
    /** @var FileInterface $original_file */
    $original_file = File::load($pdf_form->file->target_id);
    $pdf_data = file_get_contents($original_file->getFileUri());
    $fields = $field_mapping['fields'];

    $require = drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc';
    require_once DRUPAL_ROOT . '/' . $require;
    try {
      $fillpdf = new \java('com.ocdevel.FillpdfService', base64_encode($pdf_data), 'bytes');
      foreach ($fields as $key => $field) {
        if (substr($field, 0, 7) == '{image}') {
          // Remove {image} marker.
          $image_filepath = substr($field, 7);
          $image_realpath = $this->fileSystem->realpath($image_filepath);
          $fillpdf->image($key, $image_realpath, 'file');
        }
        else {
          $fillpdf->text($key, $field);
        }
      }
    }
    catch (\JavaException $e) {
      drupal_set_message(java_truncate((string) $e), 'error');
      return NULL;
    }
    try {
      if ($context['flatten']) {
        $populated_pdf = java_values(base64_decode($fillpdf->toByteArray()));
      }
      else {
        $populated_pdf = java_values(base64_decode($fillpdf->toByteArrayUnflattened()));
      }
    }
    catch (\JavaException $e) {
      drupal_set_message(java_truncate((string) $e), 'error');
      return NULL;
    }

    return $populated_pdf;
  }