User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,762 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 788 | Replies: 2 | Solved
Reply
Join Date: Apr 2004
Location: Brownsville or Austin, TX or Faber, VA
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

php and pdf?

  #1  
Nov 11th, 2007
Hello folks, I was wondering if anyone had any experience with php configured with pdflib. I am trying to create a new pdf by loading an already existing pdf and overlaying some information where the fields would be on the existing pdf. I have been trying to figure this out for some time. I know about the PDFlib and PDI solution but does any one know of another way to do this with free software. I was trying to figure out if there was a way to convert the exisitng pdf to jpg and just load the jpg and overlay text in a new document which seems like the only reasonable solution so far. If anyone knows of a better way to do this or to have php create a pdf with a page from an existing pdf without using non-free software please let me know. Any help is welcome. Thanks for any help.
The purpose of my existence is why I am here.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Location: Brownsville or Austin, TX or Faber, VA
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: php and pdf?

  #2  
Nov 12th, 2007
Well, not too many people are familiar with this stuff I guess, but I am wokring on my own solution and so just in case anyone else needs to do anything similair, the easiest thing I've found has been to use image printer from sourceforge to print to png the original pdf form and I am using FPDF to generate the pdf in php which doesn't require to be configured into PHP to work. This solution seems to be the most versatile form and although it requires you to print pdfs to png files once done, the rest is easy to do. Thanks for reading the post.
The purpose of my existence is why I am here.
Reply With Quote  
Join Date: Nov 2007
Location: Reseda, California
Posts: 19
Reputation: scottholmes is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
scottholmes scottholmes is offline Offline
Newbie Poster

Re: php and pdf?

  #3  
Nov 20th, 2007
Even though this thread has been marked solved, I'm new here and spotted this thread. I did some similar work a year or so ago and though you might be interested in what I found. I included the parsing functions just for clarity. Of primary interest is the create_fdf() function.

<?php
session_start();

// the full http path to the PDF form
$form = sprintf("http://%s/HCFA1500/hcfa1500.pdf", $_SERVER["HTTP_HOST"]);

function isNaN( $var ) {
return !ereg ("^[-]?[0-9]+([\.][0-9]+)?$", $var);
}

function fill_string ($fld_name, $fld_value)
{
$key = addcslashes($fld_name, "\n\r\t\\()");
$value = addcslashes($fld_value, "\n\r\t\\()");
$str = "<< /T ($key) /V ($value) >> \n";
return $str;
}

function parse_date($fld_name, $fld_value, $yr_size)
{
if (!strtotime($fld_value)) {
$str = "";
} else {
$mo_str = $fld_name . "_month";
$dy_str = $fld_name . "_day";
$yr_str = $fld_name . "_year";
$str = fill_string($mo_str, substr($fld_value,0,2));
$str .= fill_string($dy_str, substr($fld_value,2,2));
if ($yr_size == '4') {
$str .= fill_string($yr_str, substr($fld_value,4,4));
} else {
$str .= fill_string($yr_str, substr($fld_value,4,2));
}
}
return $str;
}

function parse_phone($fld_name, $fld_value)
{
if (strlen($fld_value) < 11) {
$str = "";
} else {
$ac_str = $fld_name . "_areacode";
$nm_str = $fld_name . "_phone";
$str = fill_string($ac_str, substr($fld_value,0,3));
$str .= fill_string($nm_str, sprintf("%s%s", substr($fld_value,4,3), substr($fld_value,8,4)));
}
return $str;
}

function parse_float($fld_name, $fld_value)
{
if ( isNaN($fld_value) == TRUE) {
$str = "";
} else {
$dol_str = $fld_name . "_dollars";
$cnt_str = $fld_name . "_cents";
$whole_val = floor($fld_value);
$cent_val = (100 * ($fld_value - $whole_val));
$str = fill_string($dol_str, sprintf("%d", $whole_val));
$str .= fill_string($cnt_str, sprintf("%02d", $cent_val));
}
return $str;
}

function create_fdf ($pdffile)
{
$fdf ="%FDF-1.2\n%âãÏÓ\n";
$fdf .= "1 0 obj \n<< /FDF << /Fields [\n";

foreach ($_SESSION as $key => $value) {
switch ($key) {
case "patientsDOB": $fdf .= parse_date("box3", $value, '4'); break;
case "box5_telephone": $fdf .= parse_phone("box5", $value); break;
case "box7_telephone": $fdf .= parse_phone("box7", $value); break;
case "otherInsuredsDOB": $fdf .= parse_date("box9", $value, '4'); break;
......

default: $fdf .= fill_string($key, $value);
}
}

$fdf .= "]\n/F ($pdffile) >>";
$fdf .= ">>\nendobj\ntrailer\n<<\n";
$fdf .= "/Root 1 0 R \n\n>>\n";
$fdf .= "%%EOF";

return $fdf;
}

header('Content-type: application/vnd.fdf');
echo create_fdf($form);
?>
Scott Holmes
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:07 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC