?
Solved

activePDF Toolkit and php

Posted on 2003-03-17
8
Medium Priority
?
1,139 Views
Last Modified: 2013-12-13
Hi,

I'm trying to use the activePDF Toolkit with php on a windows box. I'm having a hard time getting it working because I'm not too familiar with COM objects in PHP. Does anyone have a code example to get this working? I'm trying to fill pdf form fields with data submitted from another pdf. The examples on the activePDF site are only asp and coldfusion!
0
Comment
Question by:klewlis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 1

Author Comment

by:klewlis
ID: 8155004
more specifically, I need to figure out how to translate this into php:

------------------
Set TKIT = Server.CreateObject("APToolkit.Object")
FileName = TKIT.GetUniqueFileName()
r = TKIT.OpenOutputFile(Server.MapPath(FileName))
r = TKIT.OpenInputFile(Server.MapPath("Template.PDF"))

For Each FormItem in Request.Form
If FormItem <> "SUBMIT" Then
TKIT.SetFormFieldData FormItem, Request(FormItem),0
End If
Next


r = TKIT.CopyForm(0,0)
TKIT.CloseOutputFile
----------------------

it doesn't LOOK hard but I can't seem to get it right (or else something else is wrong and it's just not working...)
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 1500 total points
ID: 8158021
No checking on this, but ...

$objAPT = new COM('APToolkit.Object') or die('Unable to load APToolkit');
$sFilename = $objAPT->GetUniqueFilename();
$xOutput = $objAPT->OpenOutputFile(somefunction(FileName));
$xInput = $objAPT.OpenInputFile(somefunction("Template.PDF"));

foreach($_POST as $k => $v)
 {
 if ($k != 'SUBMIT') // Watch out for case on this!!
  {
  $objAPT->SetFormFieldData($k,$v,0);
  }
 }


$x = $objAPT->CopyForm(0,0);
$objAPT->CloseOutputFile();


I don't know what the function Server.MapPath() returns, so you will need to look into that.

Also, you may find that some of the ASP code requires nulls. You cannot use 0.

Instead use ...

$empty = new VARIANT();

and then $empty as the parameter.

This is an example COM program for word.


<?php
// Some servers may have an auto timeout, so take as long as you want.
set_time_limit(0);

// Show all errors, warnings and notices whilst developing.
error_reporting(E_ALL);

// Used as a placeholder in certain COM functions where no parameter is required.
$empty = new VARIANT();

// Load the appropriate type library.
com_load_typelib('Word.Application');

// Create an object to use.
$word = new COM('word.application') or die('Unable to load Word');
print "Loaded Word, version {$word->Version}\n";

// Open a new document with bookmarks of YourName and YourAge.
$word->Documents->Open('C:/Unfilled.DOC');

// Fill in the information from the form.
$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourName'); // Note use of wdGoToBookmark, from the typelibrary and the use of $empty.
$word->Selection->TypeText($_GET['YourName']);

$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourAge');
$word->Selection->TypeText($_GET['YourAge']);

// Save it, close word and finish.
$word->Documents[1]->SaveAs("C:/{$_GET['YourName']}.doc");
$word->Quit();
$word->Release();
$word = null;
print "Word closed.\n";
?>


Good luck!

Richard.
0
 
LVL 1

Author Comment

by:klewlis
ID: 8159917
that's pretty much what i tried first... just a straight translation. but for some reason
$xOutput = $objAPT->OpenOutputFile(somefunction(FileName));

returns an error every time, and even though the *input* line doesn't return an error, anything i try to do with the input file after that returns an error (or nothing at all).
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
LVL 1

Author Comment

by:klewlis
ID: 8159976
ps: the server.mappath is just to get the full directory path of the file rather than just the local path. i've tried it both with the full path and without, with no change...

i'm going to turn on that full error reporting and see if it helps.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8160027
What is the exact error? (Cut'n'paste rather than re-type).

A couple of things with the output file.

1 - Does PHP have permission to write to the directory that you is being used.
2 - If so, create an zero length file (right click in explorer, new text file, save and close) and then rename it to match the filename that is being used as the output file.

What does the "somefunction" do? I'm not familiar with ASP, so the Server.MapPath() function will need to be handled.

You could also use OLEView to make sure you are using the correct parameters and types. Do a search on Google for OLEView and Microsoft, download OLEView from MS. Then do a search for ipviewers.dll. This is a support file for OLEView which is not supplied! I use one called warex.dll (that's the name it came with). It works. And allows you to see the types and names and methods and objects in a COM library very clearly.

Richard.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8160040
IVIEWERS.DLL sorry, not IPVIEWERS.DLL

0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8160052
Also set the timelimit as some COM libraries may be a little slow, or the amount of time the script can run for on the server may be shorter than required.

0
 
LVL 1

Author Comment

by:klewlis
ID: 8160341
i think i'm going to die of shock. lol

i turned off all my die messages and just ran through the function.

it works.

as long as i don't include the "or die". it seems to be working *and* dying. what an odd thing. but i just got my first successful output file! yay! thanks for your help, rquadling. :)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question