Foros del Web » Programando para Internet » PHP »

Hosting sin soporte para PDFlib

Estas en el tema de Hosting sin soporte para PDFlib en el foro de PHP en Foros del Web. Hola, instale una web de otro hosting en mi hosting y la web usa PDFlib para generar reportes sobre clientes pero me salta el error ...
  #1 (permalink)  
Antiguo 04/07/2011, 03:12
 
Fecha de Ingreso: junio-2011
Ubicación: Marbella
Mensajes: 10
Antigüedad: 15 años, 3 meses
Puntos: 0
Hosting sin soporte para PDFlib

Hola, instale una web de otro hosting en mi hosting y la web usa PDFlib para generar reportes sobre clientes pero me salta el error "El archivo no empieza por '%PDF-" siempre, contacte con el soporte del hosting (yoursite.ch) y me dicen que no dan soporte a PDFlib pero si a FPDFlib. ¿Cual es la forma mas rapida de solucionarlo? pego aqui el archivo completo que genera el pdf pero creo que las funciones entre uno y otro son distintas. No hay alguna manera de simplemente hacer funcionar el PDFlib en este hosting?
  #2 (permalink)  
Antiguo 04/07/2011, 03:13
 
Fecha de Ingreso: junio-2011
Ubicación: Marbella
Mensajes: 10
Antigüedad: 15 años, 3 meses
Puntos: 0
Respuesta: Hosting sin soporte para PDFlib

Código PHP:
<?PHP

class pdf  {
    
    var 
$p;
    
    function 
generate_pdf ($page_method, $table_name, $table_key_name, $table_key_values) {
        if  (!
defined("CURRENCY_SYMBOL_PRINT")) {
            
define("CURRENCY_SYMBOL_PRINT","$");
        }
        global 
$db_hostname;
        global 
$db_user;
        global 
$db_password;
        global 
$db_name;
        global 
$db_type;
        
$user_serial = false;
        
$company_serial = false;
        
        if (!
$table_name || !$table_key_name || !$table_key_values) {
            return 
false;
        }
        
$this->conn = &ADONewConnection($db_type);
        
$this->conn->PConnect($db_hostname,$db_user,$db_password,$db_name);
        
$this->conn->SetFetchMode(ADODB_FETCH_ASSOC);
        if (!empty(
$GLOBALS['debug_mode'])) {
            
$this->conn->debug=$GLOBALS['debug_mode'];
        } else {
            
$this->conn->debug=false;
        }            
        
        
$data_class = new data_class;
        
$variable_array = $data_class->variable_array($page_method);
        
$need_comma=false;
        
$foreign_tables=null;
        
$extra_where_clauses= ' ' . $table_key_name . ' in (' . $table_key_values . ') ';
        
$foreign_where_clause= null;
        
$foreign_table_name_posix=1;
        
$order_by_clause=null;
        
$query_sql = 'select ';
        
$need_where = true;
        
        
$query_sql .= ' * ';
        
// get the field names required
        
        
foreach ($variable_array as $key=>$value) {
            if (isset(
$value['field_order_by']) && $value['field_order_by']) {
                if (
$order_by_clause) {
                    if (isset(
$value['field_order_by_reverse']) && $value['field_order_by_reverse']) {
                        
$order_by_clause .= ', ' . $key . ' DESC ';
                    } else {
                        
$order_by_clause .= ', ' . $key . ' ';
                    }
                } else {
                    if (isset(
$value['field_order_by_reverse']) && $value['field_order_by_reverse']) {
                        
$order_by_clause .= ' order by ' . $key . ' DESC ';
                    } else {
                        
$order_by_clause .= ' order by ' . $key . ' ';
                    }
                }
            }
            
$need_comma=true;
        }
        
        
$query_sql .= " from " . $table_name;
        
        if (
$extra_where_clauses) {
            if (
$need_where) {
                
$query_sql .= " where ";
            } else {
                
$query_sql .= " and ";
            }
            
$need_where = false;
            
$query_sql .= $extra_where_clauses;
        }
        if (
$order_by_clause) {
            
$query_sql .= $order_by_clause;
        }
        
        
$rs = $this->conn->Execute($query_sql);
        
        if (!
$rs) {
            
// This means the record was not found
            
return false;
        } else {
            
/* This is where font/image/PDF input files live. Adjust as necessary. */
            
$searchpath = BASE_DIR . '/pdf/data';
            
            
PDF_set_parameter($this->p, "SearchPath", $searchpath);
            
PDF_set_value($this->p, "compress", 9);
            
            
PDF_set_info($this->p, "Creator", "PDFlib");
            
PDF_set_info($this->p, "Author", SYSTEM_NAME);
            
PDF_set_info($this->p, "Title", 'Land Document');
            
            
$query_sql = 'select distinct template_serial from template, deal, company where deal.deal_serial in (' . $table_key_values . ') and deal.deal_company_serial = company.company_serial and template.template_serial = company.company_template_serial';
            
$rs_template = $this->conn->Execute($query_sql);
            if (!
$template = $rs_template->FetchRow()) {
                return 
false;
            } else {
                
// Let's generate the pdf
                
$infile = BASE_DIR . '/templates/template_' . $template['template_serial'] . '.pdf';
                
$blockcontainer = PDF_open_pdi($this->p, $infile, "", 0);
                if (
$blockcontainer == 0){
                    die (
"Couldn't open input file $infile.\n");
                }
                
                while (
$data = $rs->FetchRow()) {
                    for (
$page_number=1; $page_number < 14; $page_number++) {
                        
$page = PDF_open_pdi_page($this->p, $blockcontainer, $page_number, "");
                        if (
$page == 0){
                            
// no problem just break out of the for loop
                            
continue;
                        }
                        
PDF_begin_page($this->p, 20, 20);        /* dummy page size */
                        
                        /* This will adjust the page size to the block container's size. */
                        
PDF_fit_pdi_page($this->p, $page, 0, 0, "adjustpage");
                        
/* Fill all text blocks with dynamic data */
                        
foreach ($variable_array as $key=>$value) {
                            
$i=0;
                            while (
$blockname = PDF_get_pdi_parameter($this->p, "vdp/Blocks[$i]/Name", $blockcontainer, $page, 0)) {
                                if (
$blockname == $key || ((strpos($key, '___') === (strlen($key) - 4)) && $blockname == $key)) {
                                    if (
strpos($key, '___') === (strlen($key) - 4)) {
                                        
$key = substr($key, 0 ,strlen($key) - 4);
                                    }
                                    if (isset(
$data[$key]) && !empty($data[$key]) && ($value['field_type'] == 'text' || $value['field_type'] == 'select' || $value['field_type'] == 'hidden' || $value['field_type'] == 'key')) {
                                        
$suffix = null;
                                        
$prefix = null;
                                        
$suffix = PDF_get_pdi_parameter($this->p, "vdp/Blocks/$blockname/Custom/suffix", $blockcontainer, $page, 0);
                                        
$prefix = PDF_get_pdi_parameter($this->p, "vdp/Blocks/$blockname/Custom/prefix", $blockcontainer, $page, 0);
                                        
                                        if (
$value['field_value_type'] == 'currency') {
                                            if (isset(
$data[$key . '_poa']) && $data[$key . '_poa']) {
                                                
$temp_value = 'P.O.A.';
                                            } else {
  #3 (permalink)  
Antiguo 04/07/2011, 03:14
 
Fecha de Ingreso: junio-2011
Ubicación: Marbella
Mensajes: 10
Antigüedad: 15 años, 3 meses
Puntos: 0
Respuesta: Hosting sin soporte para PDFlib

Código PHP:
$show_currency_symbol = PDF_get_pdi_parameter($this->p, "vdp/Blocks/$blockname/Custom/show_currency_symbol", $blockcontainer, $page, 0);
                                                if (
$key == 'deal_stock_price_per_share') {
                                                    
$number_decimals = 3;
                                                } else {
                                                    
$number_decimals = 0;
                                                }
                                                if (
$show_currency_symbol == 'no') {
                                                    
$temp_value = number_format($data[$key], $number_decimals);
                                                } else {
                                                    
$temp_value = CURRENCY_SYMBOL_PRINT . ' ' . number_format($data[$key], $number_decimals);
                                                }
                                            }
                                        } elseif (
$value['field_value_type'] == 'date') {
                                            
$temp_value = date("F d, Y", strtotime($data[$key]));
                                        } elseif (
$value['field_value_type'] == 'timestamp') {
                                            
$temp_value = date("D d, M Y, h:i", $data[$key]);
                                        } elseif ((
$value['field_type'] == 'select' && $value['field_select_type'] == 'foreign_key') ||
                                        (
$value['field_type'] == 'hidden' && isset($value['field_select_type']) && $value['field_select_type'] == 'foreign_key') ) {
                                            
$sub_query_sql = null;
                                            
$show_boolean = PDF_get_pdi_parameter($this->p, "vdp/Blocks/$blockname/Custom/show_boolean", $blockcontainer, $page, 0);
                                            
                                            if (
$show_boolean == 'yes' && isset($value['field_select_boolean_name'])) {
                                                
$sub_query_sql .= 'select ' . $value['field_select_boolean_name'] . ' from ' . $value['field_select_foreign_key_table'] . ' ';
                                            } else {
                                                
$sub_query_sql .= 'select ' . $value['field_select_foreign_key'] . ' from ' . $value['field_select_foreign_key_table'] . ' ';
                                            }
                                            
$sub_query_sql .= ' where ' . $value['field_select_foreign_key_serial'] . '=\'' .    $data[$key] . '\'';
                                            
$rs_sub = $this->conn->Execute($sub_query_sql);
                                            if (!
$rs_sub || $rs_sub->RecordCount() != 1) {
                                                
// This means the record was not found
                                                // So we print nothing
                                                
$temp_value = null;
                                            } else {
                                                
$sub_data = $rs_sub->fields;
                                                if (
$show_boolean == 'yes') {
                                                    
$temp_value = $sub_data[$value['field_select_boolean_name']];
                                                    if (
$temp_value == 1) {
                                                        
$temp_value = $prefix . 'yes' . $suffix;
                                                    } else {
                                                        
$temp_value = $prefix . 'no' . $suffix;
                                                    }
                                                } else {
                                                    
$temp_value = $sub_data[$value['field_select_foreign_key']];
                                                    
$temp_value = $prefix . $temp_value . $suffix;
                                                }
                                            }
                                        } else {
                                            
$temp_value = $prefix . $data[$key] . $suffix;
                                        }
                                        if (!
PDF_fill_textblock($this->p, $page, $blockname, $temp_value, "embedding encoding winansi pdiwarning")) {
                                            
printf("Warning: couldn't fill block '%s' in '%s'.\n", $blockname, $infile);
                                        }
                                    } elseif (
$value['field_type'] == 'textarea') {
                                        
$temp_value = stripslashes((trim($data[$key])));
                                        
$fontsize = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/fontsize", $blockcontainer, $page, 0);
                                        
$fontname = PDF_get_pdi_parameter($this->p, "vdp/Blocks[$i]/fontname", $blockcontainer, $page, 0);
                                        
$lleftx = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[0]", $blockcontainer, $page, 0);
                                        
$llefty = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[1]", $blockcontainer, $page, 0);
                                        
$urightx = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[2]", $blockcontainer, $page, 0);
                                        
$urighty = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[3]", $blockcontainer, $page, 0);
                                        
$regularfont = PDF_load_font($this->p, $fontname, "winansi", "");
                                        
PDF_setfont($this->p, $regularfont, $fontsize);
                                        
$leading = $fontsize + 2;
                                        
PDF_set_value($this->p, "leading", $leading);
                                        while (
PDF_show_boxed($this->p, $temp_value, $lleftx, $llefty, $urightx - $lleftx,
                                        
$urighty - $llefty, 'justify', 'blind') != 0) {
                                            
$fontsize = $fontsize - 0.5;
                                            
PDF_setfont($this->p, $regularfont, $fontsize);
                                            
$leading = $fontsize + 2;
                                            
PDF_set_value($this->p, "leading", $leading);
                                        }
                                        
PDF_show_boxed($this->p, $temp_value, $lleftx, $llefty, $urightx - $lleftx,
                                        
$urighty - $llefty, 'justify');
                                    }
                                }
                                
$i++;
                            }
                        }
                        
                        
PDF_end_page($this->p);            /* close page */
                        
PDF_close_pdi_page($this->p, $page);
                    }
                }
                
            }
            
PDF_close_pdi($this->p, $blockcontainer);
            
PDF_close($this->p);                /* close PDF document */
            
            
return true;
        }
    }
    
    function 
display_pdf ($page_method, $table_name, $table_key_name, $table_key_values) {

        
header("Content-type: application/pdf");
        if (
strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'contype') === false) {
            
$this->p = PDF_new();
            if ( !
strchr($_SERVER['SERVER_SOFTWARE'], 'Win32')) {
                
PDF_set_parameter($this->p, 'license', 'L500602-010000');
            }

            
/*  open new PDF file; insert a file name to create the PDF on disk */
            
PDF_open_file($this->p, null);

            if (
$this->generate_pdf ($page_method, $table_name, $table_key_name, $table_key_values)) {
                
//$buf = PDF_get_buffer($this->p);
                //$len = strlen($buf);

                
header("Content-Disposition: inline; filename=tp1.pdf");
                print 
PDF_get_buffer($this->p);

                
PDF_delete($this->p);                /* delete the PDFlib object */
                
return true;
            } else {
                
PDF_delete($this->p);                /* delete the PDFlib object */
                
return false;
            }
        }

    }
    
    function 
generate_pdf_file ($page_method, $table_name, $table_key_name, $table_key_values) {
        
        
        
$filename = '/tmp/tp1_' . str_replace(',', '_', $table_key_values . '.pdf');
        
$this->p = PDF_new();
        
PDF_set_parameter($this->p, 'license', 'L500602-010000');
        
        
/*  open new PDF file; insert a file name to create the PDF on disk */
        
PDF_open_file($this->p, $filename);
        
        if (
$this->generate_pdf ($page_method, $table_name, $table_key_name, $table_key_values)) {
            
PDF_delete($this->p);                /* delete the PDFlib object */
            
return $filename;
        } else {
            
PDF_delete($this->p);                /* delete the PDFlib object */
            
return false;
        }
    }
}
?> 

Etiquetas: hosting, pdflib, soporte
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:40.