•
•
•
•
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
![]() |
•
•
Join Date: Apr 2004
Location: Brownsville or Austin, TX or Faber, VA
Posts: 59
Reputation:
Rep Power: 5
Solved Threads: 2
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.
•
•
Join Date: Apr 2004
Location: Brownsville or Austin, TX or Faber, VA
Posts: 59
Reputation:
Rep Power: 5
Solved Threads: 2
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.
•
•
Join Date: Nov 2007
Location: Reseda, California
Posts: 19
Reputation:
Rep Power: 2
Solved Threads: 0
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);
?>
<?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
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- PDF creation: Wrap text on Table with Fpdf (PHP)
- PHP and PDF (PHP)
- Php With Pdf (PHP)
- Using TCPDF or UFPDF to generate pdf files in php (PHP)
Other Threads in the PHP Forum
- Previous Thread: insert in mysql
- Next Thread: PHP Special character Problem


Linear Mode