Print BLOB file to Printer

AngeloAngelo Posts: 174Member
Hi All,

1. Is blob field only for 1 file?
2. Is it possible to get blob data (pdf file, image file, text file, etc) and print it to default printer without open the file ?

If No 2 = Yes then please let me know the pseudocode.

Comments

  • rocatisrocatis Posts: 156Member
    You can store anything in a BLOB field, including multiple files - it's basically a bucket full of bits.

    You will however need to create logarithms to store and retrieve your data from the BLOB field. To NAV, it's just a series of bits and bytes.

    It's basically the same answer to your second question: you cannot just send a random quantity of bits and bytes to your printer and expect it to make sense of it. That leaves you with two options: opening the file using a dedicated program (e.g. Word) or building your own Word-decoder...

    I would strongly advise against the latter :wink:
    Brian Rocatis
    Senior NAV Developer
    Elbek & Vejrup
  • AngeloAngelo Posts: 174Member
    Hi Rocatis,

    Based on your recommendation, it's very complicated if we put many files in one blob field.
    In Navision standard, I can see that one field is only for 1 file otherwise system will prompt confirmation to ask user to replace existing file in blob field in case user want to import file again.

    and also Navision standard will show the file and never find function to print the file directly to printer (like post + print function)
    for example, if blob file is word doc, there is function to open blob file and Microsoft word will open to show blob file.

    for many files, I will follow navision standard (1 blob = 1 field). it's easier to manage.
    but for printing, Is there anybody has done customization sending blob file (eg. pdf, word, txt, etc) to printer for printing without opening the file?
  • rocatisrocatis Posts: 156Member
    Angelo wrote:
    Is there anybody has done customization sending blob file (eg. pdf, word, txt, etc) to printer for printing without opening the file?
    Yes. Search (the forum) and you will find. Here's an example: http://mibuso.com/forum/viewtopic.php?f=23&t=37362&hilit=word+automation+print
    Brian Rocatis
    Senior NAV Developer
    Elbek & Vejrup
  • AngeloAngelo Posts: 174Member
    Thanks Rocatis

    I will try to use the third party program (classexec)

    Regards,
    Angelo
  • sarphervizsarpherviz Posts: 5Member
    I put an image to the blob field.

    When i want to print this image on report ;

    1. Call CALCFIELDS(Rec."Blob Field Name"); OnPreReport

    2. Put a picture box to report and set Source property Rec."Blob Field Name"

    You can see the image on report
  • AngeloAngelo Posts: 174Member
    Hi sarpherviz,

    my blob field is PDF file. I dont think can use your method.
  • AitorEGAitorEG Posts: 240Member
    Angelo wrote: »
    Hi sarpherviz,

    my blob field is PDF file. I dont think can use your method.

    I have the same problem. How did you solve this issue?
    pd: sorry for writing in an old post
  • lubostlubost Posts: 482Member
    Export BLOB to temporary file and call predefined application to print it.
  • AitorEGAitorEG Posts: 240Member
    lubost wrote: »
    Export BLOB to temporary file and call predefined application to print it.

    Thanks, but how can I know the path of that temporary file? Something like
    C:\Users\Administrador\AppData\Local\Temp\2\Microsoft Dynamics NAV\2492
    
    Where the 2492 changes everytime I restart NAV.
  • Slawek_GuzekSlawek_Guzek Posts: 1,516Member
    YourRecord.CALCFIELDS(YourBLOB);
    TempBLOB.BLOB := YourRecord.YourBLOB;
    TempServerFileName := C419.ServerTempFileName('.pdf');
    C419.BLOBExportToServerFile(TempBLOB, TempServerFileName);
    //if you need it on client PC
    TempClientFileName := C419.DownloadTempFile(TempServerFileName);
    
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Posts: 240Member
    YourRecord.CALCFIELDS(YourBLOB);
    TempBLOB.BLOB := YourRecord.YourBLOB;
    TempServerFileName := C419.ServerTempFileName('.pdf');
    C419.BLOBExportToServerFile(TempBLOB, TempServerFileName);
    //if you need it on client PC
    TempClientFileName := C419.DownloadTempFile(TempServerFileName);
    

    THank you @Slawek_Guzek . I'm doing this:
    lShipment.CALCFIELDS(Sticker);
       lTmpBLob.Blob := lShipment.Sticker;
       lTempServerFileName := lFileManagement.ServerTempFileName('C:\XML\sticker.pdf');
       lFileManagement.BLOBExportToServerFile(lTmpBLob,lTempServerFileName);
       lTempClientFileName := lFileManagement.DownloadTempFile(lTempServerFileName);
    

    BUt I get the "invalid path" error. What am I doing wrong?
  • ftorneroftornero Posts: 127Member
    Change this line:
    lTempServerFileName := lFileManagement.ServerTempFileName('C:\XML\sticker.pdf');
    

    to that:
    lTempServerFileName := lFileManagement.ServerTempFileName('pdf');
    
  • Slawek_GuzekSlawek_Guzek Posts: 1,516Member
    The line:
    lTempServerFileName := lFileManagement.ServerTempFileName('C:\XML\sticker.pdf');
    
    has to be:
    lTempServerFileName := lFileManagement.ServerTempFileName('.pdf')
    
    as in posted example
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Posts: 240Member
    edited 2018-09-17
    THnak you both, but..Where does this save my PDF file?
    lShipment.CALCFIELDS(Sticker);
       lTmpBLob.Blob := lShipment.Sticker;
       lTempServerFileName := lFileManagement.ServerTempFileName('.pdf');
       lFileManagement.BLOBExportToServerFile(lTmpBLob,lTempServerFileName);
       lTempClientFileName := lFileManagement.DownloadTempFile(lTempServerFileName);
    

    edit:
    I've seen that it saves in the temporaru folder again, and with a name like "__TEMP__05b8e5886d1f4332b3c150d892dbd699.tmp.pdf". My idea is to save it in a known folder to get it later for printing
  • ftorneroftornero Posts: 127Member
    In this case change this line:
     lTempClientFileName := lFileManagement.DownloadTempFile(lTempServerFileName);
    

    to that;
    lFileManagement.DownloadToFile(lTempServerFileName,  ClientFileName);
    

    To a ClientFileName you choose.
  • AitorEGAitorEG Posts: 240Member
    Thank you very much, it worked like this:
       lShipment.CALCFIELDS(Sticker);
       lTmpBLob.Blob := lShipment.Sticker;
       lTempServerFileName := lFileManagement.ServerTempFileName('.pdf');
       lFileManagement.BLOBExportToServerFile(lTmpBLob,lTempServerFileName);
       lFileManagement.DownloadToFile(lTempServerFileName,  'c:\XML\pegatina.pdf');
    

    Thank you all for your tips!
Sign In or Register to comment.