Hola a todos,
¿Existe alguna manera de fusionar datos en un fichero PDF de manera 'nativa' desde FWH?
Gracias,
Un Saludo
Carlos G.
FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home
Hola a todos,
¿Existe alguna manera de fusionar datos en un fichero PDF de manera 'nativa' desde FWH?
Gracias,
Un Saludo
Carlos G.
FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home
function MakeFDF( $data, $filefdf )
{
$fdf = '%FDF-1.2
1 0 obj<</FDF<< /Fields[';
foreach ( $data as $key => $value )
{
$fdf .= '<</T(' . $key . ')/V(' . utf8_decode( $value ) . ')>>';
}
$fdf .= '] >> >>
endobj
trailer
<</Root 1 0 R>>
%%EOF';
return ( file_put_contents( $filefdf, $fdf ) > 0 );
}
/*----------------------------------------------------------------------------*/
function BuildPDF( $aFV, $nNF )
{
$cBinPDFTK = 'pdftk';
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' )
{
$cBinPDFTK = '.\pdftk.exe';
}
if( ! MakeFDF( $aFV, 'tmp/filldata.fdf' ) )
{
$aRet = array( 'pdf_created' => false, 'error' => 'File < filldata.fdf > not created.' );
return $aRet;
}
else
{
if ( !file_exists( $cBinPDFTK ) )
{
$aRet = array( 'pdf_created' => false, 'error' => 'Binary of PDFTK not found in server host.' );
return $aRet;
}
else
{
$cFilePdf = "tmp/invoice_" . $nNF . ".pdf";
$cRunCmd = $cBinPDFTK . " ./roc.pdf fill_form tmp/filldata.fdf output $cFilePdf flatten";
//TLog( $cRunCmd );
exec( $cRunCmd );
if ( file_exists( 'tmp/filldata.fdf' ) )
{
unlink( 'tmp/filldata.fdf' );
}
if( file_exists( $cFilePdf ) )
{
$aRet = array( 'pdf_created' => true, 'filename' => $cFilePdf );
}
else
{
$aRet = array( 'pdf_created' => false, 'error' => 'Not created pdf < invoice.pdf >.' );
}
}
}
return $aRet;
}Muchas gracias Carlos,
Asà es como lo hago actualmente usando Pdftk.exe; de aà que preguntara de manera 'nativa' con Harbour o FWH.
He vuelto a tocar una aplicación de hace tiempo y me gustarÃa eliminar terceros productos para facilitar la compatibilidad en adelante.
Lo dicho muchas gracias
Un Saludo
Carlos G.
FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home
Carlos, el fichero PDF original lo tienes ya creado o lo puedes crear tú en el momento que lo necesitas?
Lo digo porque como bien sabes, FWH permite de forma nativa crear PDFS sin herramientas de terceros.

Buenas master Carlos, como funciona FoxitPhantomPDF? Gracias. Saludos.
cnavarro wrote:Carlos, el fichero PDF original lo tienes ya creado o lo puedes crear tú en el momento que lo necesitas?
Lo digo porque como bien sabes, FWH permite de forma nativa crear PDFS sin herramientas de terceros.
pues no es dificil, yo lo hago asi: con un programa como powerpoint o publisher de microsoft diseño mi documento, luego lo exporto a pdf,
ya ahi lo abro con el FoxitPhantomPDF y en la pestaña form estan los contoles (texbox, chechkbox, radio, etc), agrego uno a uno los campos que necesito, al campo se le da un nombre y atributos como fuente, color y tamaño.
y listo. Por cierto si puedes crear el pdf desde fwh con haru por ejemplo. lo que no se es si es posible agrager controles de escrituras, eso repito lo hago con el phantom.
ya es un pdf con un form interno. (PDF Filleable)
el nombre que le des al campo es el que usaras para crear la plantilla FDF, de eso hay muchos ejemplos en google, usando pdftk o php.
es sencillo una vez que le agarras el truco. El master Carles aruba lo implemento en fweb y tweb y ahi fue que aprendi a usar y crear los pdf.
en la imagen que adjunte pueden ver los recuadros en el pdf que contiene los campos, lo unico que ahi el nombre que uso el que los creo uso nombres largisimos y complejos para diferenciar paginas, secciones, etc. (topmostSubform[0].Page1[0].EmployeeName[0].f1_1[0]) no se asusten, ahi pueden usar por ejemplo un nombre secillo como "NOMBRE_EMPLEADO" y listo. ![]()
salu2
Muchas gracias a todos por el interés.
De momento yo 'creo' el PDF con word, con PDFESCAPE on line, le añado los campos y luego con PDFTK fusiono con los datos.
Hasta ahora sin problemas excepto si el PDF creado está abierto e intento volverlo a crear con PDFTK.
Lo de crear el PDF desde 'cero' con FiveWin, de momento y mientras no tenga más tiempo, lo dejo; se me hace pesado y lo tendré en cuenta cuando algún dÃa de estos deba ponerme si o si.
Lo dicho, muchas gracias por la información.
Un Saludo
Carlos G.
FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home
Hola Carlos Vargas: pudieras poner un ejemplo de fusionar datos con PDF en TWeb?
El foro de TWeb sale que está en mantenimiento hace un par de dÃas es por eso que consulto aquÃ.
Desde ya muchas gracias.
Hola caducca,
el nuevo foro de mod-harbour con TWeb, Mercury...
<?php
include( 'fweb/fweb.php' );
include( 'fweb/tdatabase.php' );
include( 'config.php' );
include( 'project_oc.php' );
include( 'myfunctions.php' );
include( 'myfunctions2.php' );
include_once( 'vendorinfo.php' );
$oAcces = new TAcces( 'index.php' );
$oAcces->Valid();
$cYear = $oAcces->GetVar( 'VA_YEAR' );
$cCiaEin = fwGetSV( 'SP_CIAEIN' );
$nCountEmployee = fwGetSV( 'SP_COUNT_EMPLOYEE' );
$lCorrected = fwGetSV( 'SP_CORRECTED' );
$oDb = new TDatabase( DB_SERVER, DB_USER, DB_PSW, DB_DATABASE );
$oDb->lLog = false;
$lError = false;
$cSql = "select * from COMPANY_$cYear as A where A.CIA_EIN='" . $cCiaEin . "' LIMIT 1";
if ( !$oDb->IsError() && $oDb->Open( $cSql ) )
{
if( $oDb->RecCount() == 1 )
{
$aData = array( 'found' => true,
'corrected' => $lCorrected,
'cia_name' => $oDb->Get( 'CIA_NAME' ),
'cia_ein' => $oDb->Get( 'CIA_EIN' ),
'cia_address' => $oDb->Get( 'CIA_ADDRESS' ),
'cia_city' => $oDb->Get( 'CIA_CITY' ),
'cia_state' => $oDb->Get( 'CIA_STATE' ),
'cia_zip' => $oDb->Get( 'CIA_ZIP' ),
'contact_name' => X_CONTACT1_FIRSTNAME . ' ' . X_CONTACT1_LASTNAME,
'contact_phone' => X_CONTACT1_PHONE,
'cia_dge_name' => '',
'cia_dge_ein' => '',
'cia_dge_address' => '',
'cia_dge_city' => '',
'cia_dge_state' => '',
'cia_dge_zip' => '',
'cia_dge_contact_name' => '',
'cia_dge_contact_phone' => '',
'count_employee' => $nCountEmployee );
$aAle = array();
$cSql = "select A.EIN, A.NAME from ALE_$cYear as A where A.CIA_EIN='" . $cCiaEin . "'";
if ( $oDb->Open( $cSql ) )
{
$aAle = array();
while ( !$oDb->Eof() )
{
array_push( $aAle, array( 'ein' => $oDb->Get( 'EIN' ), 'name' => $oDb->Get( 'NAME' ) ) );
$oDb->Skip();
}
$aData[ 'ale_members' ] = $aAle;
}
else
{
$lError = true;
$aRet = array( 'pdf_created' => false, 'error' => $oDb->Error() );
}
if( !$lError )
{
$aRet = Build1094c_Pdf( $aData, $cYear );
}
}
else
{
$aRet = array( 'pdf_created' => false, 'error' => 'Company not found.' );
}
}
else
{
$aRet = array( 'pdf_created' => false, 'error' => $oDb->Error() );
}
$oDb->Close();
echo json_encode( $aRet );
?>
<?php
function Build1094c_Pdf( $aData, $cYear )
{
$aAleMember = array(0,0);
$aAleMember[0] = array('','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
$aAleMember[1] = array('','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
$nAleCount = count( $aData[ 'ale_members' ] );
for ($nX = 0; $nX < 30; $nX++)
{
if( $nX < $nAleCount )
{
$aAleMember[ 0 ][ $nX ] = $aData[ 'ale_members' ][ $nX ][ 'name' ];
$aAleMember[ 1 ][ $nX ] = $aData[ 'ale_members' ][ $nX ][ 'ein' ];
}
}
// 'topmostSubform[0].Page1[0].c1_08[1]' => 'No',
// 'topmostSubform[0].Page2[0].Table1[0].Row1[0].p2-cb1[1]' => 'No',
$aFV = array( 'topmostSubform[0].Page1[0].c1_01_CORRECTED[0]' => $aData[ 'corrected' ],
'topmostSubform[0].Page1[0].Name[0].f1_01[0]' => $aData[ 'cia_name' ],
'topmostSubform[0].Page1[0].Name[0].f1_02[0]' => $aData[ 'cia_ein' ],
'topmostSubform[0].Page1[0].Name[0].f1_03[0]' => $aData[ 'cia_address' ],
'topmostSubform[0].Page1[0].Name[0].f1_04[0]' => $aData[ 'cia_city' ],
'topmostSubform[0].Page1[0].Name[0].f1_05[0]' => $aData[ 'cia_state' ],
'topmostSubform[0].Page1[0].Name[0].f1_06[0]' => $aData[ 'cia_zip' ],
'topmostSubform[0].Page1[0].Name[0].f1_07[0]' => $aData[ 'contact_name' ],
'topmostSubform[0].Page1[0].Name[0].f1_08[0]' => $aData[ 'contact_phone' ],
'topmostSubform[0].Page1[0].Name[0].f1_09[0]' => $aData[ 'cia_dge_name' ],
'topmostSubform[0].Page1[0].Name[0].f1_10[0]' => $aData[ 'cia_dge_ein' ],
'topmostSubform[0].Page1[0].Name[0].f1_11[0]' => $aData[ 'cia_dge_address' ],
'topmostSubform[0].Page1[0].Name[0].f1_12[0]' => $aData[ 'cia_dge_city' ],
'topmostSubform[0].Page1[0].Name[0].f1_13[0]' => $aData[ 'cia_dge_state' ],
'topmostSubform[0].Page1[0].Name[0].f1_14[0]' => $aData[ 'cia_dge_zip' ],
'topmostSubform[0].Page1[0].Name[0].f1_15[0]' => $aData[ 'cia_dge_contact_name' ],
'topmostSubform[0].Page1[0].Name[0].f1_16[0]' => $aData[ 'cia_dge_contact_phone' ],
'topmostSubform[0].Page1[0].c1_02[0]' => false,
'topmostSubform[0].Page1[0].f1_17[0]' => $aData[ 'count_employee' ],
'topmostSubform[0].Page1[0].c1_03[0]' => true,
'topmostSubform[0].Page1[0].f1_18[0]' => $aData[ 'count_employee' ],
'topmostSubform[0].Page1[0].c1_08[0]' => 'Yes',
'topmostSubform[0].Page1[0].c1_04[0]' => false,
'topmostSubform[0].Page1[0].c1_05[0]' => false,
'topmostSubform[0].Page1[0].c1_06[0]' => false,
'topmostSubform[0].Page1[0].c1_07[0]' => false,
'topmostSubform[0].Page1[0].Title2[0].f1_166[0]'=> '',
'topmostSubform[0].Page2[0].Table1[0].Row1[0].p2-cb1[0]' => 'Yes',
'topmostSubform[0].Page2[0].Table1[0].Row1[0].f2_300[0]' => $aData[ 'count_employee' ],
'topmostSubform[0].Page2[0].Table1[0].Row1[0].f2_01[0]' => $aData[ 'count_employee' ],
'topmostSubform[0].Page2[0].Table1[0].Row1[0].c2_01[0]' => true,
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_14[0]' => $aAleMember[ 0 ][ 0 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_15[0]' => $aAleMember[ 1 ][ 0 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_16[0]' => $aAleMember[ 0 ][ 1 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_17[0]' => $aAleMember[ 1 ][ 1 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_18[0]' => $aAleMember[ 0 ][ 2 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_19[0]' => $aAleMember[ 1 ][ 2 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_20[0]' => $aAleMember[ 0 ][ 3 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_21[0]' => $aAleMember[ 1 ][ 3 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_22[0]' => $aAleMember[ 0 ][ 4 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_23[0]' => $aAleMember[ 1 ][ 4 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_24[0]' => $aAleMember[ 0 ][ 5 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_25[0]' => $aAleMember[ 1 ][ 5 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_26[0]' => $aAleMember[ 0 ][ 6 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_27[0]' => $aAleMember[ 1 ][ 6 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_28[0]' => $aAleMember[ 0 ][ 7 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_29[0]' => $aAleMember[ 1 ][ 7 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_30[0]' => $aAleMember[ 0 ][ 8 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_31[0]' => $aAleMember[ 1 ][ 8 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_32[0]' => $aAleMember[ 0 ][ 9 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_33[0]' => $aAleMember[ 1 ][ 9 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_34[0]' => $aAleMember[ 0 ][ 10 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_35[0]' => $aAleMember[ 1 ][ 10 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_36[0]' => $aAleMember[ 0 ][ 11 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_37[0]' => $aAleMember[ 1 ][ 11 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_38[0]' => $aAleMember[ 0 ][ 12 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_39[0]' => $aAleMember[ 1 ][ 12 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_40[0]' => $aAleMember[ 0 ][ 13 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_41[0]' => $aAleMember[ 1 ][ 13 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_42[0]' => $aAleMember[ 0 ][ 14 ],
'topmostSubform[0].Page3[0].PartIVNameEIN1[0].f3_43[0]' => $aAleMember[ 1 ][ 14 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_42[0]' => $aAleMember[ 0 ][ 15 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_43[0]' => $aAleMember[ 1 ][ 15 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_44[0]' => $aAleMember[ 0 ][ 16 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_45[0]' => $aAleMember[ 1 ][ 16 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_46[0]' => $aAleMember[ 0 ][ 17 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_47[0]' => $aAleMember[ 1 ][ 17 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_48[0]' => $aAleMember[ 0 ][ 18 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_49[0]' => $aAleMember[ 1 ][ 18 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_50[0]' => $aAleMember[ 0 ][ 19 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_51[0]' => $aAleMember[ 1 ][ 19 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_52[0]' => $aAleMember[ 0 ][ 20 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_53[0]' => $aAleMember[ 1 ][ 20 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_54[0]' => $aAleMember[ 0 ][ 21 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_55[0]' => $aAleMember[ 1 ][ 21 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_56[0]' => $aAleMember[ 0 ][ 22 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_57[0]' => $aAleMember[ 1 ][ 22 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_58[0]' => $aAleMember[ 0 ][ 23 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_59[0]' => $aAleMember[ 1 ][ 23 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_60[0]' => $aAleMember[ 0 ][ 24 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_61[0]' => $aAleMember[ 1 ][ 24 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_62[0]' => $aAleMember[ 0 ][ 25 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_63[0]' => $aAleMember[ 1 ][ 25 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_64[0]' => $aAleMember[ 0 ][ 26 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_65[0]' => $aAleMember[ 1 ][ 26 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_66[0]' => $aAleMember[ 0 ][ 27 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_67[0]' => $aAleMember[ 1 ][ 27 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_68[0]' => $aAleMember[ 0 ][ 28 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_69[0]' => $aAleMember[ 1 ][ 28 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_70[0]' => $aAleMember[ 0 ][ 29 ],
'topmostSubform[0].Page3[0].PartIVNameEIN2[0].f3_71[0]' => $aAleMember[ 1 ][ 29 ] );
$cBinPDFTK = './pdftk';
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' )
{
$cBinPDFTK = '.\pdftk.exe';
}
if( file_exists( 'tmp/filldata.fdf' ) )
{
unlink( 'tmp/filldata.fdf' );
}
if( ! MakeFDF( $aFV, 'tmp/filldata.fdf' ) )
{
$aRet = array( 'pdf_created' => false, 'error' => 'File < filldata.fdf > not created.' );
return $aRet;
}
else
{
if ( !file_exists( $cBinPDFTK ) )
{
$aRet = array( 'pdf_created' => false, 'error' => 'Binary of PDFTK not found in server host.' );
return $aRet;
}
else
{
$cFilePdf = "tmp/f1094c_filled" . time() . ".pdf";
$cRunCmd = $cBinPDFTK . " pdf/f1094c2_$cYear.pdf fill_form tmp/filldata.fdf output $cFilePdf flatten";
exec( $cRunCmd );
if ( file_exists( 'tmp/filldata.fdf' ) )
{
unlink( 'tmp/filldata.fdf' );
}
if( file_exists( $cFilePdf ) )
{
$aRet = array( 'pdf_created' => true, 'filename' => $cFilePdf );
}
else
{
$aRet = array( 'pdf_created' => false, 'error' => 'Not created pdf < f1094c.pdf >.' );
}
}
}
return $aRet;
}
?>