Book a Demo

Author Topic: Resizing of diagram images in document generation.  (Read 5825 times)

Kaidou_91

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Resizing of diagram images in document generation.
« on: January 07, 2019, 10:37:28 pm »
Hi all,

I'm struggling with the resizing of diagrams in document generation. Some diagrams are too big and go over to a new page of the generated document leaving the name of the diagram and other information in the previous page. Is it possible to automatically resize them to fit in the same page as the diagrams' name?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Resizing of diagram images in document generation.
« Reply #1 on: January 07, 2019, 11:43:50 pm »
No, there's nothing you can do from the EA end.

What we do is run a little Word macro that resizes all images to a standard maximum size making the title and caption appear on the same page.

Geert

Kaidou_91

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Resizing of diagram images in document generation.
« Reply #2 on: January 08, 2019, 12:19:52 am »
Thanks for the answer.

I asked this because I noticed that the diagrams (that are larger than A4 page format) are automatically horizontally resized but not vertically.
I figured that there would be an option to do the same for vertical resizing. I even tried to put the diagram image in the template inside a table with fixed height but that did not work either.
It would be really helpful to fix/add this feature.

Thanks anyway.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Resizing of diagram images in document generation.
« Reply #3 on: January 08, 2019, 12:28:13 am »
I'm not sure what settings you are using, but when I generate a document with diagrams, all diagrams are resized to fit exactly on one page.

Geert

Kaidou_91

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Resizing of diagram images in document generation.
« Reply #4 on: January 08, 2019, 12:34:24 am »


This is what I'm trying to generate. The title and other information are in one page and the diagram in another one.
I set the "Scale to 1 page" option but it does not work.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Resizing of diagram images in document generation.
« Reply #5 on: January 08, 2019, 02:46:54 am »


This is what I'm trying to generate. The title and other information are in one page and the diagram in another one.
I set the "Scale to 1 page" option but it does not work.
Looks the same like I do it, but I never got any diagram spanning multiple pages.
Have you looked at the template and doc generation options? Maybe there is something there that controls this behavior.

Geert

Kaidou_91

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Resizing of diagram images in document generation.
« Reply #6 on: January 10, 2019, 08:23:41 pm »
Solved using MS Word macro.

Thanks

hnmdijkema

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Resizing of diagram images in document generation.
« Reply #7 on: June 26, 2020, 06:24:34 pm »
I've found a way to influence the image size. It needs some scripting though, so you'll need a custom template fragment with a call to a script to create the diagram image.

Here's what I've done:

1. Create a User Template Fragment for a diagram with a call to a script: documentDiagram(#DIAGRAMID#, "DiagramTemplate")

2. Create the documentDiagram() function...

function documentUPPDiagram(diagramId, diagramTemplate)
    (...)
       set docG = Repository.CreateDocumentGenerator
   if (docG.NewDocument("")) then
      docG.DocumentDiagram diagramId, 1, diagramTemplate
   DIM rtf
   rtf = docG.GetDocumentAsRTF()
   rtf = maximizeDiagramImageHeightInCm(rtf, 14.6)
   
   documentDiagram = rtf
end function


And, I used these functions to influence the RTF.

function getRtfValue(rtf, entry)
   DIM i1, i2, l
   DIM e
   i1 = InStr(rtf, entry)
   if (i1 > 0) then
      i2 = InStr(i1 + 1, rtf, "\")
      if (i2 > 0) then
         l = i2 - i1 - Len(entry)
         e = Mid(rtf, i1 + Len(entry), l)
         getRtfValue = e
      end if
   end if
end function

function rtfReplace(rtf, entry, new_value)
   DIM i1, i2
   i1 = InStr(rtf, entry)
   if (i1 > 0) then
      i2 = InStr(i1 + 1, rtf, "\")
      if (i2 > 0) then
         rtfReplace = Left(rtf, i1 - 1) & entry & new_value & Mid(rtf, i2)
      end if
   end if
end function

function maximizeDiagramImageHeightInCm(rtf, max_height_in_cm)
   DIM w_goal, h_goal
   DIM scale_w, scale_h
   DIM factor
   DIM max_height_in_twips
   
   max_height_in_twips = Round((max_height_in_cm / 2.54) * 1440)
   scale_h = CInt(getRtfValue(rtf, "\picscaley"))
   max_height_in_twips = Round((1.0 / (scale_h / 100.0)) * max_height_in_twips)
   
   w_goal = getRtfValue(rtf, "\picwgoal")
   h_goal = getRtfValue(rtf, "\pichgoal")
   LOGDebug("\picwgoal = " & w_goal & ", \pichgoal = " & h_goal)
   h_goal = CInt(h_goal)
   
   if (h_goal > max_height_in_twips) then
      factor = max_height_in_twips / h_goal
      h_goal = Round(h_goal * factor)
      w_goal = CInt(w_goal)
      w_goal = Round(w_goal * factor)
      
      LOGDebug("Scaled to: \picwgoal = " & w_goal & ", \pichgoal = " & h_goal)
      
      rtf = rtfReplace(rtf, "\picwgoal", w_goal)
      rtf = rtfReplace(rtf, "\pichgoal", h_goal)
   end if
   
   maximizeDiagramImageHeightInCm = rtf
end function


Oke, it's a dirty hack, but it works.