Voorbeeld van extenden van PDF-Tools rapport

  • 2 minutes to read

Hieronder voorbeeldcode van het extenden van een PDF-Tools rapport.
In dit voorbeeld passen we de geboekte verkoopfactuur aan:

  • aanpassen document-titel tekst en achtergrondkleur.
  • toevoegen van een lijn per artikel met een link.
  • toevoegen van een kolom met btw percentage.
  • toevoegen een barcode type EAN128.
  • aanpassen van de paginanummer tekst.
  • niet toepassen van briefpapier.
  • toevoegen van de verkoopsvoorwaarden aan het document.
  • verhinderen dat de verkoopsvoorwaarden als aparte bijlage aan de mail worden toegevoegd.

Voorbeeld pdf factuur

codeunit 50101 "CFL Invoice Ext"
{
    [EventSubscriber(ObjectType::Report, Report::"CFL Sales - Invoice", 'CFLOnAfterNewPage', '', false, false)]
    local procedure CFLonAfterNewPage(var PDFProgram: Codeunit "CFL PDFProgram")
    begin
        PDFProgram.CFLSetFieldBackgroundColor('TypeDocument', 255, 0, 0);
        PDFProgram.CFLSetField('TypeDocument', 'FACTUUR VERKOOP');
        PDFProgram.CFLSetField('BTWHeadingTest', 'BTW');
    end;

    [EventSubscriber(ObjectType::Report, Report::"CFL Sales - Invoice", 'CFLOnAfterAddLineToDocument', '', false, false)]
    local procedure CFLOnAfterAddLineToDocument(var SalesInvLine: Record "Sales Invoice Line"; var PDFProgram: Codeunit "CFL PDFProgram"; var intCounter: Integer)
    var
        CFLBarcodeBuffer: record "CFL Barcode Buffer";
        CFLBarcodeMgt: codeunit "CFL Barcode Management";
        BarcodeText: text;
        CFLBarCode: record "CFL Barcode";
        CFLBarcodeType: enum "CFL Barcode Type";
        CFLDOcument: record "CFL Document";
        CFLBocountSetup: record "CFL BoCount Base Setup";
        Counter: integer;
        AltBarcodeText: text;
        FNC1: text;
    begin
        CFLBocountSetup.Get();
        CFLDocument.get(CFLBocountSetup."CFL Invoice");
        PDFProgram.CFLSetField('BTW.' + format(intCounter - 1), '21%');
        if SalesInvLine.type = SalesInvLine.type::Item then begin
            PDFProgram.CFLSetField('Omschrijving.' + format(intCounter), 'klik hier voor meer informatie over dit artikel.');
            PDFProgram.CFLSetFieldHyperlink('Omschrijving.' + format(intCounter), 'http://www.google.be');
            intCounter += 1;
            //barcode
            Counter := PDFProgram.CFLGetNoOfRowsForImageHeight('Omschrijving.' + format(intCounter), 40, CFLDOcument.CFLGetFileBase64());
            CFLBarcodeBuffer.init;
            CFLBarcodeBuffer.Validate("CFL Application Identifier", '01');
            CFLBarcodeBuffer.Validate("CFL Value", '05437654786045');
            CFLBarcodeBuffer.insert();
            CFLBarcodeBuffer.init;
            CFLBarcodeBuffer.Validate("CFL Application Identifier", '10');
            CFLBarcodeBuffer.Validate("CFL Value", 'ABC-123');
            CFLBarcodeBuffer.insert();
            CFLBarcodeBuffer.init;
            CFLBarcodeBuffer.Validate("CFL Application Identifier", '17');
            CFLBarcodeBuffer.Validate("CFL Value", '211222');
            CFLBarcodeBuffer.insert();
            CFLBarCode.get('EAN128');
            FNC1 := CFLBarCode."CFL FNC1 Character";
            BarcodeText := CFLBarcodeMgt.CFLEncodeBufferToBarcode(CFLBarcodeBuffer, CFLBarCode."CFL Code");
            CFLBarcode.get('EAN128/MANUAL');
            AltBarcodeText := CFLBarcodeMgt.CFLEncodeBufferToBarcode(CFLBarcodeBuffer, CFLBarCode."CFL Code");
            PDFProgram.CFLSetFieldBarcode('Omschrijving.' + format(intCounter), BarcodeText, CFLBarcodeType::"CFL EAN128", 40, AltBarcodeText, FNC1);
            intCounter += Counter;
        end
    end;

    [EventSubscriber(ObjectType::Report, Report::"CFL Sales - Invoice", 'CFLOnBeforePageNumberOutputFile', '', false, false)]
    local procedure CFLOnBeforePageNumberOutputFile(var PageNoFormat: Text; Handled: Boolean; var PDFProgram: Codeunit "CFL PDFProgram")
    begin
        PageNoFormat := 'Pag. %1 van %2';
    end;

    [EventSubscriber(ObjectType::Report, Report::"CFL Sales - Invoice", 'CFLOnBeforeEndFillePage', '', false, false)]
    local procedure CFLOnBeforeEndFillePage(var PDFProgram: Codeunit "CFL PDFProgram"; var ApplyBackground: Boolean; var FormFlattening: Boolean)
    begin
        ApplyBackground := false;
    end;

    [EventSubscriber(ObjectType::Report, Report::"CFL Sales - Invoice", 'CFLOnBeforeCloseOutPutFile', '', false, false)]
    local procedure CFLOnBeforeCloseOutPutFile(var PDFProgram: Codeunit "CFL PDFProgram")
    var
        CFLBoCountSetup: record "CFL BoCount Base Setup";
        CFLDocument: record "CFL Document";
    begin
        CFLBoCountSetup.get();
        if CFLBoCountSetup."CFL Sales Conditions" <> '' then begin
            CFLDocument.get(CFLBoCountSetup."CFL Sales Conditions");
            PDFProgram.CFLAddPDFToOutputFile(CFLDocument.CFLGetFileBase64());
        end
    end;

    [EventSubscriber(ObjectType::Report, Report::"CFL Sales - Invoice", 'CFLOnBeforeAddSalesConditionsAttachment', '', false, false)]
    local procedure CFLOnBeforeAddSalesConditionsAttachment(var Attachments: Codeunit "Temp Blob List"; var AttachmentNames: List of [Text]; var Handled: Boolean)
    begin
        Handled := true;
    end;
}