2013-11-26 92 views
2

我通過批處理作業生成報告pdf文件時遇到了問題。它的工作原理,當一個批處理作業執行,除了罰款(有時它的工作原理,但大多數的時候我已經損壞的PDF文件):在AX 2009中通過批處理作業生成損壞的pdf文件

while(qr.next()) //loop on my quotationId with some filters 
     { 
     salesQuotation = qr.get(tablenum(salesQuotationTable)); 
     filenamePDF = strfmt("%1%2",SalesQuotation.QuotationId,".pdf"); 

     permissionSetPDF = new Set(Types::Class); 
     permissionSetPDF.add(new FileIOPermission(filenamePDF,'w')); 
     permissionSetPDF.add(new InteropPermission(InteropKind::ClrInterop)); 
     CodeAccessPermission::assertMultiple(permissionSetPDF); 

     report = new ReportRun(new Args(ReportStr(DevisContactBusinessV2))); 
     report.query().interactive(false); 
     report.report().interactive(false); 
     report.args().caller(null); 

     report.args().parm(SalesQuotation.QuotationId); 

     report.printJobSettings().setTarget(PrintMedium::File); 
     report.printJobSettings().format(PrintFormat::PDF); 
     report.printJobSettings().warnIfFileExists(false); 
     report.printJobSettings().fileName(strfmt("%1%2",path,filenamePDF)); 

     report.run(); 

     //tried to get around the file size problem by execute pdf file generation outside the loop 
     fi = new System.IO.FileInfo(strfmt('%1%2',path,filenamePDF)); 
     length = fi.get_Length(); 

     if(length <= 1000) 
      { 
       info(strfmt("%1 %2","Quotation problem",SalesQuotation.QuotationId)); 
       this.OBRfixPDF(salesQuotation.QuotationId); 
      } 
     else 
      { 
       info(strfmt("%1 %2","Quotation OK:",SalesQuotation.QuotationId)); 
      } 

     CodeAccessPermission::revertAssert(); 
    } 

生成的文件似乎已損壞,他們有一個大小爲1 KO,並且無法讀取。報告中沒有圖像,我使用沒有SP1的AX 2009。

回答

1

我有同樣的問題,並相信它與否與字體和字體緩存。我不得不做出一些改變,但你需要做的第一件事是:

report.printJobSettings.format(PrintFormat::PDF_Embed_Fonts); 

然後在班「的ClassFactory」 createViewer方法添加一個名爲「noFontCache」下的情況下,「ReportOutputUserType :: PDFEmbedFonts一個布爾變量在類PDF查看器

noFontCache = true; 
return new PDFViewer(jobsCursor,pagesCursor,true,noFontCache); 

那麼新mehtod下,改變方法的簽名是::,更改代碼爲以下然後

public void new(PrintJobHeader _jobCursor, PrintJobPages _pagesCursor, boolean _embedFonts = false, boolean _noFontCache = false) 

,只是前在該方法結束時的超級呼叫添加以下代碼:

if(_noFontCache) 
{ 
    pdfFontCache = new SysPdfFontCache(); 
} 
else 
{ 
    pdfFontCache = infolog.getPdfFontCache(); 
} 

這允許AX以生成新的字體緩存,而不是使用現有的(將其通過他們的客戶端機器上的用戶這是產生現在與批處理作業運行的服務器不同)。