2012-08-26 31 views
2

我使用Submit按鈕創建了一個帶有兩個表單字段(名字和姓氏(或FirstName和LastName))的快速PDF文件,並使用以下代碼嘗試填充這些字段一個新的PDF文件:ColdFusion CFPDFFORM不會填充PDF表單字段

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

不過,我收到此錯誤:

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 

我試着閱讀PDF文件,以確保表單字段是正確使用這一點,他們分別是:

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

<cfdump var="#fields#"> 

的結構轉儲出:

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

我試着搜索的Adobe文檔和周圍的一些其他網站,但無法找到此錯誤的解決方案。我還嘗試在需要的情況下向cfpdfform標籤添加一個「目標」參數,但獲得了相同的結果。 PDF文件確實存在。有任何想法嗎?提前致謝。

更新: 這裏是堆棧跟蹤:

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) 

回答

1

你沒有提到您是如何創建PDF文件。根據您創建PDF文件的方式,表單字段可能包含在子表單中。 LiveCycle中的模板生成的PDF將執行此操作。默認情況下,LiveCycle將命名子窗體「form1」。爲了填充這些表單域,您需要包含cfpdfsubform標籤。看到這裏的文檔:cfpdfsubform documentation

所以您的代碼會是這個樣子:

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

你包含閱讀PDF文件應該告訴你,如果字段包括在子窗體的代碼。轉儲將顯示包含在另一個結構中的表單域。這將是您在cfpdfsubform標籤的name屬性中使用的名稱。

HTH。

+1

的PDF是在Adobe Acrobat X Pro中創建。我確實檢查確定沒有子表單(沒有),但仍然存在問題。閱讀PDF時,它只顯示諸如FirstName,LastName等字段,但不嵌套在任何其他字段或結構中。使用CFPDFFORM會生成我指出的錯誤。不知道還有別的去。 – Whatevo

+1

您是否嘗試添加'overwriteData'屬性並將其設置爲'yes'?文檔狀態:指定是否使用數據源中的數據覆蓋PDF表單域中的現有數據: yes:使用數據源中的數據覆蓋表單域中的現有數據。 否:保留表單字段中的現有數據並僅填充沒有數據的字段。 此屬性適用於從XML數據源和cfpdfparam和cfpdfsubform標記提供的數據。 –

+1

嘗試添加overwriteData屬性並將其設置爲「是」,但仍然收到相同的錯誤。 – Whatevo

0

我剛剛意識到重新閱讀你的問題後,我走錯了路。我認爲你有一個問題填入pdf中的字段。但你真正的問題是空指針。衛生署!對此感到抱歉。

通常,這個錯誤告訴你,你正在使用的變量沒有被定義。我看到的唯一變量是#variables.AbsPath#。您正在指定變量範圍。那是對的嗎?變量作用域僅在其創建的頁面(以及包含的頁面)上可用。

您沒有包括如何定義該變量。你能分享一下嗎?

錯誤是隨機發生還是始終發生?

你確定錯誤發生在cfpdfform行而不是其他地方?我會在你的代碼周圍放一個cftry/cfcatch塊,並轉儲cfcatch結構以獲得更具體的錯誤。你可以嘗試一下並回復?

+0

好問題。我在同一頁面上的cfpdfform「填充」行上方定義變量.AbsPath。這只是PDF文件的路徑(我確認設置正確,因此如果需要,我不必繼續輸入)。我收到的錯誤總是出現在cfpdfform「填充」標籤上。 – Whatevo

+0

您是否嘗試過將路徑硬編碼到cfpdfform標記(不使用變量)以確認錯誤仍然存​​在? –

+0

@ Miguel-F - FYI如果您需要修改您的回覆,您隨時可以編輯現有答案。 – Leigh

6

我相信這是使用特定服務器的字體問題。這就是爲什麼相同的代碼可以在生產服務器上運行而不是在測試服務器上運行。我遇到了同樣的問題,雖然我沒有一個很好的解決方案,但這裏是我學到的東西。

  1. 堆棧跟蹤表明,有越來越的的OpenType字體getPlatformFontDescription錯誤。
  2. 我們的Windows服務器列出了一些TrueType字體爲OpenType。是你的?
  3. 使用下面的代碼糾正了這個問題,但它只是一個工作。

    <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. 更多診斷:簡單地列出所有可用的使用Java子系統也失敗服務器的字體。嘗試這個。

    <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. 我們已經從Windows \ Fonts文件夾刪除所有字體,並隔離那些破損的此刻「固定」我們的問題。這是艱苦的,但似乎工作。

祝你好運!

+2

+1。好寫。 Re:* flatten =「no」必須設置,否則您將再次得到錯誤*您也可以使用java.io.FileOutputStream而不是ByteArrayOutputStream直接保存到文件中。那麼就不需要最後的'cfpdf action =「write」'。 – Leigh

+0

謝謝Leigh,幫助我解決了一些與cfpdf有關的寫作問題。 – Aaron

2

我只是寫了一個腳本來解決這裏這個問題:https://stackoverflow.com/a/20408559/1223555

這與不具有語言環境或平臺名稱設置字體文件存在問題。 ColdFusion中的PDF功能調用此

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

此枚舉所有的字體,如果一個是壞的,它拋出一個異常,並殺死你的進程。

我的代碼枚舉了c:\ windows \ fonts中的所有字體,然後告訴你壞的。

這裏是我們的問題與個位:

AdobeNaskh-Medium.otf 
Mechanical.TTF 
msgothic.ttf 
MyriadArabic-Bold.otf 
MyriadArabic-BoldIt.otf 
MyriadArabic-It.otf 
MyriadArabic-Regular.otf 
+0

只是好奇,刪除壞的解決了錯誤? – Leigh