Pages

Wednesday, January 16, 2008

Fill in PDF based forms from AX

I stumbled accross the AX class PDFFiller the other day, while investigating some PDF stuff.

It turns out that you can use this report to fill in PDF based forms. The forms must of course be created so it allows the reader to fill in form fields.

The data from the form fields are stored in a file with XFDF extension, an XML file, and this paired with the initial PDF file gives you the filled in form to show on screen or print.

The PDFFiller class is in the standard only used by the Austrian tax report. See \Classes\TaxReport_ReportAT\fillPDFFile.

Also here is a short sample, assuming the PDF file has a "FieldA" and "FieldB" field:
static void PDFFiller(Args _args)
{
PDFFiller PDFFiller;;

PDFFiller = PDFFiller::construct();

PDFFiller.parmPdfFileName("C:\\testpdf.pdf");

PDFFiller.addStrField("FieldA", "This is for the first field");
PDFFiller.addStrField("FieldB", "This is for the second field");

PDFFiller.showFDF();
}

Monday, January 14, 2008

Print PDF files from AX to specific printer

This job illustrates how you can print an external PDF file to a printer choosen in AX:

static void pdfprint(Args _args)
{
PrintJobSettings printJobSettings = new PrintJobSettings();
Dialog dialog = new Dialog();
DialogField dialogFileName;
str adobeExe;
str adobeParm;
;
dialogFilename = dialog.addField(typeid(FilenameOpen));

if (dialog.run())
{
printJobSettings.printerSettings('SysPrintForm');
adobeExe = WinAPI::findExecutable(dialogFileName.value());

adobeParm = strFmt(' /t "%1" "%2" "%3" "%4"',
dialogFileName.value(),
printJobSettings.printerPrinterName(),
printJobSettings.printerDriverName(),
printJobSettings.printerPortName());

winAPI::shellExecute(adobeExe, adobeParm);
}
}

Monday, January 7, 2008

Get the literal label of an enum value

I couldn't find a function in the standard to give me the literal label (@SYSxxxx) of an enum value, so I came up with this prototype:

static void literalLabelsFromEnum(Args _args)
{  
    #Properties         
    SysDictEnum sysDictEnum = new SysDictEnum(enumNum(SysDimension));  
    TreeNode    treeNode;  
    int         x;     
    ;
     
    for (x = 0; x <= SysDictEnum.lastValue(); x++) 
    {           
        treeNode = TreeNode::findNode(sysDictEnum.path() + '\\' + sysDictEnum.index2Symbol(x));           
        print sysDictEnum.index2Label(x)+ '  ' + findProperty(treeNode.AOTgetProperties(),#PropertyLabel);     
    }     
    pause;
}