Use the following code to converting in pdf format

DarkHorseDarkHorse Member Posts: 389
Dear folks, I've asked this problem long ago but I left it because I can't find the solution. I used the search to find information about creating documents in pdf but I want to take my code to do it.
I've a commmand button on Sales Order form that, on pushing it, creates the sales order in html format and automatically insert it in a mail, and it runs perfectly; but now I want to do it in pdf format. I've Adobe Acrobat 8 Professional installed and I want to use it. This is the code in OnPush trigger:
RecOrder.RESET;
RecOrder.SETRANGE("Document Type","Document Type");
RecOrder.SETRANGE("No.","No.");
IF RecOrder.FIND('-') THEN BEGIN

IF RecCustomer.GET("Bill-to Customer No.") THEN BEGIN
rptOrder.SETTABLEVIEW(RecQuote);
rptOrder.SAVEASHTML('C:\Sales order.html');
SLEEP(2000);

CodeMail.NewMessage(RecCustomer."E-Mail",'','SALES ODER' + "No.",
'We send your sales order ' + "No.",'C:\Sales order.html',TRUE);

END;
END;

RecOrder is Sales Header table
rptOrder is my "Order confirmation" report
RecCustomer is Customer table
CodeMail is the codeunit Mail

Does anybody know how I cant create it using Adobe acrobat?.
Thanks in advance for help.

Comments

  • matttraxmatttrax Member Posts: 2,309
    Download a PDF printer like CutePDF and send it to that printer.

    On another note, there are a few issues with your code.

    1) The output file name is hard coded, and the file is not deleted afterward. If there was a problem overwriting that file, you might mistakenly send another customer's invoice to that customer.

    2) Don't just do a SLEEP for a certain amount of time. You never know if some other process is going to come along and steal your CPU. Query the File table to see if the file has been created. If it hasn't, THEN do a sleep for a few seconds and try again. You'll need a maximum time that you want to keep looking for it.
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. Thanks for advise me about SLEEP code. I know about overwriting the file, it was a question for the future :wink: , thanks for advise so.
    But, by now, I don't want to install another software printer, I'll have to install in every user, I want to use Acrobat; is ther any way to use it?.
    Thanks for help.
  • DarkHorseDarkHorse Member Posts: 389
    Any idea please?.
    Thanks.
  • DarkHorseDarkHorse Member Posts: 389
    UP!!, does anybody knows something about it?.
    Thanks for reply.
  • ara3nara3n Member Posts: 9,256
    To use adobe acrobat, you need to check the if adobe spooler or adobe printer settings .
    or option to automatically save the printed documents into a folder.

    You have to change your code to print the report, and assume that the adobe is the default printer.
    Afterwords keep monitoring the folder and see that the pdf file is created and that you can change the datetime on it (this means the printing is done);

    then you can attach it to your email.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply.
    You have to change your code to print the report, and assume that the adobe is the default printer.

    This is the problem, now, on save in html format is easy, I put file.SAVEASHTML('C:\file.html'); and after put it in a mail; but I don't know what is the code on printing it in pdf format.
    Thanks for help.
  • ara3nara3n Member Posts: 9,256
    you simply run

    REPORT.RUNMODAL(Number [, ReqWindow = false] [, SystemPrinter = true] [, Record with filters]);
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply, but how it will be with my code?, I mean, I don't know how do Systemprinter for example, it's a variable o is the name of the printer?.
    Thanks.
  • ara3nara3n Member Posts: 9,256
    system printer is a boolean, and I gave you the value true.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply; and waht is "Number"?, because I put the number of the report but it show's me an error.
    Thanks for help.
  • ara3nara3n Member Posts: 9,256
    The Number is Report ID. What error are you getting?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply; the error says "is missing a ')' " an stops on the report number. Also I don't know what is Reqwindows and Record with filters.
    Thanks.
  • ara3nara3n Member Posts: 9,256
    Your code should something like this.
    REPORT.RUNMODAL(50012, false, true, RecOrder);
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Perfect!!, it works!!, only one question more and and forgive abusing your kindness :oops: It creates the pdf with a generic name, I mean 8485499.pdf or so, how can I give a specific name to the document?.
    Thank you very much for your help.
  • ara3nara3n Member Posts: 9,256
    Once it creates the pdf document, you can add code to rename it
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Do you know that code, please?.
    Thanks for help.
  • ara3nara3n Member Posts: 9,256
    put your latest code and I'll make the necessary changes.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Sorry, I don't understand; my code go to an specific document created with saveashtml, but in this case it createsa different pdf name each time that I run the code, I can't look for it if always change the name.
    Thanks for help.
  • ara3nara3n Member Posts: 9,256
    you can see search for a *.pdf file in the folder it is being saved. use the virtual table "File" to set filters.


    MyFolder datatype = record, subtype File

    clear(MyFolder);
    MyFolder.setrange("Directory",'c:\someFolder');
    MyFolder.setrange("is file",true);
    MyFolder.setfilter(Name,'*.pdf');
    if MyFolder.findfirst
    message(MyFolder.Name);


    There are other examples on this website for find a file in a folder.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Ok; I'll try it. Thank you very much for your help and time. Only one question, I think is by I've Attain 3.70, What are "Directory" and "is file", I don't find the equal in my version.
    Thanks.
  • ara3nara3n Member Posts: 9,256
    i'v fixed the code it's "path" and "is a file"
    clear(MyFolder);
    MyFolder.setrange(Path,'c:\someFolder');
    MyFolder.setrange("is a file",true);
    MyFolder.setfilter(Name,'*.pdf');
    if MyFolder.findfirst
    message(MyFolder.Name);
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DarkHorseDarkHorse Member Posts: 389
    Ok; It's correct!!, thank you very much for your help and time.
    Thanks again.
  • nav_126nav_126 Member Posts: 77
    Hi,

    I understood the problem and solution both, but can you tell me which printer should i use which will save my file in a pdf format automatically?

    Is it a freeware or we need to buy a licensed version? Pls Help


    Thnx
    Navision Developer
  • ara3nara3n Member Posts: 9,256
    When you install a PDF printer it will create a new Printer in your printer folder.

    Acrobat pdf printer i believe you need to purchase.
    Bullzip is freeware for up to 10 people.
    PDFCreator is freeware.
    CutePDF is not free
    PDF95 is not free.

    There are several threads on each pdf printer
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • nbangazanbangaza Member Posts: 30
    Thank you very much Darkhorse for your post, you've certainly helped me a lot.
    I've been trying to automatically send orders to customers for weeks.


    Regards,
    N
Sign In or Register to comment.