Пример #1
0
<?php

include_once "java/Java.inc";
java_autoload("itext.jar");
use com\lowagie\text;
use com\lowagie\text\pdf;
try {
    $document = new text\Document();
    $out = new java\io\ByteArrayOutputStream();
    $pdfWriter = pdf\PdfWriter::type()->getInstance($document, $out);
    $document->open();
    $font = text\FontFactory::type()->getFont(text\FontFactory::type()->HELVETICA, 24, text\Font::type()->BOLDITALIC, new java\awt\Color(0, 0, 255));
    $paragraph = new text\Paragraph("Hello World", $font);
    $document->add($paragraph);
    $document->close();
    $pdfWriter->close();
    // print the generated document
    header("Content-type: application/pdf");
    header("Content-Disposition: attachment; filename=HelloWorld.pdf");
    echo java_values($out->toByteArray());
} catch (JavaException $e) {
    echo "Exception occured: ";
    echo $e;
    echo "<br>\n";
}
Пример #2
0
<?php

include_once "java/Java.inc";
java_autoload("lucene.jar");
use java\lang\System as SYS;
use java\io as IO;
use java\util as Util;
use org\apache\lucene as Lucene;
try {
    echo "indexing ... ";
    /* create the index files in the tmp dir */
    $tmp = create_index_dir();
    $analyzer = new Lucene\analysis\standard\StandardAnalyzer();
    $writer = new Lucene\index\IndexWriter($tmp, $analyzer, true);
    $file = new IO\File(getcwd());
    $files = $file->listFiles();
    assert(!java_is_null($files));
    foreach ($files as $f) {
        $doc = new Lucene\document\Document();
        $doc->add(new Lucene\document\Field("name", $f->getName(), Lucene\document\Field::type("Store")->YES, Lucene\document\Field::type("Index")->UN_TOKENIZED));
        $writer->addDocument($doc);
    }
    $writer->optimize();
    $writer->close();
    echo "done\n";
    echo "searching... ";
    /* Search */
    $searcher = new Lucene\search\IndexSearcher($tmp);
    $phrase = new Lucene\search\MatchAllDocsQuery();
    $hits = $searcher->search($phrase);
    /* Print result */