Pictures in Style sheets

wwestendorpwwestendorp Member Posts: 178
I testing the Navision Style Sheet tool and it works fine!

Does anyone knows how to export or Link Navision Pictues like Company Picture Item Pictures in the Stylesheet?

:shock:

Comments

  • kinekine Member Posts: 12,562
    I am afraid that it will be not possible... :-/ but this is just my assumption...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Daniel86Daniel86 Member Posts: 13
    Hi

    I almost have a solution for the problem. Maybe if i post what i have done, someone else can tell me the last peace thats missing to get this to work.


    So here we go... \:D/

    I have build a Report, which exports the Item Pictures to the Hard Drive and writes the path of the Files back to the Item Table (27).
    I have choosen Item."No." as the Filename.
    The Path is written back to Navision with two backslashes \\ instead of just one
    So the Path is "C:\\temp\\filename.bmp" instead of "C:\temp\filename.bmp". Word needs this weid format.

    Then in the Style Sheet tool I select the Item List (Form 30) and Item Table (27). Then the fields "No.", "Description", "Unit Price" and my new Field "Picture Path".

    In Word you have to build a table and insert the Fields. Just like it is descriped in the User Guide for the Style Sheet tool.

    To make Word use your "Picture Path" as the Path to the Picture.
    You have to use "Field Functions" in the Tablefield where the Pictures should be.


    ###I Translated the Word Funktions and Buttons myself from german
    They probably are not correct###

    In Word 2003 Click "Insert" - "Field" a Windows should now popup
    Select the last "Categorie" that should be something like "Links and ..."
    Then select "IncludePicture" and press OK.

    You should now see something like
    "Error! No Filepath was given."
    Now press ALT+F9 and you will see the "Code" behing this funktion.
    It should be something like "{ INCLUDEPICTURE \* MERGEFORMAT }"
    Now where the \* is, put your Field "Item_Picture_Path" from Navision.
    So it should look something like this "{ INCLUDEPICTURE { MERGEFIELD "Item_Picture_Path" } MERGEFORMAT }"


    This way, Word should read whats in the Field Picture Path from your Item Table of Navision. And use that as the Filepath for the image.

    This does not work ;(
    Word then shows the "Error! No Filepath was given." in ever Item even when the Item has a Picture.

    When I put the Filepath fixed in the Field Code ( something like { INCLUDEPICTURE C:\\temp\\filename.bmp MERGEFORMAT }")
    Word shows the picture. BUT it shows the same picture in evey Item that I Export from Navision.

    Well I hope you can understand what I have done and maybe someone can tell me how to make this work correctly.
  • Johnny_ReggaeJohnny_Reggae Member Posts: 63
    Daniel,

    did you find a solution to this problem ?
    I'm trying to do the same thing :-k
  • Steini1980Steini1980 Member Posts: 4
    Hi Daniel,

    did you have meanwhile a solution for this problem?
  • rkvirurkviru Member Posts: 1
    Hi All,
    I have the same problem that I must use dynamic picture in word in mail merge functionality.
    I try everything ( i think :D ) , but in end I always stack in point as rest of us.

    But somedays i catch a idea , and i do this :).

    So my idea is easy. What if we declare as mail merge field source normal field with name for example "Signature", and then when we fill word document with data we catch that field ( of course if it is use in template) and replace them by image .

    So i try this and its works :mrgreen: .

    Only what we need is declared additional field as mail merge source with name which we use after, and when we fill data in WordManagement codeunit we should put empty text to this field .

    The most interesting do is add additional code after filling word.
    In WordManagement Cu in function ShowMergeDocument after that code line
    wrdDoc.MailMerge.ViewMailMergeFieldCodes(ParamInt);
    

    we should add this code:
        wrdMailMerge := wrdApp.ActiveDocument.MailMerge;
        FOR AciveFields := 1 TO wrdDoc.Fields.Count() DO BEGIN
    
          FieldName := wrdMailMerge.Fields.Item(AciveFields).Code.Text;
          
          // Sign
          IF STRPOS(FieldName,'Signature') > 0 THEN BEGIN
            
            wrdRange := wrdApp.ActiveDocument.Fields.Item(AciveFields).Result;
            LinkToFile := TRUE;
            SaveWithDocuments := TRUE;
            //now below patch to picture we can make dynamicly             
            wrdApp.Selection.InlineShapes.AddPicture(PatchToPicture,
                                                     LinkToFile, SaveWithDocuments,wrdRange);  
          END;
        END;
    

    where :
    wrdMailMerge - 'Microsoft Word 12.0 Object Library'.MailMerge
    wrdApp - 'Microsoft Word 12.0 Object Library'.Application
    wrdRange - 'Microsoft Word 12.0 Object Library'.Range


    And that's all.

    Only one problem which I have now is set correct image size.
    I try everything but nothing works, maybe someone of us find solution for redefine size of image in that solution.

    At this moment if we have prepared image for example signature in the same correct size this solution could be helpful.

    Now I waiting for idea how define size of image :D
  • Steini1980Steini1980 Member Posts: 4
    Hi,

    I have another solution:

    - Save the Path to the physical Imagefile in NAV

    - Add this Code to Codeunti StyleSheetManagement.CreateOutputSectionProperties()
          // Replace Mail Merge Text strings with XML Path
          ChildNodeList := XMLDoc.getElementsByTagName('w:t');
          FOR NodeCount := 1 TO ChildNodeList.length DO BEGIN
            ChildNode := ChildNodeList.item(NodeCount - 1);
            ReplaceMailMergePlaceHolder(ChildNode);
          END;
    
          {->IMG 11-10-2011}
          // Replace Mail Merge Images with XML Path
          ChildNodeList := XMLDoc.getElementsByTagName('v:shape');
          FOR NodeCount := 1 TO ChildNodeList.length DO BEGIN
            ChildNode := ChildNodeList.item(NodeCount - 1);
            ReplaceMailMergeImages(ChildNode);
          END;
          {<-IMG 11-10-2011}
    
    
          // Manage MultiLine Changes
          IF IOParentNode.hasChildNodes THEN BEGIN
    

    - Add new Function ReplaceMailMergeImages() similar like ReplaceMailMergePlaceHolder()
        PROCEDURE ReplaceMailMergeImages@119451001(VAR IOChildNode@1002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode");
        VAR
          StyleSheetFields@1000 : Record 682;
          StyleSheetHeader@1004 : Record 680;
          StyleSheetTables@1005 : Record 681;
          NodeTextValue@1001 : Text[100];
          Pos1@1003 : Integer;
          CaptionFound@1008 : Boolean;
          TempXMLText@1009 : Text[30];
          TempXMLAttribute@1010 : Text[30];
          RelationFound@1011 : Boolean;
        BEGIN
          {->IMG 12.10.2011}
          StyleSheetHeader.GET(StyleSheetTemplateCode);
    
          NodeTextValue := COPYSTR(IOChildNode.attributes.getNamedItem('alt').text,
            1,MAXSTRLEN(NodeTextValue) - 1);
    
          // Handle Relationships
          RelationFound := (COPYSTR(NodeTextValue,1,8) = 'RELATION');
          IF RelationFound THEN
            NodeTextValue := COPYSTR(NodeTextValue,STRLEN(Text023) + 2);
    
          // Handle Mail Merge Fields
          StyleSheetFields.SETCURRENTKEY("Merge Field");
          StyleSheetFields.SETRANGE("Merge Field",NodeTextValue);
          StyleSheetFields.SETRANGE("Style Sheet Code",StyleSheetTemplateCode);
    
          IF StyleSheetFields.ISEMPTY THEN
            StyleSheetFields.SETRANGE("Merge Field");
    
          IF StyleSheetFields.FINDFIRST THEN
            REPEAT
              IF STRPOS(StyleSheetFields."Merge Field",NodeTextValue) <> 0 THEN BEGIN
                StyleSheetTables.GET(StyleSheetFields."Style Sheet Code",StyleSheetFields."Table No.");
                Pos1 := STRLEN(StyleSheetFields."XML Path");
                WHILE StyleSheetFields."XML Path"[Pos1] <> '/' DO
                  Pos1 -= 1;
    
                TempXMLText := '/Data/';
                IF StyleSheetTables."Multiple Lines" THEN
                  TempXMLText += 'Row/';
                TempXMLAttribute := '';
    
                InMultiLineSection := CONFIRM('Befindet sich das Bild "%1" in einer Multiline-Section?',TRUE,NodeTextValue);
    
                IF InMultiLineSection THEN  // used with xsl:for-each select
                  IF RelationFound THEN
                    IOChildNode.firstChild.attributes.getNamedItem('src').text :=
                      '{'+'Relations/' + COPYSTR(StyleSheetFields."XML Path",Pos1 + 1) +'}'
                  ELSE
                    IOChildNode.firstChild.attributes.getNamedItem('src').text :=
                      '{'+COPYSTR(StyleSheetFields."XML Path",Pos1 + 1) +'}'
                ELSE
                  IOChildNode.firstChild.attributes.getNamedItem('src').text :=
                    '{'+COPYSTR(StyleSheetFields."XML Path",1,Pos1 - 1) +
                    TempXMLText +
                    COPYSTR(StyleSheetFields."XML Path",Pos1 + 1) +
                    TempXMLAttribute +'}';
                EXIT;
              END;
            UNTIL (StyleSheetFields.NEXT = 0);
          {<-IMG 12.10.2011}
        END;
    

    - Add Dummyimage in Word MailMerge Document (Insert Image as Link), now you can change Properties and Size for the ImagePlaceholder.

    - Open Image Properties in Word and type the Mailmergefieldname into the "alternative text"

    Now it should be work, but the Images will only be linked in the Document.
    You should create a PDF Document before relaying the created Document.
  • Steini1980Steini1980 Member Posts: 4
    Has anyone a Solution to convert the linked Images to embedded Images after processing in Word?!
Sign In or Register to comment.