How to set password protected PDF file in NAV 2009?

Hi FRiends,

[Version: 2009 SP1 Classic Client]

I need to convert Customer Statement (and Sales Invoice) report to PDF and send to customer's e-mail ID which is mentioned in Customer card. I can able to convert into PDF and attach send as an e-mail successfully.

I am facing couple of issues:

1. How to set password to the PDF file (Password: Customer No.)?
2. How to avoid the dialog window SaveAs (show the path to store the file)?

Below are the local variables defined in the function SaveCustStatementInPDF, I am using.
Customer (Record) -	Customer	
File1	(Automation) -	'Microsoft Scripting Runtime'.FileSystemObject	
Filename1(Text200)
RunOnceFile (Text250)
TimeOut (Integer		)
SalesStat (Report) - Statement report

Code in the function...

SaveCustStatementInPDF(CustNo : Code[20]) : Text[250]

SMTPSetup.GET;
Customer.SETRANGE("No.",CustNo);

IF Customer.FINDSET THEN BEGIN

  IF ISCLEAR(File1) THEN
     CREATE(File1);

  IF ISCLEAR(BullZipPDF) THEN
    CREATE(BullZipPDF);
  

  IF NOT File1.FolderExists(SMTPSetup."Path to Save Report") THEN
    File1.CreateFolder(SMTPSetup."Path to Save Report");

  Filename1:= SMTPSetup."Path to Save Report" +'Statement' + '.pdf';

  IF EXISTS(Filename1) THEN
    ERASE(Filename1);

   BullZipPDF.Init;
   BullZipPDF.LoadSettings;
   RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
   
   BullZipPDF.SetValue('ShowSaveAs','never');
   BullZipPDF.SetValue('OwnerPassword','abc');
   BullZipPDF.SetValue('UserPassword', CustNo);
   BullZipPDF.SetValue('KeyLength', 'Standard128bit');

   BullZipPDF.SetValue('Output',Filename1);
   BullZipPDF.SetValue('ShowSaveAS','never');
   BullZipPDF.SetValue('Showsettings', 'never');
   BullZipPDF.SetValue('ShowPDF', 'no');
   BullZipPDF.SetValue('ShowProgress', 'no');
   BullZipPDF.SetValue('ShowProgressFinished', 'no');
   BullZipPDF.SetValue('SuppressErrors', 'yes');
   BullZipPDF.SetValue('ConfirmOverwrite', 'no');

   BullZipPDF.WriteSettings(TRUE);

   SalesStat.SETTABLEVIEW(Customer);
   SalesStat.USEREQUESTFORM(FALSE);
   SalesStat.RUNMODAL;

   TimeOut := 0;
   WHILE EXISTS(RunOnceFile) AND (TimeOut < 30) DO BEGIN
       SLEEP(1000);
       TimeOut += 1;
   END;

    CLEAR(File1);
    CLEAR(BullZipPDF);
END;

EXIT(Filename1);

Can anyone help me how to solve this?

Thanks in advance, Aarvi.

Comments

  • geronimogeronimo Member Posts: 90
    does it do any of the settings?
    if i remember correctly you have to select the printer before doing the settingsfile

    something along the lines of

    BullZipPDF.PrinterName := PrinterName;

    before the init
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Nope. None of the BullZipPDF setting is working.
  • SogSog Member Posts: 1,023
    Oh wow this has been a while. It has something to do with the bullzip settingsfile being written to some folder that's then not used during the print. It's a bullzip bug/compatibility issue with the nav 3-tier scenario. You have to make sure that the runonce settings file is being picked up correctly. Make sure that after the bullzipPDF.Writesettings command, the appropriate file is stored in the correct location:
    See more at wiki.bullzip.com/pdf-printer/documentation/reference/configuration-files
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Geronimo/Sog.. Thanks a lot for your responses. I have sorted the issue. I have created a new table Printer Selection and wrote below code..
    IF NOT PrinterSelection.GET('',50003) THEN BEGIN
      PrinterSelection.INIT;
      PrinterSelection."Report ID" := 50003;
      PrinterSelection."Printer Name" := 'Bullzip PDF Printer';
      PrinterSelection.INSERT;
    END;
    
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    I have another issue where I got struct. I need to merge the Open Invoices in one single pdf file.

    Function: SendMailToRegOpenInvoices
    Locals:
    Parameter
    CustNo (Code20)
    
    Variables:
    Customer (Record) -	Customer	
    File1	(Automation) -	'Microsoft Scripting Runtime'.FileSystemObject	
    Filename1- (Text200)
    RunOnceFile - (Text250)
    TimeOut - (Integer)
    SalesInv (Report) - Sales Invoice report
    SalesInvoice - (Record) - Sales Invoice Header	
    PrinterSelection - (Record) - Printer Selection	
    CustLedgEntry - (Record) - Cust. Ledger Entry	
    InvoiceNo - (Code20)
    mergeAfterFilename - (Text200)
    

    Coding..

    SendMailToRegOpenInvoices(CustNo : Code[20])
    
    SMTPSetup.GET;
    Customer.GET(CustNo);
    CustLedgEntry.SETCURRENTKEY("Customer No.",Open,Positive,"Due Date","Currency Code");
    CustLedgEntry.SETRANGE(CustLedgEntry."Customer No.",CustNo);
    CustLedgEntry.SETRANGE(Open,TRUE);
    CustLedgEntry.SETRANGE(CustLedgEntry."Document Type",CustLedgEntry."Document Type"::Invoice);
    
    IF CustLedgEntry.FINDFIRST THEN BEGIN
      REPEAT
        InvoiceNo := CustLedgEntry."Document No.";
    
        SalesInvoice.SETFILTER(SalesInvoice."No.",InvoiceNo);
        IF SalesInvoice.FINDFIRST THEN BEGIN
    
          IF ISCLEAR(File1) THEN
            CREATE(File1);
    
          IF ISCLEAR(BullZipPDF) THEN
          CREATE(BullZipPDF);
    
          IF NOT File1.FolderExists(SMTPSetup."Path to Save Inv. Report") THEN
            File1.CreateFolder(SMTPSetup."Path to Save Inv. Report");
    
          Filename1:= SMTPSetup."Path to Save Inv. Report" +'SalesInvoice' + '.pdf';
          mergeAfterFilename := SMTPSetup."Path to Save Inv. Report" +'SalesInvoiceA' + '.pdf';
    
          IF NOT PrinterSelection.GET('',50003) THEN BEGIN
            PrinterSelection.INIT;
            PrinterSelection."Report ID" := 50003;
            PrinterSelection."Printer Name" := 'Bullzip PDF Printer';
            PrinterSelection.INSERT;
          END;
    
          BullZipPDF.Init;
          BullZipPDF.LoadSettings;
          RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
          BullZipPDF.SetValue('Output',Filename1);
          BullZipPDF.SetValue('OwnerPassword','abc');
          BullZipPDF.SetValue('UserPassword', CustNo);
          BullZipPDF.SetValue('EncryptionType', 'Standard128bit');
          BullZipPDF.SetValue('ShowSaveAs', 'never');
          BullZipPDF.SetValue('Showsettings', 'never');
          BullZipPDF.SetValue('ShowPDF', 'no');
          BullZipPDF.SetValue('ShowProgress', 'no');
          BullZipPDF.SetValue('ShowProgressFinished', 'no');
          BullZipPDF.SetValue('SuppressErrors', 'yes');
          BullZipPDF.SetValue('ConfirmOverwrite', 'no');
    
          BullZipPDF.SetValue('Mergefile', Filename1 + '|.|' + mergeAfterFileName);
          BullZipPDF.SetValue('MergePosition', 'below');
          
          BullZipPDF.WriteSettings(TRUE);
    
          SalesInv.SETTABLEVIEW(SalesInvoice);
          SalesInv.USEREQUESTFORM(FALSE);
          SalesInv.RUNMODAL;
    
          TimeOut := 0;
          WHILE (TimeOut < 20) DO BEGIN
            SLEEP(3000);
            TimeOut += 1;
          END;
    
          CLEAR(File1);
          CLEAR(BullZipPDF);
        END;
      UNTIL CustLedgEntry.NEXT = 0;
    END;
    

    Can anybody let me know where I made mistake?

    Thanks.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-02-13
    The problem is that you call
    SalesInv.RUNMODAL;
    
    once per invoice. This produces one file per invoice.

    You need to build a filtrer for all the invoice Nos you need to be included in one PDF file and call the SalesInv.RUNMODAL only once.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • rishi_rishabh123rishi_rishabh123 Member Posts: 9
    edited 2018-02-13
    I did something similar as a prototype for some other purpose but the code below creates a PDF file on location with password :

    PdfFile.CREATE('D:\Invoice.pdf');

    PDFSecurity := PDFSecurity.PdfSettings;
    PDFSecurity.PrinterName('Bullzip PDF Printer');
    PDFSecurity.SetValue('Output',PdfFile.NAME);
    PDFSecurity.SetValue('ShowSaveAs', 'never');
    PDFSecurity.SetValue('ShowSettings', 'never');
    PDFSecurity.SetValue('ShowPDF', 'no');
    PDFSecurity.SetValue('ShowProgress', 'no');
    PDFSecurity.SetValue('ShowProgressFinished', 'no');
    PDFSecurity.SetValue('ConfirmOverwrite', 'no');
    PDFSecurity.SetValue('UserPassword','1234');
    PDFSecurity.SetValue('OwnerPassword','12345');
    PDFSecurity.WriteSettings(TRUE);

    CLEAR(SalesInvHeader);
    SalesInvoiceHeader.SETRANGE("No.","No.");
    IF SalesInvoiceHeader.FINDSET THEN;
    REPORT.RUNMODAL(REPORT::"Sales - Invoice", FALSE,FALSE,SalesInvHeader);

    PdfFile.CLOSE;

    Looking your code I think on REPORT.RUNMODAL you have to pass System printer as false if you are defining different printer for this report on printer selection else it is going to take default printer of Windows.
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thanks Rishabh for your reply.. Setting of password had been done already. I need to merge open invoices in one single PDF of a customer from Customer Card (from some menuitem).
  • geronimogeronimo Member Posts: 90
    As Slawek_Guzek mentioned it would be best by building a filter to filter all your invoices in your repeat loop.

    you can use a text variable for this and fill it with numbers split by the "|" sign. like invoiceno1|Invoiceno2 and so on.

    After the loop you then set the filter on salesinvoiceheader with a setfilter and run the report once
  • NavSolutionNavSolution Member Posts: 36
Sign In or Register to comment.