function CreateButtonAppearance($doc, $button_down)
{
    // Create a button appearance stream ------------------------------------
    $build = new ElementBuilder();
    $writer = new ElementWriter();
    $writer->Begin($doc->GetSDFDoc());
    // Draw background
    $element = $build->CreateRect(0, 0, 101, 37);
    $element->SetPathFill(true);
    $element->SetPathStroke(false);
    $element->GetGState()->SetFillColorSpace(ColorSpace::CreateDeviceGray());
    $element->GetGState()->SetFillColor(new ColorPt(0.75, 0.0, 0.0));
    $writer->WriteElement($element);
    // Draw 'Submit' text
    $writer->WriteElement($build->CreateTextBegin());
    $text = "Submit";
    $element = $build->CreateTextRun($text, Font::Create($doc->GetSDFDoc(), Font::e_helvetica_bold), 12.0);
    $element->GetGState()->SetFillColor(new ColorPt(0.0, 0.0, 0.0));
    if ($button_down) {
        $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 33.0, 10.0);
    } else {
        $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 30.0, 13.0);
    }
    $writer->WriteElement($element);
    $writer->WriteElement($build->CreateTextEnd());
    $stm = $writer->End();
    // Set the bounding box
    $stm->PutRect("BBox", 0, 0, 101, 37);
    $stm->PutName("Subtype", "Form");
    return $stm;
}
Пример #2
0
//
// In the opaque imaging model, images mark all areas they occupy on the page as
// if with opaque paint. All portions of the image, whether black, white, gray,
// or color, completely obscure any marks that may previously have existed in the
// same place on the page.
// In the graphic arts industry and page layout applications, however, it is common
// to crop or 'mask out' the background of an image and then place the masked image
// on a different background, allowing the existing background to show through the
// masked areas. This sample illustrates how to use image masks.
$page = $doc->PageCreate();
$writer->Begin($page);
// begin writing to the page
// Create the Image Mask
$imgf = new MappedFile($input_path . "imagemask.dat");
$mask_read = new FilterReader($imgf);
$device_gray = ColorSpace::CreateDeviceGray();
$mask = Image::Create($doc->GetSDFDoc(), $mask_read, 64, 64, 1, $device_gray, Image::e_ascii_hex);
$mask->GetSDFObj()->PutBool("ImageMask", true);
$element = $builder->CreateRect(0, 0, 612, 794);
$element->SetPathStroke(false);
$element->SetPathFill(true);
$element->GetGState()->SetFillColorSpace($device_gray);
$element->GetGState()->SetFillColor(new ColorPt(0.8));
$writer->WritePlacedElement($element);
$element = $builder->CreateImage($mask, new Matrix2D(200.0, 0.0, 0.0, -200.0, 40.0, 680.0));
$element->GetGState()->SetFillColor(new ColorPt(0.1));
$writer->WritePlacedElement($element);
$element->GetGState()->SetFillColorSpace(ColorSpace::CreateDeviceRGB());
$element->GetGState()->SetFillColor(new ColorPt(1.0, 0.0, 0.0));
$element = $builder->CreateImage($mask, new Matrix2D(200.0, 0.0, 0.0, -200.0, 320.0, 680.0));
$writer->WritePlacedElement($element);
Пример #3
0
         // Recompress only 1 BPC images
         continue;
     }
     // Skip images that are already compressed using JBIG2
     $itr = $obj->Find("Filter");
     if ($itr->HasNext() && $itr->Value()->IsName() && $itr->Value()->GetName() == "JBIG2Decode") {
         continue;
     }
     $filter = $obj->GetDecodedStream();
     $reader = new FilterReader($filter);
     $hint_set = new ObjSet();
     // A hint to image encoder to use JBIG2 compression
     $hint = $hint_set->CreateArray();
     $hint->PushBackName("JBIG2");
     $hint->PushBackName("Lossless");
     $new_image = Image::Create($cos_doc, $reader, $input_image->GetImageWidth(), $input_image->GetImageHeight(), 1, ColorSpace::CreateDeviceGray(), $hint);
     $new_img_obj = $new_image->GetSDFObj();
     $itr = $obj->Find("Decode");
     if ($itr->HasNext()) {
         $new_img_obj->Put("Decode", $itr->Value());
     }
     $itr = $obj->Find("ImageMask");
     if ($itr->HasNext()) {
         $new_img_obj->Put("ImageMask", $itr->Value());
     }
     $itr = $obj->Find("Mask");
     if ($itr->HasNext()) {
         $new_img_obj->Put("Mask", $itr->Value());
     }
     $cos_doc->Swap($i, $new_img_obj->GetObjNum());
 }