Skip to main content
November 24, 2010
Answered

PDF function error: "Platform, Locale, and Platform Name must not be null"

  • November 24, 2010
  • 3 replies
  • 3313 views

I'm trying to read in a pdf form, complete the fields and send it to the user's browser. However I approach it, whenever I use a cfpdf type of tag, I get the error message "Platform, Locale, and Platform Name must not be null".


For example the following flags an error on the cfpdfformparam line:


<cfpdfform action="populate" source="Order Acknowledgement Form4.pdf">
    <cfpdfformparam name="Text1" value="Test Data">
</cfpdfform>


What am I doing wrong?


Using CF9.01 Developer edition. The PDF was created in Acrobat X from a Word file.


The following works and lists the form field, so I'm guessing that it's not a problem with the source file.


<cfpdfform source="Order Acknowledgement Form4.pdf" result="resultStruct" action="read"/>
<cfdump var="#resultStruct#">
    This topic has been closed for replies.
    Correct answer jcarlton

    I've created a cfm page that enumerates all the fonts in the c:\windows\fonts directory and lists the ones that are incompatible with the CF PDF components:

    <cfset fontobj = createobject("java","com.adobe.fontengine.fontmanagement.FontLoader")>

    <cfdirectory action="list" directory="c:\windows\fonts" name="fontdir">

    <table border="1" style="border-collapse:collapse">

      <tr>

        <th>Font Name:</th>

        <th>Error</th>

      </tr>

      <cfloop query="fontdir">

      <cftry>

        <cfset loaded = fontobj.load(createobject("java","java.net.URL").init("file:///C|/windows/fonts/#fontdir.name#"))>

        <cfif arraylen(loaded) gt 0>

          <cfset dummy="#loaded[1].getPlatformFontDescription()[1].toString()#" >

        </cfif>

        <cfcatch>

          <cfif findnocase("platform",cfcatch.message)>

            <tr>

              <td><cfoutput>#fontdir.name#</cfoutput></td>

              <td><cfoutput>#cfcatch.message#</cfoutput></td>

            </tr>

          </cfif>

        </cfcatch>

      </cftry>

      </cfloop>

    </table>

    3 replies

    jcarltonCorrect answer
    New Participant
    December 5, 2013

    I've created a cfm page that enumerates all the fonts in the c:\windows\fonts directory and lists the ones that are incompatible with the CF PDF components:

    <cfset fontobj = createobject("java","com.adobe.fontengine.fontmanagement.FontLoader")>

    <cfdirectory action="list" directory="c:\windows\fonts" name="fontdir">

    <table border="1" style="border-collapse:collapse">

      <tr>

        <th>Font Name:</th>

        <th>Error</th>

      </tr>

      <cfloop query="fontdir">

      <cftry>

        <cfset loaded = fontobj.load(createobject("java","java.net.URL").init("file:///C|/windows/fonts/#fontdir.name#"))>

        <cfif arraylen(loaded) gt 0>

          <cfset dummy="#loaded[1].getPlatformFontDescription()[1].toString()#" >

        </cfif>

        <cfcatch>

          <cfif findnocase("platform",cfcatch.message)>

            <tr>

              <td><cfoutput>#fontdir.name#</cfoutput></td>

              <td><cfoutput>#cfcatch.message#</cfoutput></td>

            </tr>

          </cfif>

        </cfcatch>

      </cftry>

      </cfloop>

    </table>

    New Participant
    June 26, 2014

    Thank you Carlton!!!!!

    Known Participant
    July 13, 2013

    Hi, had the same issue myself.

    My solution (which compliments the above correct answer):
    Here's the list of fonts that Adobe installs with the Creative Suite 6:
    http://www.adobe.com/type/browser/fontinstall/cs6installedfonts.html

    1. Copy all these fonts to the separate folder and remove from the Windows/Fonts directory.
    2. Test CFPDFFORM bit and confirm it's working
    3. Manually add them back.

    In my case it turned out none of those fonts were corrupt per se, though probably weren't installed the way Windows like it. Re-installing it manually somewhat fixed the issue.

    One more note: I've removed all until MyriadPro (including it) constantly refreshing the page containing CFPDFFORM bit until it worked. So for those trying to get a fast fix, I'd recommend starting with MyriadPro family. It just may turn out it's the one that breaks the things.

    Hope this helps someone out!

    Participating Frequently
    November 15, 2012

    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:

            <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. 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 in the Windows\Font folder, fixing or isolating any corrupt fonts, and reinstalling them. It's painstaking but seems to work.

    Good luck!