Expand my Community achievements bar.

Geting the user name

Avatar

Former Community Member
I have the need to display the username of the current user on a form. (This will be used to index scanned paper and therefore it is important to know who indexed the document, scanning is after processing the papers).



Maybe this has been beaten to death. I browsed the internet and Adobes JavaScript manual. Seems the Identity object fullfills all my needs, but it is restricted in security. I'm not at all clear why the username poses a security threat, but regardless..



I'm not clear on how to proceed. As far as I got it, you have to write some JavaScript, that goes to the JS folder of Acrobat and sets some application level variables.



In the document I can set the fields from those global variables. But I want to distribute the form as a self contained document an not to have to roll out the JavaScripts to many desktops.



I tried to use the code within the form in a app.trustedFunction between app.beginPriv() and app.endPriv() but the console tells me that security setting prevent execution of this code?



What can I do or where have I gone wrong (for a change)?



Thanks,



/gerold
9 Replies

Avatar

Former Community Member
Care for a (by all means short, not as elaborative as the reply) explananation ?



/Gerold

Avatar

Level 6
It's a privacy issue. It's unlikely that Adobe would allow Acrobat/Reader to sniff out information about the user without his or her knowledge, including his or her username.

Avatar

Former Community Member
You can do this with an AcroForm with an IAC application using the the VB JS Object but I'm not sure about a Designer XML based form. Here is the VBScript below that does it for an AcroForm.



~T



'Begin Code

Dim objNet

On Error Resume Next



'In case we fail to create object then display our custom error



Set objNet = CreateObject("WScript.NetWork")



Set WshShell = WScript.CreateObject("WScript.Shell")

'use the wshell to launch Acrobat

WshShell.Run ("Acrobat.exe")

WScript.Sleep 1000



'open a file

WshShell.run "Acrobat.exe c:\test.pdf"



'if Acrobat or no document is open you get an error message about not finding the file.

set WshShell = CreateObject ("Wscript.Shell")

WshShell.AppActivate("Adobe Acrobat")

WScript.Sleep 100



'get the active Document for use with JSObject

Set AcroApp = CreateObject("AcroExch.App")

Set AVDoc = AcroApp.GetActiveDoc

Set PDDoc = AVDoc.GetPDDoc

set jso = PDDOC.GetJSObject



set f = jso.getField("Text1")

f.value = objNet.UserName



Set g = jso.getField("Text2")

g.value = objNet.ComputerName



Set h = jso.getField("Text3")

h.value = objNet.UserDomain



Set objNet = Nothing 'Destroy the Object to free the Memory

'end script

'End Code

Avatar

Former Community Member
OK... I've been experimenting and you should be able to write the username value from the system via VBScript to an XML file and then import it to a Designer based XML form using VB JS Object. I'll need to work out the details but it looks possible.



~T

Avatar

Former Community Member
Got it! Granted this isn't the way to really do it but it shows that you can use an IAC application via VB or VBScript (in this case) to populate a Designer based XML form with username (and other) information using the JS Object.<br /><br />~T<br /><br />'Begin Code<br />Dim objNet<br />On Error Resume Next <br /><br />'In case we fail to create object then display our custom error<br /><br />Set objNet = CreateObject("WScript.NetWork") <br /><br />'Dim strInfo<br />'strInfo = "User Name is " & objNet.UserName & vbCRLF & _<br />' "Computer Name is " & objNet.ComputerName & vbCRLF & _<br />' "Domain Name is " & objNet.UserDomain<br />'MsgBox strInfo<br /> 'create the script object<br /><br /> Dim sFSpec ' FSpec of file to write <br /> Dim sXmlPfx ' fixed xml prefix <br /> Dim sXmlSfx ' fixed xml suffix <br /> Dim aMeta ' fixed meta/tag info <br /> Dim aData ' changing data <br /><br />' needs your attention <br /> sFSpec = "c:\test.xml" <br /> sXmlPfx = "<?xml version='1.0' encoding = 'UTF-8'?>" <br /> 'sXmlPfx = sXmlPfx + "<form1>" <br /> 'sXmlSfx = "</form1>" <br /> aMeta = Array( "form1", "TextField1", "TextField2", "TextField3") <br /><br /> aData = Array( Array( objNet.UserName, objNet.ComputerName, objNet.UserDomain )_ <br /> ) <br /><br />' should work as is <br /> Dim sXML <br /> Dim aItem <br /> Dim nIdx <br /><br /> sXmlPfx = Replace( sXmlPfx, "'", """" ) ' not without risk of replacing <br /> sXmlSfx = Replace( sXmlSfx, "'", """" ) ' "'"s you want to keep <br /> sXML = sXmlPfx <br /><br /> For Each aItem in aData <br /> sXML = sXML + "<" + aMeta( 0 ) + ">" <br /> For nIdx = 1 To UBound( aMeta ) <br /> sXML = sXML + "<" + aMeta( nIdx ) + ">" <br /> sXML = sXML + aItem( nIdx - 1 ) <br /> sXML = sXML + "</" + aMeta( nIdx ) + ">" <br /> Next <br /> sXML = sXML + "</" + aMeta( 0 ) + ">" <br /> Next <br /><br /> sXML = sXML + sXmlSfx <br /> sXML = Replace( sXML, "><", ">" + vbCrLf + "<" ) ' poor man's format <br /><br /> CreateObject( "Scripting.FileSystemObject" ) _ <br /> .CreateTextFile( sFSpec, True ) _ <br /> .Write sXML <br /><br /> 'create the script object<br />Set WshShell = WScript.CreateObject("WScript.Shell")<br />'use the wshell to launch Acrobat<br />WshShell.Run ("Acrobat.exe")<br />WScript.Sleep 1000<br /><br /> 'open a file<br /> WshShell.run "Acrobat.exe c:\DesignerTest.pdf"<br /><br /> 'if Acrobat or no document is open you get an error message about not finding the file. <br />set WshShell = CreateObject ("Wscript.Shell") <br />WshShell.AppActivate("Adobe Acrobat") <br />WScript.Sleep 100<br /> <br /> 'get the active Document for use with JSObject <br />Set AcroApp = CreateObject("AcroExch.App") <br />Set AVDoc = AcroApp.GetActiveDoc <br />Set PDDoc = AVDoc.GetPDDoc <br />set jso = PDDOC.GetJSObject <br /><br />jso.importXFAData "/c/test.xml"<br /><br />'End Code

Avatar

Level 8
With Google, I did a very very long search on how to use Adobe LiveCycle Designer to design Interactive/Dynamic Forms, and publish them to the IIS Server and used ASP.NET to populate such forms with field values from back-end Database such as SQL Server.



The solution mentioned in this post above may work, but I am not comfortable with using such approach, it is very complex.



We are designing and implementing Electronic Forms that must detect the user currently logged in to the Windows Intranet (under IIS), and should perform a Look-up to the Back-End Database to extract the User Related Data and Populate the Form Fields to start the Form Processing.



I finally found that the product "Adobe LiveCycle® Designer add-in for Microsoft Visual Studio .NET" from www.ensemble.com seems to be the Answer.



So I download the add-in, but I did not find enough documentation to tell me how to use it. I also noticed that I may need to install Adobe LiveCycle Forms Server to make this work. At the time being, Adobe LiveCycle Forms Server is not on our budget yet. We will assume at this point in time, that the users will have the required Adobe Acrobat version on the Client PC.



Also, I tried to use the Add-In from Visual Studio Prof 2005, and when I try to Add New Item to an exiting Project or Website, I cannot find the template "Adobe Designer Form". By chance, I was able to add this Item only when I try to add to a Solution (where you have to have 2 projects open at the same time). Could you please clarify this part ?



Do you think this add-in satisfy our requirements ?



Do you have any recommendations on how to implement such requirement ?



It seems to me that the recommended way it write a program in ASP.NET to detect the Current Windows User ID, and perform a Query to the back-end Database and generate the required XML Schema and Data Files, and connect them to the Adobe Form and Render the form back to the Client. Is this possible ? How ?



Your feedback will be highly appreciated.

Avatar

Level 8
Dear All,



I found the solution using asp.net to extract the form fields data from the request object and also extract the entire pdf from the xml chunk element in the same request.



I was also able to merge the data with the form fields and render the results as xdp to the client pc.



Any one excited to know how ? I am here to help .



Tarek.

Avatar

Former Community Member
I am looking for similar solution but i want to extract the form data in a .jsp page through request object. Can someone help?



Thanks