?
Solved

Access and edit fields in pdf document

Posted on 2003-03-17
10
Medium Priority
?
422 Views
Last Modified: 2010-04-04
How can I access and edit fields in a pdf document using the TPdf component.
0
Comment
Question by:edhemmit
[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
10 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 8155078
I always thought PDF's were read only, and the PDF component just gave you an interface to Acrobat so you could view a PDF.

Be interested to see the outcome of this.

Stu
0
 

Author Comment

by:edhemmit
ID: 8155333
You may be right. I just thought there had to be some way to do it.
0
 
LVL 2

Expert Comment

by:BorlandMan
ID: 8156374

if you have placed fields in the pdf, then you can put values in them and then save the document or print it out.

if you have acrobat 5 or 4 check out the help on Forms and fields.

as for how to get your hands on that via Delphi, good question. I haven't seen an API you can call through COM to say "get me field 14's value"

maybe you might be able to use Spy++ to find out what the windows are and then get a hold of the applications window (using FindWindow()) and then use enumerateWindows() to get a list of windows.... something like that, know what i mean?

sorry I don't have a simple "oh just do this" solution.

hth,
J
0
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.

 

Author Comment

by:edhemmit
ID: 8160342
Maybe I didn't ask the right question. I need to prompt a user through Delphi interface for input, which will be entered into blank pdf fields. The pdf will then be printed, the input discarded and the pdf closed. So the pdf will not actually be edited and saved.
0
 
LVL 1

Accepted Solution

by:
BobbyD earned 1000 total points
ID: 8177191
Where I work we've solved that problem by saving the PDF as a JPG image and then printing our responses directly on the image.  This works really well for printing on government forms, but it sure takes a lot of time and effort to properly position your text in the right part of the image.  I wouldn't use this approach for forms that change frequently.
0
 
LVL 2

Assisted Solution

by:BorlandMan
BorlandMan earned 1000 total points
ID: 8178826
ah.

Ok, here's the deal... or at least a little lite on the deal.

First of all, there is another automation object, which is specifically for form manipulations - which is what you are talking about when you place fields in a pdf. They are form fields.

The amusing thing is that unlike the acrobat.tlb, which comes with Adobe Acrobat 5.0 (and I guess 4.0 too), there isnt' one like this - but the samples in the Adobe Acrobat SDK (It's a C SDK, which I actually have used a few times) mentions and even has samples in visual basic demonstrating the usage.

Problem is there is no .tlb.... or at least it might seem like a problem. Turns out Adobe stashed the type information in a plug-in, which they include with Adobe Acrobat, called AcroForm.api

Use Import Typelib in Delphi and it will import the type information and create wrappers for them.  With this class, you can then iterate through fields and read their values and so on.... and yes set their values too.

Now if only we had a good delphi sample on how to do this...

Well, this looks like it is going to require a little fooling around with. The thing that's interesting is that the FormAutomation server is not a registered and Delphi seems to only want to create a registered com object, so you get an error.... it looks like you need to load Acrobat com object first, but I'm still getting the error.

something is not connecting somewhere... sorry need to sleep on this one.

I'll take a look at it again when it's lite.


hth,... a little,
J
0
 

Expert Comment

by:CleanupPing
ID: 9316743
edhemmit:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 10616049
There is no need to use TPDF.

Based upon the article on http://www.15seconds.com/issue/010822.htm,
here is a solution I posted the the Delphi newsgroups that should help you...

Depending on your PDF file and the fields
in it, here is how your FDF would look:
{
note the path to your pdf file in the /F parameter,
I had to escape the \.
}


%FDF-1.2
1 0 obj
<<
/FDF
<< 
/Fields
[
<<
/T (txtFirstName)
/V (EddieShipman)
>> 
<<
/T (chkVBS)
/V (No)
>>
<<
/T (radGender)
/V (Male)
>>
<<
/T (selSite)
/V (microsoft.com)
>>
<<
/T (selColor)
/Opt [(#6699FF) (#0000CC) (#990033) (#000080) (#FFCC00)]
/V (#990033)
>>
<<
/T (txtExperience)
/V (9 year Delphi; 12 months in HTML, 6 months in ASP & VBScript, 12 month in JavaScript, CSS2 & DOM)
>>
]
/F (c:/\FormTest.pdf)
>> 
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF

You need a section like this for EACH FIELD in the PDF:
<<
/T (txtFirstName)
/V (EddieShipman)
>> 


The /T is the name of the field and the /V is the Value.
If a field has /Opt then it is a Combobox.

And this is all you need to populate the fields:

Now, I can see that you have more than one field in that PDF.
I don't have Acrobat installed here to determine what the field
names are otherwise, I'd give you a full solution.

procedure TForm1.Button1Click(Sender: TObject);
  function GetFieldName(AString: String):String;
  begin
    Result := '';
    Result := StringReplace(AString, '/T', '', [rfReplaceALL]);
    Result := StringReplace(Result, '(', '', [rfReplaceALL]);
    Result := StringReplace(Result, ')', '', [rfReplaceALL]);
    Result := Trim(Result);
  end;
var
  slForm: TStringList;
  slData: TStringList;
  sFormName, sFieldName: String;
  i, x: Integer;
begin
  sFormName := 'c:\FormTest.fdf';
  slData := TStringList.Create;
  slData.Add('txtFirstName=EddieShipman');
  slData.Add('txtExperience=9 yrs Delphi;');
  slData.Add('chkVBS=No');
  slData.Add('radGender=Male');
  slData.Add('selSite=microsoft.com');
  slData.Add('selColor=#990033');

  slForm := TStringList.Create;
  try
    slForm.LoadFromFile(sFormName);
    for i := 0 to slForm.Count-1 do
    begin
      if Copy(slForm[i], 1, 2) = '/T' then
      begin
        sFieldName := GetFieldName(slForm[i]);
        for x := 0 to slData.count-1 do
          if slData.IndexOfName(sFieldName) > -1 then
            if sFieldName = 'selColor' then
            begin
              slForm[i+2] := '/V (' + slData.Values[sFieldName] + ')';
              break;
            end
            else
            begin
              slForm[i+1] := '/V (' + slData.Values[sFieldName] + ')';
              break;
            end;
      end;
    end;
    slForm.SaveToFile(sFormName);
    ShellExecute(0, 'open', PChar(sFormName), 'c:\FormTest.pdf', 'c:\', SW_SHOW);
  finally
    slForm.Free;
    slData.Free;
  end;
end;


I am currently working on a solution to retrieve the field data from a
PDF to build the FDF dynamically.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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