示例#1
1
 function preprocess()
 {
     if (FormLib::get_form_value('start', False) !== False) {
         $pdf = new FPDF('P', 'in', 'Letter');
         $pdf->SetMargins(0.5, 0.5, 0.5);
         $pdf->SetAutoPageBreak(False, 0.5);
         $pdf->AddPage();
         $start = FormLib::get_form_value('start');
         $x = 0.5;
         $y = 0.5;
         $pdf->AddFont('Gill', '', 'GillSansMTPro-Medium.php');
         $pdf->SetFont('Gill', '', 16);
         for ($i = 0; $i < 40; $i++) {
             $current = $start + $i;
             $pdf->SetXY($x, $y);
             $pdf->Cell(1.75, 0.5, $current, 0, 0, 'C');
             $pdf->Cell(1.75, 0.5, $current, 0, 0, 'C');
             if ($i % 2 == 0) {
                 $x += 1.75 * 2 + 0.5;
             } else {
                 $x = 0.5;
                 $y += 0.5;
             }
         }
         $pdf->Close();
         $pdf->Output("mem stickers {$start}.pdf", "I");
         return False;
     }
     return True;
 }
示例#2
1
function pdf_export_dots(&$dots, &$more)
{
    # PLEASE FOR TO BE CACHING ME, OBIWAN...
    # (20110120/straup)
    $w = 11;
    $h = 8.5;
    $margin = 0.5;
    $dpi = 72;
    $header_h = 0.2;
    $row_h = 0.2;
    $col_width = 1.25;
    # Here we go...
    $pdf = new FPDF("P", "in", array($w, $h));
    $pdf->setMargins($margin, $margin);
    # The legend gets added below (once we've figured out what page
    # each dot is on) but we'll just declare it here.
    $legend = array();
    $count_legend_items = floor($h / ($row_h * 1.4));
    $count_clusters = ceil(count($dots) / $count_legend_items);
    # Just turn clusters off for now... the map rendering time
    # is still too long for multiple map images (20110120/straup)
    $count_clusters = 1;
    $clusters = array();
    if ($count_clusters == 1) {
        $clusters = array($dots);
    } else {
        $points = array();
        $i = 0;
        foreach ($dots as $dot) {
            $points[] = array('x' => (double) $dot['longitude'], 'y' => (double) $dot['latitude'], 'id' => $dot['id'], 'idx' => $i);
            $i++;
        }
        $_clusters = kmeans_cluster($points, $count_clusters);
        foreach ($_clusters as $_cluster) {
            $_dots = array();
            foreach ($_cluster as $_pt) {
                $_dots[] = $dots[$pt['idx']];
            }
            $clusters[] = $_dots;
        }
    }
    #
    # First generate all the maps
    #
    $maps = array();
    $img_more = array('width' => $h * $dpi, 'height' => $h * $dpi, 'dot_size' => 15);
    foreach ($clusters as $dots) {
        list($map, $gd_img) = maps_image_for_dots($dots, $img_more);
        $maps[] = maps_gd_to_png($gd_img, 'pdf');
    }
    # Now figure out the what is the what of the dots
    $columns = array();
    $cols_per_page = floor(($w - $margin * 2) / $col_width);
    $count_cols = count($more['columns']);
    $pages_per_row = ceil($count_cols / $cols_per_page);
    # See this? We're adding enough extra columns and re-counting
    # everything in order to ensure that every page for each row
    # has an 'id' column
    if ($pages_per_row > 1) {
        $_count = $count_cols + ($pages_per_row - 1);
        $pages_per_row = ceil($_count / $cols_per_page);
    }
    # First, chunk out the header in (n) pages and measure the
    # height of the (header) row itself
    $_h = $header_h * 1.3;
    $pdf->SetFont('Helvetica', 'B', 10);
    for ($i = 0; $i < $count_cols; $i++) {
        $col_name = $more['columns'][$i];
        $b = floor($i / $cols_per_page);
        if (!is_array($columns[$b])) {
            $columns[] = array();
        }
        $columns[$b][] = $col_name;
        $str_width = ceil($pdf->GetStringWidth($more['columns'][$i]));
        if ($str_width > $col_width) {
            $lines = ceil($str_width / $col_width);
            $_h = max($_h, $lines * $header_h);
        }
    }
    $header_h = $_h;
    # make sure every page has an 'id' field
    # (see above)
    $count_columns = count($columns);
    for ($i = 0; $i < $count_columns; $i++) {
        $cols = $columns[$i];
        if (!in_array('id', $cols)) {
            array_unshift($cols, 'id');
            $columns[$i] = $cols;
        }
        # move stuff around so that we keep the pages nice and tidy
        if (count($columns[$i]) > $cols_per_page) {
            $to_keep = array_slice($columns[$i], 0, $cols_per_page);
            $extra = array_slice($columns[$i], $cols_per_page);
            $columns[$i] = $to_keep;
            $columns[$i + 1] = $extra;
        }
    }
    # Now work out the height of each row of dots
    $row_heights = array();
    $pdf->SetFont('Helvetica', '', 10);
    foreach ($dots as $dot) {
        $_h = $row_h;
        foreach ($dot as $key => $value) {
            $str_width = ceil($pdf->GetStringWidth($value));
            if ($str_width > $col_width) {
                $lines = ceil($str_width / $col_width);
                $_h = max($_h, $lines * $row_h);
            }
        }
        $row_heights[] = $_h * 1.1;
    }
    # Now sort everything in to pages
    $pages = array();
    $page = 0;
    $count_dots = count($dots);
    $dot_idx = 0;
    $y = $margin + $header_h;
    while ($dot_idx < $count_dots) {
        $dot = $dots[$dot_idx];
        $row_height = $row_heights[$dot_idx];
        # will this row bleed off the current page ($page) ?
        $goto_nextpage = 0;
        if ($y + $row_height > $h - $margin * 1.5) {
            $goto_nextpage = 1;
        }
        if ($goto_nextpage) {
            $page += $pages_per_row;
            $y = $margin + $header_h;
        }
        $y += $row_height;
        # set up information for legend
        $legend[$dot['id']] = array('page' => $page + 2, 'id' => $dot['id'], 'latitude' => $dot['latitude'], 'longitude' => $dot['longitude'], 'ymd' => gmdate('Y-m-d', strtotime($dot['created'])));
        #
        $j = 0;
        foreach ($columns as $cols) {
            $_row = array();
            foreach ($cols as $name) {
                $_row[] = $dot[$name];
            }
            $page_idx = $page + $j;
            if (!is_array($pages[$page_idx])) {
                $pages[$page_idx] = array(array('row' => $cols, 'bold' => 1, 'height' => $header_h));
            }
            $pages[$page_idx][] = array('row' => $_row, 'height' => $row_height);
            $j++;
        }
        $dot_idx++;
    }
    #
    # ZOMG... finally publish the thing...
    #
    # First, display all the maps and corresponding
    # legends
    function sort_by_lat($a, $b)
    {
        if ($a['latitude'] == $b['latitude']) {
            return 0;
        }
        return $a['latitude'] > $b['latitude'] ? -1 : 1;
    }
    $count_clusters = count($clusters);
    for ($i = 0; $i < $count_clusters; $i++) {
        $dots = $clusters[$i];
        $_legend = array();
        $j = 0;
        foreach ($dots as $dot) {
            $_legend[$dot['id']] = $legend[$dot['id']];
            $j++;
            if ($j >= $count_legend_items) {
                break;
            }
        }
        usort($_legend, "sort_by_lat");
        $pdf->AddPage();
        $pdf->Image($maps[$i], 0, 0, 0, 0, 'PNG');
        $pdf->SetFont('Helvetica', '', 10);
        $x = $h + $margin;
        $y = $margin;
        foreach ($_legend as $dot) {
            $text = "{$dot['id']} / pg. {$dot['page']}";
            $pdf->SetXY($x, $y);
            $pdf->Cell(0, $row_h, $text);
            $loc = new MMaps_Location($dot['latitude'], $dot['longitude']);
            $pt = $map->locationPoint($loc);
            $x1 = $x - $margin / 8;
            $y1 = $y + $row_h / 2;
            $x2 = $pt->x / $dpi;
            $y2 = $pt->y / $dpi;
            $pdf->Line($x1, $y1, $x2, $y2);
            $y += $row_h * 1.1;
        }
    }
    # Now the rows (of dots)
    foreach ($pages as $page) {
        $pdf->AddPage();
        $x = $margin;
        $y = $margin;
        $z = 0;
        foreach ($page as $data) {
            $style = $data['bold'] ? 'B' : '';
            $pdf->SetFont('Helvetica', $style, 10);
            $x_offset = $col_width * 0.1;
            $y_offset = $data['height'] * 0.1;
            $max_width = $col_width - $x_offset * 3;
            $bg = $z % 2 ? 255 : 235;
            $z++;
            foreach ($data['row'] as $value) {
                $value = trim($value);
                $width = $pdf->GetStringWidth($value);
                $pdf->SetFillColor($bg);
                $pdf->Rect($x, $y, $col_width, $data['height'], 'F');
                # Don't bother with MultiCell - it is behaving
                # badly (20110120/straup)
                if ($width < $max_width) {
                    $pdf->SetXY($x + $x_offset, $y + $y_offset);
                    $pdf->Cell(0, $row_h, $value);
                } else {
                    $_x = $x;
                    $_y = $y;
                    $lines = array();
                    $buffer = '';
                    foreach (str_split($value) as $char) {
                        if ($buffer == '' && $char == ' ') {
                            continue;
                        }
                        $buffer .= $char;
                        $width = $pdf->GetStringWidth($buffer);
                        if ($width >= $max_width) {
                            $lines[] = $buffer;
                            $buffer = '';
                        }
                    }
                    if (strlen($buffer)) {
                        $lines[] = $buffer;
                        $buffer = '';
                    }
                    foreach ($lines as $ln) {
                        $pdf->SetXY($_x + $x_offset, $_y + $y_offset);
                        $pdf->Cell(0, $row_h, $ln);
                        $_y += $row_h * 0.8;
                    }
                }
                $x += $col_width;
            }
            $x = $margin;
            $y += $data['height'];
        }
    }
    # Go!
    $pdf->Close();
    $pdf->Output($more['path'], 'F');
    $pdf = null;
    foreach ($maps as $map_img) {
        if (!unlink($map_img)) {
            error_log("[EXPORT] (pdf) unlink {$map_img} : {$ok}");
        }
    }
    return $more['path'];
}
function EWD_UFAQ_Export_To_PDF()
{
    require_once EWD_UFAQ_CD_PLUGIN_PATH . '/FPDF/fpdf.php';
    if ($Category != "EWD_UFAQ_ALL_CATEGORIES") {
        $category_array = array('taxonomy' => 'ufaq-category', 'field' => 'slug', 'terms' => $Category->slug);
    }
    $params = array('posts_per_page' => -1, 'post_type' => 'ufaq');
    $faqs = get_posts($params);
    $PDFPasses = array("FirstPageRun", "SecondPageRun", "Final");
    foreach ($PDFPasses as $PDFRun) {
        $pdf = new FPDF();
        $pdf->AddPage();
        if ($PDFRun == "SecondPageRun" or $PDFRun == "Final") {
            $pdf->SetFont('Arial', 'B', 14);
            $pdf->Cell(20, 10, "Page #");
            $pdf->Cell(20, 10, "Article Title");
            $pdf->Ln();
            $pdf->SetFont('Arial', '', 12);
            foreach ($ToC as $entry) {
                $pdf->Cell(20, 5, "  " . $entry['page']);
                $pdf->MultiCell(0, 5, $entry['title']);
                $pdf->Ln();
            }
            unset($ToC);
        }
        foreach ($faqs as $faq) {
            $PostTitle = strip_tags(html_entity_decode($faq->post_title));
            $PostText = strip_tags(html_entity_decode($faq->post_content));
            $PostText = str_replace("&#91;", "[", $PostText);
            $PostText = str_replace("&#93;", "]", $PostText);
            $pdf->AddPage();
            $Entry['page'] = $pdf->page;
            $Entry['title'] = $PostTitle;
            $pdf->SetFont('Arial', 'B', 15);
            $pdf->MultiCell(0, 10, $PostTitle);
            $pdf->Ln();
            $pdf->SetFont('Arial', '', 12);
            $pdf->MultiCell(0, 10, $PostText);
            $ToC[] = $Entry;
            unset($Entry);
        }
        if ($PDFRun == "FirstPageRun" or $PDFRun == "SecondPageRun") {
            $pdf->Close();
        }
        if ($PDFRun == "Final") {
            $pdf->Output('Ultimate-FAQ-Manual.pdf', 'D');
        }
    }
}
示例#4
0
 function Close()
 {
     parent::Close();
     // clean up tmp files
     foreach ($this->tmpFiles as $tmp) {
         @unlink($tmp);
     }
 }
示例#5
0
<?php

require dirname(__FILE__) . '/../../pacotes/fpdf/fpdf.php';
include "geraimagens.php";
$pdf = new FPDF("L", "mm", "A4");
$pdf->Open();
$pdf->AddPage();
$pdf->Image($nomemapa, 0, 0, $w - 50, $h - 50, 'PNG');
$pdf->Close();
//$nomepdf = $dir_tmp.'/'.$imgdir.'/'.$nomes.'.pdf';
$pdf->Output("mapa.pdf", true);
示例#6
0
 /**
  * Wrapper for FPDF::Close. It's main purpose is to
  * replace {nb} by our own count and not the number FPDF counted.
  *
  * @author Former03 GmbH :: Florian Lippert <*****@*****.**>
  */
 function Close()
 {
     // taken from original fpdf-class
     $nb = $this->page;
     if (!empty($this->AliasNbPages)) {
         //Replace number of pages
         for ($n = 1; $n <= $nb; $n++) {
             $this->pages[$n] = str_replace($this->AliasNbPages, $this->_my_page_count, $this->pages[$n]);
         }
     }
     parent::Close();
 }
示例#7
0
 public function preparePdf()
 {
     $genPdf = new FPDF();
     $recipients = Campaign::getRecipients($this->group);
     $genPdf->AddPage();
     $genPdf->SetFont('Arial', 'B', "9px");
     foreach ($recipients as &$recipient) {
         if (!is_null($recipient->getHash($this->id))) {
             $genPdf->Cell("100%", "12px", $this->name . " Voter: " . $recipient->getName(), "LBT", 0);
             $genPdf->Cell("95%", "12px", "Hash: " . $recipient->getHash($this->getId()), "RBT", 1, 'R');
         }
     }
     $genPdf->Output();
     $genPdf->Close();
 }
示例#8
0
    public static function createEmptyRenderError($filename,$filepath){


        require_once(Yii::app()->basePath.'/extensions/Fpdf/fpdf.php');

        $pdf = new FPDF('P','mm','Letter');

        $pdf->SetAuthor('ASA AP');
        $pdf->SetTitle('Render error');
        //set font for the entire document
        $pdf->SetFont('Helvetica','B',20);
        $pdf->SetTextColor(255,0,0);
        //set up a page
        $pdf->AddPage('P');
        $pdf->SetDisplayMode(90,'default');

        //Set x and y position for the main text, reduce font size and write content
        $pdf->SetXY (30,55);
        $pdf->SetFontSize(15);
        $pdf->Write(5,'Existing document '.$filename.' can\'t be rendered');
        //Output the document
        $pdf->Output($filepath,'F');
        $pdf->Close();

        return $filepath;
    }
示例#9
0
function printFPDF($pdfobj){

	require('fpdf/fpdf.php');

	$DIRPATH = $_SERVER['SCRIPT_FILENAME'];

	// remove the file name and append the new directory name
	if (PHP_OS == "WINNT" || PHP_OS == "WIN32") {
		$pos1 = strrpos($DIRPATH,'\\');
		$DIRPATH= substr($DIRPATH,0,$pos1)."\\pdf\\";
	}else{
		$pos1 = strrpos($DIRPATH,'/');
		$DIRPATH= substr($DIRPATH,0,$pos1)."/pdf/";
	}
	$pdf_FILE_NAME = session_id(). "MapLocator.pdf";
	$pdf_FILE_PATH = $DIRPATH. $pdf_FILE_NAME ;

	$pdf = new FPDF('P', 'pt', array(640,450));
	$pdf->AddPage();
	$pdf->SetFont('Arial','B',10);

	$domain = getenv("HTTP_HOST");

	//base map
	$base_url = $pdfobj->BaseUrl;
	$base_url = str_replace(' and ','&' ,$base_url);

	if (strpos($base_url,'http://') === false) {
		//since client sends only relative path a full http url needs to constructed here
		$base_url = 'http://'. $domain. $base_url;
		//echo 'here';
	}


	$base_image = createImageForPDF($base_url,$DIRPATH.'base');
	$base_image_jpeg = $DIRPATH.'base'.session_id() .'.jpeg';
	png2jpg($base_image, $base_image_jpeg, 100);

	$layerURL = $pdfobj->LayerURL;

	$layerURL = str_replace(' and ','&' ,$layerURL );

	//since client sends only relative path a full http url needs to constructed here
	$layerURL = 'http://'. $domain. $layerURL;
	$layer = $pdfobj->Layer;
	$legendURL = $pdfobj->LegendURL;
	$legendURL = 'http://'. $domain. $legendURL;
	$legendURL = str_replace(' and ','&' ,$legendURL );

	$image = createImageForPDF($layerURL,$DIRPATH.$layer);

	$image_jpeg = $DIRPATH.$layer.session_id() .'.jpeg';
	png2jpg($image, $image_jpeg, 100);

	$url = 'http://'. $domain. base_path().'ImageMerge.php?baseimage='.$base_image_jpeg.'&overlayimage='.			$image_jpeg;

	$merged_image_buff = file_get_contents($url);

	$final_image =$DIRPATH.'merge.jpeg';

	$fh = fopen($final_image,"w");
  	fwrite($fh,$merged_image_buff);
	fclose($fh);


	$pdf->Image($final_image,0,30);

	$image = createImageForPDF($legendURL,$DIRPATH.$layer.'_legend');
	$image_jpeg = $DIRPATH.$layer.'_legend'.session_id() .'.jpeg';
	png2jpg($image, $image_jpeg, 100);
	$size = getimagesize($image);
	$width = $size[0];
	$height = $size[1];



	$pdf->sety(25);
	$pdf->Cell(0,0,"Layer Name: ". $pdfobj->LayerName);


	$top_scale = $pdfobj->TopScale;
	$bottom_scale = $pdfobj->BottomScale;


	$pdf->Text(0,430,"Scalebar: ");
	$pdf->Text(50,430,"| ".$top_scale." |");
	$pdf->Text(50,430,"  _____ ");
	$pdf->Text(50,440,"| ".$bottom_scale." |");
	$pdf->Text(475,445,"Created by Map Locator");


	if($width < 100){//show legend on the map/same page
		$pdf->Image($image_jpeg,640 - $width,30);
		$pdf->sety(20);
		$pdf->setX(-75);
		$pdf->Cell(20,10,"Legend ");
	}else{//show legend on the next page
		$pdf->AddPage();
		$pdf->Image($image_jpeg,0,30);
		$pdf->sety(20);
		$pdf->setX(5);
		$pdf->Cell(20,10,"Legend ");
	}



	$pdf->Output($pdf_FILE_PATH,'F');
	$pdf->Close();
	return $pdf_FILE_NAME;


}
示例#10
0
 function sign_pdf()
 {
     global $FANNIE_ROOT;
     $desc = isset($_REQUEST['desc']) ? $_REQUEST['desc'] : '&nbsp;';
     $price = isset($_REQUEST['price']) ? $_REQUEST['price'] : '&nbsp;';
     if (isset($_REQUEST['scale']) && $_REQUEST['scale'] == 1) {
         $price .= " / lb";
     }
     $price = '$' . $price;
     $origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : '&nbsp;';
     require $FANNIE_ROOT . 'src/fpdf/fpdf.php';
     define('FPDF_FONTPATH', $FANNIE_ROOT . 'src/fpdf/font/');
     $pdf = new FPDF('L', 'in', 'Letter');
     $pdf->SetMargins(0.59, 0.25, 0.59);
     $pdf->SetAutoPageBreak(False, 0.25);
     $pdf->AddPage();
     $pdf->AddFont('ScalaSans-Bold', 'B', 'ScalaSans-Bold.php');
     $pdf->AddFont('ScalaSans', '', 'ScalaSans.php');
     $pdf->SetFont('ScalaSans', '', 22);
     $pdf->SetXY(0.25, 5.87);
     $pdf->Cell(5.26, 0.54, $desc, 1, 0, 'C');
     $pdf->SetFont('ScalaSans-Bold', 'B', 70);
     $pdf->SetXY(0.25, 6.41);
     $pdf->Cell(5.26, 1.3, $price, 1, 0, 'C');
     $pdf->SetXY(0.25, 7.71);
     $pdf->SetFont('ScalaSans', '', 18);
     $pdf->Cell(5.26, 0.54, $origin, 1, 0, 'L');
     $pdf->Close();
     $pdf->Output("sign.pdf", "I");
 }
 /**
  * valida email
  * @param string $email
  */
 public function geraProcessosDetran($orgao, $resultado, $anexar, $id_empresa, $id_usuario, $id_pedido, $ordem, $res_oficio)
 {
     if ($orgao == '') {
         $orgao = 'Detran';
     }
     if ($resultado == '') {
         $resultado = 'Nada Constou';
     }
     // Variaveis de Tamanho
     $mesq = "10";
     // Margem Esquerda (mm)
     $msup = "10";
     // Margem Superior (mm) margem mínima dois pois ficou cortando)
     /*Uma dica: estes tamanhos você pode verificar com uma régua ou na própria caixa da etiqueta, seja bem preciso e sugiro que faça o teste na impressora que vai ser utilizada, pois pode acontecer de na impressão começar a subir ou descer, portanto, você deverá aumentar ou diminuir a altura da etiqueta.
      */
     $m = date(m);
     $mes = traduzMes($m);
     $anexoDAO = new AnexoDAO();
     $impressoDAO = new ImpressoDAO();
     $atividadeDAO = new AtividadeDAO();
     $res = $impressoDAO->buscaPorId(28);
     $imprimir_topo = $res->topo;
     $id_impresso = $res->id_impresso;
     $imprimir_timbre = $res->timbre;
     $imprimir_sub = $res->sub;
     $imprimir_linha = $res->linhas;
     $frase = '';
     #if($anexar!='on'){
     $pdf = new FPDF('P', 'cm', 'A4');
     //papel personalizado
     $pdf->Open();
     $pdf->SetMargins(1, 2);
     //seta as margens do documento
     $pdf->SetAuthor('Softfox 2011');
     $pdf->SetFont('times', '', 7);
     $pdf->SetDisplayMode(100, 'continuous');
     //define o nivel de zoom do documento PDF
     $coluna = 0;
     $linha = 0;
     $posicaoH = 0;
     $posicaoV = 0;
     #}
     $impressao_ordem = '';
     $linha = 0;
     $frase .= $imprimir_topo;
     $bloco = '';
     if ($res_oficio->id_pedido != '') {
         $linha_bloco = 1;
         $orgao_regiao = $res_oficio->certidao_cidade;
         $orgao_regiao .= '-' . $res_oficio->certidao_estado;
         $impressao_ordem = '#' . $res_oficio->id_pedido . '/' . $res_oficio->ordem . ' ';
         $responsavel_endereco = $res_oficio->endereco . ' ' . $res_oficio->numero . ' ' . $res_oficio->complemento;
         $data_atual = $res_oficio->cidade . ', ' . date(d) . ' de ' . $mes . ' de 20' . date(y) . '.';
         $topo = str_replace('<certidao_nome>', $res_oficio->certidao_nome, $imprimir_topo);
         $topo = str_replace('<certidao_cnpj>', $res_oficio->certidao_cnpj, $topo);
         $topo = str_replace('<certidao_cpf>', $res_oficio->certidao_cpf, $topo);
         $topo = str_replace('<orgao>', $orgao, $topo);
         $topo = str_replace("<resultado>", $resultado, $topo);
         $topo = str_replace("<orgao_regiao>", $orgao_regiao, $topo);
         $topo = str_replace('<responsavel_empresa>', $res_oficio->fantasia, $topo);
         $topo = str_replace('<responsavel_endereco>', $responsavel_endereco, $topo);
         $topo = str_replace('<responsavel_cidade>', $res_oficio->cidade, $topo);
         $topo = str_replace('<responsavel_estado>', $res_oficio->estado, $topo);
         $topo = str_replace("<data>", $data_atual, $topo);
         $topo = str_replace('<impressao_ordem>', $impressao_ordem, $topo);
         $sub = str_replace('<responsavel_empresa>', $res_oficio->fantasia, $imprimir_sub);
         $sub = str_replace('<responsavel_endereco>', $responsavel_endereco, $sub);
         $sub = str_replace('<responsavel_cidade>', $res_oficio->cidade, $sub);
         $sub = str_replace('<responsavel_estado>', $res_oficio->estado, $sub);
         $sub = str_replace('<responsavel_cep>', $res_oficio->cep, $sub);
         $sub = str_replace('<responsavel_tel>', $res_oficio->tel, $sub);
         $sub = str_replace('<responsavel_fax>', $res_oficio->fax, $sub);
         $sub = str_replace('<responsavel_email>', $res_oficio->email, $sub);
         $pdf->AddPage();
         $pdf->Image('../images/header.jpg', '0', '0', '19', '3,04', 'JPG');
         $pdf->SetFont('', 'B', 12);
         $pdf->Cell('', 2, 'NÃO EMITIMOS E NEM VENDEMOS CERTIDÕES E SIM PRAZOS E SOLUÇÕES', '', 1, 'C');
         $pdf->SetFont('', 'B', 14);
         $pdf->Cell('', 2, 'Declaração de Busca', '', 1, 'C');
         $pdf->SetFont('', '', 12);
         $pdf->Write(1, $topo, '');
         $pdf->SetFont('', '', 12);
         $pdf->Cell('', 1, '', '', 1, 'C');
         $pdf->Cell('', 1, '', '', 1, 'C');
         $pdf->Cell('', 1, '', '', 1, 'C');
         $pdf->Cell('', 1, '', '', 1, 'C');
         $pdf->Cell('', 1, '', '', 1, 'C');
         $pdf->Cell('', 1, '', '', 1, 'C');
         $pdf->Cell('', 1, $data_atual, '', 1, 'C');
         $pdf->Cell('', 1, $impressao_ordem, '', 1, 'R');
         $pdf->ln();
         $pdf->ln();
         $pdf->ln();
         $pdf->ln();
         $pdf->Cell('', 1, $res_oficio->fantasia, '', 1, 'C');
         $pdf->ln();
         $pdf->ln();
         $pdf->Write(0.5, $sub, '');
         $pdf->Line(1, 25, 20, 25);
         $pdf->Ln();
         $pdf->Cell('', 0.5, $rodape, '', 1, 'C');
         $rodape = $responsavel_endereco . ', ' . $res_oficio->cidade . '-' . $res_oficio->estado . ' CEP: ' . $res_oficio->cep;
         $pdf->Cell('', 0.5, $rodape, '', 1, 'C');
         $rodape = 'Tel/Fax: ' . $res_oficio->tel . '/' . $res_oficio->fax . ' E-mail:' . $res_oficio->email;
         $pdf->Cell('', 0.5, $rodape, '', 1, 'C');
         $rodape = 'www.cartoriopostal.com.br';
         $pdf->Cell('', 0.5, $rodape, '', 1, 'C');
         if ($anexar == 'on' and $res_oficio->id_servico == '16') {
             $pdf->Close();
             //imprime a saida
             $num_a = $anexoDAO->listaAnexoPedidoNome($res_oficio->id_pedido_item, 'Declaração de Busca');
             if (COUNT($num_a) == 0) {
                 $file_path = "../anexosnovos/" . date('m') . '' . date('Y') . '/';
                 #alterado => "../anexos/"
                 if (!is_dir($file_path)) {
                     mkdir($file_path, 0777);
                 }
                 #alterado
                 $arq_anexo = $file_path . 'decla_busca_' . $res_oficio->id_pedido_item . '_' . time() . '.pdf';
                 $pdf->Output($arq_anexo, 'F');
                 //imprime a saida
                 $anexo->anexo = $arq_anexo;
                 $anexo->anexo_nome = 'Declaração de Busca';
                 $anexo->id_pedido_item = $res_oficio->id_pedido_item;
                 $anexo->id_usuario = $id_usuario;
                 $anexoDAO->inserir($anexo);
                 $ativ = $atividadeDAO->inserir('209', '', $id_usuario, $res_oficio->id_pedido_item);
                 return 'Declaração anexada para ' . $impressao_ordem . '<br>';
             } else {
                 return 'Declaração não pode ser anexada para ' . $impressao_ordem . ' porque o anexo já existe<br>';
             }
         } else {
             if ($anexar == 'on' and $res_oficio->id_servico != '16') {
                 return '<b>Declaração não pode ser anexada para ' . $impressao_ordem . ' porque o serviço não é "Pesquisa Detran</b>"<br>';
             }
         }
     }
     if ($anexar != 'on') {
         return $pdf->Output();
         //imprime a saida
     } else {
         return 1;
     }
 }