Hi
I don't know whether it is correct forum or not. I have below code in Sap B1 . In this scenario Default printer shoule be PDF . Secondly it asks for path. Is there any way to set the name and path through code so the exporting of the layout becames automatic? Below is the Code.
C#
SAPbobsCOM.CompanyService oCmpSrv;
SAPbobsCOM.ReportLayoutsService oReportLayoutService;
SAPbobsCOM.ReportLayoutPrintParams oPrintParam;
oCmpSrv = oCompany.GetCompanyService();
oReportLayoutService = (ReportLayoutsService)oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService);
oPrintParam = (ReportLayoutPrintParams)oReportLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutPrintParams);
oPrintParam.LayoutCode = "INV20014";
oPrintParam.DocEntry = 350;
oReportLayoutService.Print(oPrintParam);Thanks

Emily FosterRank #3,495 · 415 reputationPosted Mar 11, 2025, 9:19 AM EDT
Absolutely! It seems like you're looking for a way to automatically save the output of the SAP Business One report layout to a PDF file, with the ability to specify the file path and name via code.
In your scenario, you are currently dealing with SAP Business One's SDK (Software Development Kit) in C# code. To achieve automatic PDF output with customizable file path and name, you typically need to make use of additional functionalities within the SDK.
Here is the general approach you can take:
1. Specify PDF as the Default Printer:
- Before printing the report layout, you can set the default printer to a PDF printer. This way, the output will automatically be saved as a PDF file.
2. Customize File Path and Name:
- You can modify your existing code to include logic that allows you to set the desired file path and name before triggering the printing process. This can be done by updating the `oPrintParam` object properties.
Below is an example of how you could potentially enhance your existing code:
SAPbobsCOM.CompanyService oCmpSrv; SAPbobsCOM.ReportLayoutsService oReportLayoutService; SAPbobsCOM.ReportLayoutPrintParams oPrintParam; oCmpSrv = oCompany.GetCompanyService(); oReportLayoutService = (ReportLayoutsService)oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService); oPrintParam = (ReportLayoutPrintParams)oReportLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutPrintParams); oPrintParam.LayoutCode = "INV20014"; oPrintParam.DocEntry = 350; // Set the default printer to PDF (code snippet may vary based on SDK functionalities) oPrintParam.Printer = "Name of the PDF Printer"; // Set the file path and name for the PDF output oPrintParam.DocumentPath = "C:\\Your\\Desired\\Path\\FileName.pdf"; oReportLayoutService.Print(oPrintParam);Remember, the specifics may vary based on the capabilities provided by the SAP Business One SDK and the methods available in the `ReportLayoutsService`. Make sure to consult the SDK documentation or reach out to SAP support for detailed guidance on how to achieve automatic PDF output with customized file paths in your SAP Business One environment.
If you need further assistance or more detailed examples, feel free to ask!
Ramco RamcoRank #462 · 5.4K reputationPosted Mar 11, 2025, 10:49 AM EDT
Hi
oPrintParam does not have Printer & DocumentPath properties.
Thanks
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 11, 2025, 9:08 PM EDT
Hello Ramco,
Yes, you can automate the export of the layout to PDF in SAP Business One without prompting for a file path. You need to use the ExportReportToFile method instead of
Print(), specifying the file path and name in the code.Solution
Modify your code to:
Updated Code
SAPbobsCOM.CompanyService oCmpSrv; SAPbobsCOM.ReportLayoutsService oReportLayoutService; SAPbobsCOM.ReportLayoutExportParams oExportParam; oCmpSrv = oCompany.GetCompanyService(); oReportLayoutService = (SAPbobsCOM.ReportLayoutsService)oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService); oExportParam = (SAPbobsCOM.ReportLayoutExportParams)oReportLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutExportParams); // Set the Layout Code oExportParam.LayoutCode = "INV20014"; oExportParam.DocEntry = 350; // Set the Export Path and File Name oExportParam.ExportType = SAPbobsCOM.BoReportLayoutExportType.lfet_PDF; oExportParam.ExportFilePath = @"C:\Exports\Invoice_350.pdf"; // Set the desired path // Export the layout as a PDF oReportLayoutService.ExportReportToFile(oExportParam);Good Luck!