Print BLOB file to Printer

AngeloAngelo Member Posts: 180
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 Member Posts: 163
    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 Member Posts: 180
    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 Member Posts: 163
    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 Member Posts: 180
    Thanks Rocatis

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

    Regards,
    Angelo
  • sarphervizsarpherviz Member Posts: 5
    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 Member Posts: 180
    Hi sarpherviz,

    my blob field is PDF file. I dont think can use your method.
  • AitorEGAitorEG Member Posts: 342
    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 Member Posts: 627
    Export BLOB to temporary file and call predefined application to print it.
  • AitorEGAitorEG Member Posts: 342
    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 Member Posts: 1,690
    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 Member Posts: 342
    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 Member Posts: 524
    Change this line:
    lTempServerFileName := lFileManagement.ServerTempFileName('C:\XML\sticker.pdf');
    

    to that:
    lTempServerFileName := lFileManagement.ServerTempFileName('pdf');
    
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    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 Member Posts: 342
    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 Member Posts: 524
    In this case change this line:
     lTempClientFileName := lFileManagement.DownloadTempFile(lTempServerFileName);
    

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

    To a ClientFileName you choose.
  • AitorEGAitorEG Member Posts: 342
    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.