Print Sales Invoice to PDF file from code

You can print an existing Sales invoice to a PDF file named as SalesInvoice_<InvoiceId>.pdf through the following code, regardless of how the Print Management setup of Sales Invoice might look like:

2 thoughts on “Print Sales Invoice to PDF file from code

  1. Hi,

    For Email, we have mentioned PrintMediumType as Email_DC.

    How to get all defaults value from PrintManagement (Docentric) setup for Email setting?
    emailPrintDestSettings should get it from Print management. Here system is allowing only when giving all details.
    .
    VendInvoiceDocumentController vendInvoiceController;
    VendInvoiceDocumentContract vendInvoiceContract;
    VendInvoiceJour vendInvoiceJour;
    SRSPrintDestinationSettings srsPrintDestSettings;
    DocPrintDestSettingsEmail emailPrintDestSettings;

    vendInvoiceController = new VendInvoiceDocumentController();
    vendInvoiceController.parmArgs(args);
    vendInvoiceController.parmShowDialog(false);
    vendInvoiceController.parmLoadFromSysLastValue(false);
    vendInvoiceController.parmReportName(
    PrintMgmtDocType::construct(PrintMgmtDocumentType::PurchaseOrderInvoice).getDefaultReportFormat());
    vendInvoiceContract = vendInvoiceController.parmReportContract().parmRdpContract();
    vendInvoiceContract.parmRecordId(invoiceJour.RecId);
    vendInvoiceContract.parmDocumentTitle(“@SYS99734″);
    vendInvoiceContract.parmPrintCopyOriginal(PrintCopyOriginal::OriginalPrint);
    vendInvoiceController.parmReportContract().parmRdpContract(vendInvoiceContract);
    srsPrintDestSettings = new SRSPrintDestinationSettings();
    srsPrintDestSettings.printMediumType(SRSPrintMediumType::Email_DC);
    srsPrintDestSettings.fileFormat(SRSReportFileFormat::PDF);
    srsPrintDestSettings.overwriteFile(true);
    str filename = strfmt(‘CN-%1.pdf’,invoiceJour.InvoiceId);
    srsPrintDestSettings.fileName(filename);
    emailPrintDestSettings =new DocPrintDestSettingsEmail ();
    emailPrintDestSettings.parmEmailAttachmentName(filename);
    emailPrintDestSettings.parmEmailAttachmentFileFormat(DocOutputFileFormat::PDF);
    emailPrintDestSettings.parmEmailFrom(‘from address’);
    emailPrintDestSettings.parmEmailTo(‘to address’);
    emailPrintDestSettings.parmEmailSubject(‘Auto docentric email subject’);
    emailPrintDestSettings.parmEmailBody(”);
    srsPrintDestSettings.parmEmailPrintDestSettings_DC(emailPrintDestSettings);
    vendInvoiceController.parmReportContract().parmPrintSettings(srsPrintDestSettings);
    vendInvoiceController.startOperation();

    Thanks,

    1. For a precise answer we would need to know your specific use case.

      If you just want to send VendInvoiceJour report from code using the Print management setting, the easiest way is to invoke output menu item PurchInvoice with selected VendInvoiceJour record.

      If you want to load the current (default) Print management settings and change them later use the code below.

      DocPrintMgmtSettingsEntity printMgmtSettingsEntity;

      select firstOnly printMgmtSettingsEntity where
      printMgmtSettingsEntity.DocInstanceDocumentType == PrintMgmtDocumentType::PurchaseOrderInvoice &&
      printMgmtSettingsEntity.DataArea == curExt();

      SRSPrintDestinationSettings srsPrintDestSettings = new SRSPrintDestinationSettings();
      srsPrintDestSettings.unpack(printMgmtSettingsEntity.PrintJobSettings);

      If you need further help on your specific case, please contact support@docentric.com.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Docentric respects your privacy. Learn how your comment data is processed >>