2016-02-16 147 views
2

我需要找到一种方法来打印SrsReport,在我的情况下,SalesInvoice,作为.PDF(或任何类型的文件)到一个特定的位置。打印SSRSReport到文件(.PDF)

为此,我修改了SRSPrintDestinationSettings输出SalesInvoice-报告为.PDF:

settings = controller.parmReportContract().parmPrintSettings(); 
settings.printMediumType(SRSPrintMediumType::File); 
settings.fileFormat(SRSReportFileFormat::PDF); 
settings.overwriteFile(true); 
settings.fileName(@'\\AXDEV\Bottomline\Test\test.pdf'); 

不知怎的,这个被忽略,我recive附带的报告.PDF一个电子邮件。

例如,这将在ax 2012上运行,但不会为我打印为PDF。

SRSPrintDestinationSettings  settings; 
CustInvoiceJour   custInvoiceJour; 
SrsReportRunController   controller = new SrsReportRunController(); 
PurchPurchaseOrderContract rdpContract = new PurchPurchaseOrderContract(); 
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract(); 

select firstOnly1 * from custInvoiceJour where custInvoiceJour.SalesId != ""; 

// Define report and report design to use 
controller.parmReportName(ssrsReportStr(SalesInvoice,Report)); 
// Use execution mode appropriate to your situation 
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous); 


rdpContract.parmRecordId(custInvoiceJour.RecId); 
controller.parmReportContract().parmRdpContract(rdpContract); 

// Explicitly provide all required parameters 
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty 
controller.parmReportContract().parmRdpContract(salesInvoiceContract); 
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release 

// Change print settings as needed 
settings = controller.parmReportContract().parmPrintSettings(); 
settings.printMediumType(SRSPrintMediumType::File); 
settings.fileFormat(SRSReportFileFormat::PDF); 
settings.overwriteFile(true); 
settings.fileName(@'\\AXDEV\Bottomline\Test\test.pdf'); 

//tokens = settings as SrsPrintDestinationTokens(); 
//controller.parmPrintDestinationTokens(null); 

//Suppress report dialog 
controller.parmShowDialog(false); 
// Execute the report 
controller.startOperation(); 

问题: 这是打印srsReport为pdf格式正确的方法是什么? 我是否正确地传递/设置printerSettings? 它说“发送电子邮件”在哪里?

编辑:代码工作正常。我们正在使用一个公司的外部代码,它根本没有实现这一点。 使用Alex Kwitny的清洁代码

回答

5

这里是工作的代码我。我只是快速地从头开始编写这个代码,基于对你的看法,所以比较差异。

我有两件事标记为(1)和(2),您可以尝试使用您的代码,或者只是复制/粘贴我的代码。

static void JobSendToPDFInvoice(Args _args) 
{ 
    SrsReportRunController   controller = new SrsReportRunController(); 
    SRSPrintDestinationSettings  settings; 
    CustInvoiceJour     custInvoiceJour = CustInvoiceJour::findRecId(5637925275); 
    SalesInvoiceContract   salesInvoiceContract = new SalesInvoiceContract(); 
    Args       args = new Args(); 

    controller.parmReportName(ssrsReportStr(SalesInvoice, Report)); 
    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous); 
    controller.parmShowDialog(false); 

    salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); 
    salesInvoiceContract.parmDocumentTitle(CustInvoiceJour.InvoiceId); 
    salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); 

    // (1) Try by passing args 
    args.record(custInvoiceJour); 
    args.parmEnum(PrintCopyOriginal::Original); 
    args.parmEnumType(enumNum(PrintCopyOriginal)); 

    controller.parmReportContract().parmRdpContract(salesInvoiceContract);  
    controller.parmArgs(args); 

    // (2) Try explicitly preventing loading from last value 
    // controller.parmLoadFromSysLastValue(false); 

    // Change print settings as needed 
    settings = controller.parmReportContract().parmPrintSettings(); 
    settings.printMediumType(SRSPrintMediumType::File); 
    settings.fileFormat(SRSReportFileFormat::PDF); 
    settings.overwriteFile(true); 
    settings.fileName(@'C:\Temp\Invoice.pdf'); 


    controller.startOperation(); 
} 
+0

代码和我的一样,但是更好:D。代码应该适用于其他人。问题是我的公司使用了名为Bottomline的公司的技术。看起来它不支持PDF输出。我将不得不修改它。感谢您的帮助=) – C0d1ngJammer

1

由于您在讨论销售发票,因此报告使用的是打印管理功能,您不能简单地覆盖此类打印设置。

您需要覆盖控制器类上的runPrintMgmt,并确定是否需要默认打印管理或您自己的代码。

看到这个职位的一个例子:http://www.winfosoft.com/blog/microsoft-dynamics-ax/manipulating-printer-settings-with-x

+0

Aww no。所以我真的需要重写它。我虽然可以绕过这个; /。非常感谢这个链接。我会尽快尝试。 – C0d1ngJammer

+1

我不相信你需要这样做,请参阅下面的答案。他使用'SrsReportRunController',而不是'SrsPrintMgmtController' –