Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1164
  • Last Modified:

activePDF Toolkit and php

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
klewlis
Asked:
klewlis
  • 4
  • 4
1 Solution
 
klewlisAuthor Commented:
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
 
Richard QuadlingSenior Software DeverloperCommented:
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
 
klewlisAuthor Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
klewlisAuthor Commented:
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
 
Richard QuadlingSenior Software DeverloperCommented:
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
 
Richard QuadlingSenior Software DeverloperCommented:
IVIEWERS.DLL sorry, not IPVIEWERS.DLL

0
 
Richard QuadlingSenior Software DeverloperCommented:
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
 
klewlisAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now