Problem:Send a pdf file attachment

foronavision
Member Posts: 79
I have a report than i want to send by e-mail after convert it in pdf file. I have the following code in onPostReport
IF GeneradoAutomatico THEN BEGIN
CLEAR (PDFCreatorOption);
FileDirectory := Text024;
FileName := Text025 + FORMAT(FechaRecuento) + '.pdf';
IF ISCLEAR(PDFCreator) THEN
CREATE(PDFCreator);
IF ISCLEAR(PDFCreatorError) THEN
CREATE(PDFCreatorError);
PDFCreatorError := PDFCreator.cError;
IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN
ERROR('Status: Error: ' + PDFCreatorError.Description);
IF ISCLEAR(PDFCreatorOption) THEN
CREATE(PDFCreatorOption);
PDFCreatorOption := PDFCreator.cOptions;
PDFCreatorOption.UseAutosave := 1;
PDFCreatorOption.UseAutosaveDirectory := 1;
PDFCreatorOption.AutosaveDirectory := FileDirectory;
PDFCreatorOption.AutosaveFormat := 0;
PDFCreatorOption.AutosaveFilename := FileName;
PDFCreator.cOptions := PDFCreatorOption;
PDFCreator.cClearCache;
DefaultPrinter := PDFCreator.cDefaultPrinter;
PDFCreator.cDefaultPrinter := 'PDFCreator';
PDFCreator.cPrinterStop := FALSE;
Espera := 0;
REPEAT
Espera += 1;
UNTIL PDFfile.OPEN(FileDirectory + '\' + CONVERTSTR(FileName,'/','_'));
FicheroExistVinos := FileDirectory + '\' + CONVERTSTR(FileName,'/','_');
mail.NewMessage(DirEMailTo,DirEMailCC,Asunto, '',FicheroExistVinos,FALSE);
END;
The pdf file isn't attachmented to the e-mail because isn't generated. Could somebody say me which can be the problem?
Thanks a lot!
IF GeneradoAutomatico THEN BEGIN
CLEAR (PDFCreatorOption);
FileDirectory := Text024;
FileName := Text025 + FORMAT(FechaRecuento) + '.pdf';
IF ISCLEAR(PDFCreator) THEN
CREATE(PDFCreator);
IF ISCLEAR(PDFCreatorError) THEN
CREATE(PDFCreatorError);
PDFCreatorError := PDFCreator.cError;
IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN
ERROR('Status: Error: ' + PDFCreatorError.Description);
IF ISCLEAR(PDFCreatorOption) THEN
CREATE(PDFCreatorOption);
PDFCreatorOption := PDFCreator.cOptions;
PDFCreatorOption.UseAutosave := 1;
PDFCreatorOption.UseAutosaveDirectory := 1;
PDFCreatorOption.AutosaveDirectory := FileDirectory;
PDFCreatorOption.AutosaveFormat := 0;
PDFCreatorOption.AutosaveFilename := FileName;
PDFCreator.cOptions := PDFCreatorOption;
PDFCreator.cClearCache;
DefaultPrinter := PDFCreator.cDefaultPrinter;
PDFCreator.cDefaultPrinter := 'PDFCreator';
PDFCreator.cPrinterStop := FALSE;
Espera := 0;
REPEAT
Espera += 1;
UNTIL PDFfile.OPEN(FileDirectory + '\' + CONVERTSTR(FileName,'/','_'));
FicheroExistVinos := FileDirectory + '\' + CONVERTSTR(FileName,'/','_');
mail.NewMessage(DirEMailTo,DirEMailCC,Asunto, '',FicheroExistVinos,FALSE);
END;
The pdf file isn't attachmented to the e-mail because isn't generated. Could somebody say me which can be the problem?
Thanks a lot!
0
Comments
-
You have the loop for waiting until the file is created, but you have not set the WRITEMODE for the file. It means that the OPEN will succeed when the file is created, but it doesn't mean that the file is released and closed with the PDFCreator. You need to set the file variable into write mode, to try open the file for writing. This will succeed only if the file is released by PDFCreator...0
-
how can i get it?0
-
Espera := 0; PDFFile.WRITEMODE := true; //I want to write access to the file... REPEAT Espera += 1; UNTIL PDFfile.OPEN(FileDirectory + '\' + CONVERTSTR(FileName,'/','_'));
0 -
I try with this code and now the e-mail send but without the pdf file attachment, but this file exist in the directory. ](*,) I dont't know what i do0
-
Do not forget to close the file after you successfully opened it... ;-)0
-
when i execute the report continue in the loop
Espera := 0;
PDFfile.WRITEMODE := TRUE;
REPEAT
Espera += 1;
UNTIL PDFfile.OPEN(FileDirectory + '\' + CONVERTSTR(FileName,'/','_'));
PDFfile.CLOSE;
and don't exit. I run the report from the job scheduler, could be this the problem?0 -
foronavision wrote:when i execute the report continue in the loop
Espera := 0;
PDFfile.WRITEMODE := TRUE;
REPEAT
Espera += 1;
UNTIL PDFfile.OPEN(FileDirectory + '\' + CONVERTSTR(FileName,'/','_'));
PDFfile.CLOSE;
and don't exit. I run the report from the job scheduler, could be this the problem?
1) add condition to end when the Espera is greater than some max (and add some delay into the loop to not overstress the CPU - e.g. SLEEP(500)
2) If it never end it means that the file was not created or was created under different name or folder. Check if the PDF was created, if the name is correct and if the folder is correct...0 -
I had a customer who wanted to send multiple pdf files as e-mail attachments. I used PDFCreator, but could never figure out how to loop the codeunit until the event PDFCreator::eReady() fired. However, I solved it in another way. Maybe not the most elegant of solutions, but so far it's been working without any problems.
IF SalesHeader."REP Save as PDF" THEN BEGIN FileCreated := FALSE; SetSnoozeTime(); WHILE NOT FileCreated DO BEGIN FileCreated := PrintPDF(ReportID,FileName); IncrSnoozeTime(); END;
SetSnoozeTime resets integer variable to 3000, while IncrSnoozeTime increments the integer value by 1000.
And this is the function PrintPDF;IF ISCLEAR(PDFCreatorError) THEN CREATE(PDFCreatorError); PDFCreatorError := PDFCreator.cError; IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description); PDFCreatorOption := PDFCreator.cOptions; PDFCreatorOption.UseAutosave := 1; PDFCreatorOption.UseAutosaveDirectory := 1; PDFCreatorOption.AutosaveDirectory := SalesSetup."Path E-Mail Attachments"; PDFCreatorOption.AutosaveFormat := 0; //PDF file, you can also save in other formats PDFCreatorOption.AutosaveFilename := FileName; PDFCreator.cOptions := PDFCreatorOption; PDFCreator.cClearCache(); DefaultPrinter := PDFCreator.cDefaultPrinter; PDFCreator.cDefaultPrinter := 'PDFCreator'; PDFCreator.cPrinterStop := FALSE; REPORT.RUNMODAL(ReportID,FALSE,TRUE,SalesHeader2); SLEEP(SnoozeTime); PDFCreator.cPrinterStop := TRUE; PDFCreator.cDefaultPrinter := DefaultPrinter; PDFCreator.cClose(); IF EXISTS(SalesSetup."Path E-Mail Attachments" + FileName) THEN EXIT(TRUE) ELSE EXIT(FALSE);
I would welcome comments on my code, so that I might improve it. As I said it works fine and all the pdf attachments are generated, but it might not be the most time efficient way of doing things...
The last thing I did was to modify the codeunit Mail, so that it could send multiple attachments;SalesSetup.GET; SalesSetup.TESTFIELD("Path E-Mail Attachments"); recFile.SETRANGE(Path,'C:\'); IF recFile.FINDFIRST THEN ; //Do nothing. recFile.SETRANGE(Path,SalesSetup."Path E-Mail Attachments"); recFile.SETRANGE("Is a file",TRUE); IF recFile.FINDSET THEN REPEAT BSTRConverterAttachFileName.ResetBSTR; BSTRConverterAttachFileName.AppendNextStringPortion(recFile.Path + recFile.Name); OAttachments := OSendMail.Attachments; OAttachment := OAttachments.Add(BSTRConverterAttachFileName); ERASE(recFile.Path + recFile.Name); UNTIL recFile.NEXT = 0; OSendMail.OpenDialog := OpenDialog; MailSent := OSendMail.Send; ErrorNo := OSendMail.ErrorStatus; OApplication.Logoff;
0 -
I have just finished implementing PDFCreator Version 0.9.5 on VISTA Business.
Try using
REPEAT
UNTIL PDFCreator.cIsConverted;
Instead of thisEspera := 0;
REPEAT
Espera += 1;
UNTIL PDFfile.OPEN(FileDirectory + '\' + CONVERTSTR(FileName,'/','_'));
I found this function in PDFCreator Version 0.9.50
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions