3

I created a quick PDF file with two form fields, first name and last name (or FirstName and LastName), with a Submit button and used the following code to try to populate these fields in a new PDF file:

<cfpdfform action="populate" source="#variables.AbsPath#\test.pdf">
    <cfpdfformparam name="FirstName" value="foo" />
    <cfpdfformparam name="LastName" value="bar" />
</cfpdfform>

However, I receive this error:

The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code.
Null Pointers are another name for undefined values.
Platform, Locale, and Platform Name must not be null

I tried reading the PDF file to make sure the form fields were correct using this and they are:

<cfpdfform action="read" source="#variables.AbsPath#\test.pdf" result="fields" />

<cfdump var="#fields#">

The struct dumps out:

FirstName:  [empty string]
LastName:   [empty string]
Submit:     [empty string]

I tried searching the Adobe docs and around some other sites, but can't find a solution for this error. I also tried adding a "destination" parameter to the cfpdfform tag in case it was needed, but got the same result. The PDF file does exist. Any ideas? Thanks in advance.

UPDATED: Here is the stack trace:

java.lang.NullPointerException: Platform, Locale, and Platform Name must not be null
at com.adobe.fontengine.fontmanagement.platform.PlatformFontDescription.<init>(Unknown Source)
at com.adobe.fontengine.font.opentype.OpenTypeFont.getPlatformFontDescription(Unknown Source)
at com.adobe.fontengine.font.FontImpl.getPlatformFontDescription(Unknown Source)
at com.adobe.fontengine.font.FontImpl.getPlatformFontDescription(Unknown Source)
at com.adobe.fontengine.fontmanagement.platform.PlatformFontResolverImpl.addFont(Unknown Source)
at com.adobe.internal.pdftoolkit.core.fontset.impl.PDFFontSetImpl.addFont(Unknown Source)
at com.adobe.internal.pdfm.util.FontSetBuilder.loadFontsPath(FontSetBuilder.java:418)
at com.adobe.internal.pdfm.util.FontSetBuilder.loadSystemFonts(FontSetBuilder.java:346)
at com.adobe.internal.pdfm.util.FontSetBuilder.makePDFFontSet(FontSetBuilder.java:239)
at com.adobe.internal.pdfm.util.FontSetBuilder.getPdfFontSet(FontSetBuilder.java:93)
at com.adobe.internal.pdfm.PDFM7Factory.getPdfFontSet(PDFM7Factory.java:97)
at coldfusion.document.DocumentServiceImpl.getAssemblerFontSet(DocumentServiceImpl.java:512)
at coldfusion.pdf.PDFForm.populateFields(PDFForm.java:292)
at coldfusion.tagext.lang.PDFFormTag.doEndTag(PDFFormTag.java:347)
at cfsubmit2ecfm1224790315.runPage(C:\ColdFusion\wwwroot\nVision\projects\test\pdfform\submit.cfm:9)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:381)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:94)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126)
at coldfusion.CfmServlet.service(CfmServlet.java:200)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Whatevo
  • 280
  • 3
  • 14

4 Answers4

6

I believe this is a font issue with the specific server being used. This is why the same code will work on the production server and not the testing server. I am experiencing the same issue and although I don't have a great solution here's what I learned.

  1. The stacktrace shows that there's an error getting the getPlatformFontDescription of an OpenType font.
  2. Our Windows server is listing some TrueType fonts as OpenType. Is yours?
  3. Using the following code corrected the issue, but it's a work around only.

    <cfpdf name="local.pdffile" action="read" source="some path" >
    <cfscript>
    local.pdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader").init(tobinary(local.pdffile));
    local.outputStream = createObject("java", "java.io.ByteArrayOutputStream").init();
    local.pdfStamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(local.pdfReader,local.outputStream);
    local.Acroform = local.pdfStamper.getAcroFields();
    //Populating Form Fields     
     local.Acroform.setField("Field1",Arguments.Value1);
     local.Acroform.setField("Field2",Arguments.Value2);
     // etc.
     local.pdfStamper.setFormFlattening(true); //optional
      local.pdfStamper.close();
      local.pdfReader.close();
      local.pdffile = local.outputStream.toByteArray();
     </cfscript>
     <!--- flatten="no" must be set or you will get the error again  --->
     <cfpdf action="write" source="local.pdffile" destination="#variables.OutputPath##local.UUID#.pdf" overwrite="yes" flatten="no"  />
    
  4. More Diagnostics: Simply listing all the fonts available to the server using the Java subsystem also fails. Try this.

     <cfset list=createobject("java","com.adobe.internal.pdfm.util.FontSetBuilder")>
     <cfdump var="#list#">
     <cfset dummy = list.getPdfFontSet()>
     <cfdump var="#dummy.toString()#">
     <!--- this should fail --->
    
  5. We have "fixed" our problem at the moment by removing all the fonts from the Windows\Fonts folder, and isolating the damaged ones. It's painstaking but seems to work.

Good luck!

John S.
  • 61
  • 1
  • 3
  • 2
    +1. Good write up. Re: *flatten="no" must be set or you will get the error again* You could also save directly to a file by using `java.io.FileOutputStream`, instead of `ByteArrayOutputStream`. Then there is no need for the final `cfpdf action="write"`. – Leigh Apr 30 '13 at 02:17
  • Thanks Leigh that helped me solve some writing issues that I was having with cfpdf. – Aaron Sep 26 '13 at 00:36
2

You did not mention how you created your PDF file. Depending on how you created the PDF file the form fields may be contained within a subform. PDFs generated from templates within LiveCycle will do this. By default LiveCycle will name the subform "form1". In order to populate these form fields you need to include the cfpdfsubform tag. See the documentation here: cfpdfsubform documentation

So your code would look something like this:

<cfpdfform action="populate" source="#variables.AbsPath#\test.pdf">
    <cfpdfsubform name="form1">
        <cfpdfformparam name="FirstName" value="foo" />
        <cfpdfformparam name="LastName" value="bar" />
    </cfpdfsubform>
</cfpdfform>

The code that you included to read your PDF file should show you if the fields are included in a subform. The dump would show your form fields contained within another structure. That would be the name that you use in the cfpdfsubform tag's name attribute.

HTH.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • 1
    The PDF was created in Adobe Acrobat X Pro. I did check to make sure there wasn't a subform (there isn't), but it is still causing issues. When reading the PDF, it just shows fields such as FirstName, LastName, etc. but not nested within any other fields or structures. Using CFPDFFORM generates the error I noted. Not sure where else to go. – Whatevo Sep 05 '12 at 05:56
  • 1
    Have you tried adding the 'overwriteData' attribute and setting it to 'yes'? The documentation states: Specifies whether to overwrite existing data in PDF form fields with data from the data source: yes: Overwrite existing data in the form fields with that from the data source. no: Retain existing data in form fields and populate only those fields without data. This attribute applies to data supplied from an XML data source and from the cfpdfparam and cfpdfsubform tags. – Miguel-F Sep 05 '12 at 13:43
  • 1
    Tried adding the overwriteData attribute and setting it to "yes", but still receive the same error. – Whatevo Sep 05 '12 at 21:31
2

I just wrote up a script to fix this issue here: https://stackoverflow.com/a/20408559/1223555

It's an issue with a font file not having a locale or platform name set. the PDF functions in Coldfusion call this

<cfset list=createobject("java","com.adobe.internal.pdfm.util.FontSetBuilder")>
<cfset dummy = list.getPdfFontSet()>

This enumerates every font and if one is bad it throws an exception and kills your process.

My code enumerates all the fonts in c:\windows\fonts and then tells you the bad ones.

Here are the ones we have issues with:

AdobeNaskh-Medium.otf
Mechanical.TTF
msgothic.ttf
MyriadArabic-Bold.otf
MyriadArabic-BoldIt.otf
MyriadArabic-It.otf
MyriadArabic-Regular.otf
Community
  • 1
  • 1
Jesse Carlton
  • 91
  • 1
  • 1
1

I just realized after re-reading your question that I was going down the wrong path. I was thinking you were having an issue populating the fields in the pdf. But your real issue is the null pointer. Doh! Sorry about the confusion.

Usually that error is telling you that a variable you are using is not defined. The only variable I see in your example is #variables.AbsPath#. You are specifying the variables scope. Is that correct? The variables scope is available only on the page in which it was created (and to included pages).

You did not include how you are defining that variable. Can you share that?

Is the error happening randomly or all the time?

Are you sure the error is happening on that cfpdfform line and not somewhere else? I would put a cftry/cfcatch block around your code and dump the cfcatch structure to get a more specific error. Can you try that and post back?

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • Good question. I am defining variables.AbsPath just above the cfpdfform "populate" line on the same page. It's just the path to the PDF file (which I confirmed is set correctly, so I don't have to keep entering it if I need it). The error I'm receiving always occurs on that cfpdfform "populate" tag. – Whatevo Sep 05 '12 at 17:21
  • Have you tried just hardcoding the path into the cfpdfform tag (not using the variable) to confirm the error persists? – Miguel-F Sep 05 '12 at 17:45
  • @Miguel-F - FYI if you need to modify your response, you can always edit your existing answer. – Leigh Sep 05 '12 at 18:30
  • @JoshuaRowe - Shot in the dark, but are there any unusual fonts involved with this pdf? Also what is your environ and the full stack trace message? – Leigh Sep 05 '12 at 18:33
  • @Leigh - thanks. I thought since it was a completely different answer a new one might be better than editing the first. Long time reader, first time answerer. – Miguel-F Sep 05 '12 at 18:50
  • @Miguel-F - Okay, I was not sure if you were familiar with the options. Welcome to "posting/answering" on SO btw :) – Leigh Sep 05 '12 at 19:17
  • @Miguel-F - I did try hard coding the path instead of using the variable, but still receive the same error. – Whatevo Sep 05 '12 at 21:32
  • @Leigh - I modified the original post to add the stack trace (for readability). You can view it above. As for weird fonts, etc., there are some icons and stuff in the PDF file. However, I tried creating my own PDF file with just a few input fields to test it out and still receive the same error message with the simplified PDF file. – Whatevo Sep 05 '12 at 21:34
  • @JoshuaRowe - I have not seen that one before. But it does not look like it is caused by missing CF variables. Looks like some problem with internal initialization of font settings. Unfortunately, I have no idea about the cause. – Leigh Sep 05 '12 at 21:57
  • @JoshuaRowe - When you tried the simplified PDF did you try a different font? – Miguel-F Sep 06 '12 at 13:12
  • The simplified one just had two input fields and submit button without any text. – Whatevo Sep 06 '12 at 18:45
  • @JoshuaRowe - Can you upload/post a link to the sample file? We can test it to see the problem is the file itself - or maybe something in your environ. Also what is your CF version BTW? – Leigh Sep 06 '12 at 22:17
  • @Leigh - funny thing is now it's working on the live server, but still not on my local machine. Go here for the successful test on the live server: www.nvisionweb.com/pdfform/test.pdf. The two fields are First Name and Last Name. This server is running ColdFusion 9 Standard and my local machine runs CF 9 Developer Edition. – Whatevo Sep 07 '12 at 17:22
  • @JoshuaRowe - What are the full version numbers? It tested and it worked without error under CF9.0.0 & CF10. Unfortunately a brief search returned few references to the error, and no causes. Just throwing out ideas here .. does the error occur with *all* pdf's or just that one? The former suggests a possible environ problem. The latter a possible issue with the program that produced the pdf (GhostScript). – Leigh Sep 07 '12 at 18:02
  • Local version is 9,0,1,274733 running on Windows 7. Live version is 9,0,0,251028 running on Windows Server 2008. The test PDF I created with the two fields and the PDF I need for the live version of my client's site both work on my live environment, but not locally. So, you're right.. this appears to be an environment issue. Any ideas on where to go from here? The only difference I can think of is I installed the 9.0.1 hotfix locally. – Whatevo Sep 09 '12 at 19:15
  • @JoshuaRowe - Sorry, I did not see your comment until just now. I am not sure it is the hotfix as it works okay for me with windows 7 + 9,0,1,274733. At this point I am not sure what else to recommend, other than checking all logs or if there are any strange fonts registered on the non-working box. Those are long shots though... Given that it is an obscure issue (and there are not many references to it), you may want to file a bug report or possibly check with support. (Edit) ... and try twitter #coldfusion too. – Leigh Sep 12 '12 at 02:51
  • Yeah, the server.log reports 2 items: 1) Processing template completed in 12 seconds, exceeding the 10 second warning limit, and 2) Platform, Locale, and Platform Name must not be null. I tried changing the warning time to 60 seconds, which didn't correct the problem, it just didn't log it. Thank you for your help with everything. I will contact their support team to see if there is something they know about this. Thanks again! – Whatevo Sep 12 '12 at 14:21
  • @JoshuaRowe - Sounds good. Post back if you get answers, because I would love to know the cause of this weird error too. Just be sure to throw in a "@" + username, otherwise I will never see the followup ;) – Leigh Sep 13 '12 at 11:07
  • @JoshuaRowe - Did you ever find out the cause and/or a fix for the issue? Just noticed [someone else having the same problem](http://stackoverflow.com/questions/16289795/coldfusion-cfpdfform-populate-error), but under CF10. – Leigh Apr 29 '13 at 23:46