Options

PDFCreator - Email attachment

teckpohteckpoh Member Posts: 271
Dear All,
I'm using PDFCreator to print and autosave pdf file and then using Codeunit 397 to auto send email to customer.

My problem is while PDFCreator is generating the PDF File, my outlook is sending the email(b4 pdfcreator finish generating the pdf) so it cant detect the attachment coz it's too fast(faster than PDFCreator). I tried using the SLEEP(20) to slower the report processing but it's failed below is my coding...help~~~


filename := 'C:\sentbox\tempFile.pdf';
testFile := EXISTS(filename);

IF testFile THEN BEGIN

myCust.RESET;
myCust.SETRANGE(myCust."No.","Sales Invoice Header"."Sell-to Customer No.");
IF myCust.FIND('-') THEN BEGIN
IF myCust."E-Mail" <> '' THEN BEGIN

EmailBody[1] := 'Regards,';
EmailBody[2] := 'IRG';
cr := 10;
lf := 13;
//BodyText := EmailBody[1]+FORMAT(cr)+FORMAT(lf)+EmailBody[2];
BodyText := EmailBody[1]+FORMAT(cr)+EmailBody[2];

mymail.NewMessage(myCust."E-Mail",'','Sales Invoice Report',BodyText,filename,FALSE);
mymail.Send();
END;
END;
END ELSE
MESSAGE('File not found');

Comments

  • Options
    teckpohteckpoh Member Posts: 271
    Anybody hv any idea?
  • Options
    teckpohteckpoh Member Posts: 271
    Anybody hv tis kind of experience b4?
  • Options
    ara3nara3n Member Posts: 9,255
    Hello

    The PDFCreator autmation has an event that is triggered once it's done. Create a single instance codeunit that will create the report. Make sure the automation variable has withevent enabled.

    From your code call the single instance codeunit to print the report.

    Inside the single instance codeunit you'll have a loop that will repeat until the event is triggered that is done. You can sleep inside the loop for a second.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    teckpohteckpoh Member Posts: 271
    Hi Ara3n,

    I already enable the event..i think the event that u mean is PDF::eReady
    I tried to put a MESSAGE('test') inside PDF::eReady() but it's not prompt the message at all..does tis mean the eReady event is not fire?

    How to check whether the pdf file is generated? how to check the trigger whether it's fire or not?
  • Options
    ara3nara3n Member Posts: 9,255
    you need to create a single instance CU and loop till eready is triggered.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    teckpohteckpoh Member Posts: 271
    Dear Ara3n,
    10s for ur replied. May i know how to loop the instance/Code unit? coz i've no idea how to check the eReady whether it's fire or not?

    Can u provide me a simple coding of looping the instance that check the eReady trigger? 10s a lot~
  • Options
    teckpohteckpoh Member Posts: 271
    Dear Ara3n/All,

    I managed to loop the codeunit/instance...using below code
    OnRUN()
    While myEReady = FALSE DO BEGIN
    GetmyEReadyValue() //tis will return the myEready
    END;

    But the code above made my report hang....

    And i use alternative way to implement it as below wihout looping:
    Let say i print report in a batch.
    Example Report A to Report C, and eReady only get fired when the Report C is completely generated. That mean system only able to send attached email to last recepient(Report C)

    And i wish to send the report to recepient A & B as well....Any idea?
  • Options
    ara3nara3n Member Posts: 9,255
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    teckpoh wrote:
    Dear All,
    I'm using PDFCreator to print and autosave pdf file and then using Codeunit 397 to auto send email to customer.

    My problem is while PDFCreator is generating the PDF File, my outlook is sending the email(b4 pdfcreator finish generating the pdf) so it cant detect the attachment coz it's too fast(faster than PDFCreator). I tried using the SLEEP(20) to slower the report processing but it's failed below is my coding...help~~~


    filename := 'C:\sentbox\tempFile.pdf';
    testFile := EXISTS(filename);

    IF testFile THEN BEGIN

    myCust.RESET;
    myCust.SETRANGE(myCust."No.","Sales Invoice Header"."Sell-to Customer No.");
    IF myCust.FIND('-') THEN BEGIN
    IF myCust."E-Mail" <> '' THEN BEGIN

    EmailBody[1] := 'Regards,';
    EmailBody[2] := 'IRG';
    cr := 10;
    lf := 13;
    //BodyText := EmailBody[1]+FORMAT(cr)+FORMAT(lf)+EmailBody[2];
    BodyText := EmailBody[1]+FORMAT(cr)+EmailBody[2];

    mymail.NewMessage(myCust."E-Mail",'','Sales Invoice Report',BodyText,filename,FALSE);
    mymail.Send();
    END;
    END;
    END ELSE
    MESSAGE('File not found');

    Try something like
    // PDFFile var of type FILE
    Window.open('@');
    REPEAT
    counter += 1;
    window.update(1,counter);
    UNTIL PDFFile.OPEN(PDFDir + '\' + PDFFile) OR (Counter > 10000);
    David Singleton
  • Options
    darshanmdarshanm Member Posts: 280
    Hi all,

    I have similar kind of requirement. I want to send the report
    as an attachment( html or pdf) to the user, automatically when report gets
    executed.

    Can anybody tell me what code should i put. ](*,)
    Darshan Mungekar
    Senior Consultan
  • Options
    maheshmahesh Member Posts: 115
    Hi frenzs,

    make a function.
    SendEmail(Cust."No.",DateFilter,ReportId,ReportName,EmailIdList);

    In this function
    --> Check mail id list
    --> Set file path (u can use by default Setup also)
    --> REPORT.RUNMODAL(ReportId,FALSE,FALSE,Rec)
    --> if report fails to run then generate error
    OR make a failure table & generate a report from dat if u r
    generating n sending reports to multiple customer (or Vendor)
    -->set pdf printer (we used PDF995, PDF Creator, Amyuni)
    --> CheckFileStatus
    In this function u write a code to check whether file is ready or not.
    As u know that Email function is too much fast, it will send an
    corrupt file.
    --> Using file function try to open it by code, if its get opened, close it
    otherwise wait using sleep.
    --> u can setup default wait time in company info card.
    --> if filestatus returns true then send mail.
    --> This works great, We made this one, installed for many clients. Even
    we implemented Email, Fax together which generates reports for
    multiple customer,vendor,contacts & send them at same time. U can
    also save them in Draft or send it directly using automation control.

    mErry chRisTmas 8)
    Best Regards,
    Mahesh Jain
    mahesh@reliconservices.com
  • Options
    darshanmdarshanm Member Posts: 280
    Thanks a lot dear. Dhanyavad
    Darshan Mungekar
    Senior Consultan
  • Options
    MiniMini Member Posts: 17
    I am using PDFCreator to generate PDF files and send the file thru email. Once the file will send I want to reset my system printer as default Printer(not PDFCreator printer).

    Is any body can suggest how can I reset my default printer?

    Thanks
    Mini
  • Options
    ara3nara3n Member Posts: 9,255
    DefaultPrinter := PDFCreator.cDefaultPrinter;
    PDFCreator.cDefaultPrinter := 'PDFCreator'; 
    
    
    PDFCreator.cDefaultPrinter := DefaultPrinter;
    PDFCreator.cClose();
    



    The DefaultPrinter is copied to txt variable and then assigned at the end.
    Are you doing that?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    MiniMini Member Posts: 17
    Yes I am doing this. Written on OnEvent of PDFCreator::eReady().

    I also write this code once email is send. But not working.:(

    ara3n wrote:
    DefaultPrinter := PDFCreator.cDefaultPrinter;
    PDFCreator.cDefaultPrinter := 'PDFCreator'; 
    
    
    PDFCreator.cDefaultPrinter := DefaultPrinter;
    PDFCreator.cClose();
    



    The DefaultPrinter is copied to txt variable and then assigned at the end.
    Are you doing that?
  • Options
    ara3nara3n Member Posts: 9,255
    put a breakpoint and see what DefaultPrinter is set to at the begging and once you are assigning it back. What are the values?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.