Insert a subdoc with anchored images in a writepro doc

Hi,

I have a module dynamically building a report with a series of chart images, also built on-the-fly.
I want to show these images in a grid layout (4 images per page). I’m anchoring the images relative to the paper box, in a blank document, a sub-document of sorts.

Then I load my master/final doc from a template which includes bookmarks. I then insert my sub-doc at the bookmark position, and happily save my final doc… And when opening it, well the graph area is nowhere to be found ( :cry:). And I’ve already tried changing the document view mode to all possible values…

Could you please tell me what’s incorrect with code?

Thanks

Olivier

PS: i tried using a table in the sub-doc, but the 4 images are too small to be readable in that case, hence my try to use anchored images which provides more placement flexibility…

<code 4D>

C_OBJECT($voMasterDoc)
C_PICTURE($viGraph;$viHisto)
C_OBJECT($voPictureRange)
C_TEXT($vtSaveFolder)
C_LONGINT($vlCurrentPage)
C_OBJECT($voGraphSectionDoc;$voGraphSectionRange;$voMasterDoc;$voBookmarkRange)

$vtSaveFolder:=“C:\LocalDocs\svn\scquam_unit_tests\monthlyReport”+Folder separator

$voGraphSectionDoc:=WP new
$vlCurrentPage:=1
// //Test anchor the image
$voPictureRange:=WP Add picture($voGraphSectionDoc;Get 4D folder(Current resources folder)+“graph.svg”)

//image in top left spot
WP SET ATTRIBUTES($voPictureRange;wk anchor origin;wk paper box;
wk anchor horizontal align;wk left;
wk anchor horizontal offset;“2.30cm”;
wk anchor vertical align;wk top;
wk anchor vertical offset;“3.00cm”;
wk anchor page;$vlCurrentPage)

//image in bottom left spot
$voPictureRange:=WP Add picture($voGraphSectionDoc;Get 4D folder(Current resources folder)+“Histo.svg”)
WP SET ATTRIBUTES($voPictureRange;wk anchor origin;wk paper box;
wk anchor horizontal align;wk left;
wk anchor horizontal offset;“2.30cm”;
wk anchor vertical align;wk top;
wk anchor vertical offset;“10.50cm”;
wk anchor page;$vlCurrentPage)

//load the master doc from the template
$voMasterDoc:=WP Import document($vtSaveFolder+“Monthly report template(en).4wp”)

//get the bookmark and insert the sub-doc at the bookmark position
$voBookmarkRange:=WP Get bookmark range($voMasterDoc;“GRAPH”)
assert($voBookmarkRange.end>$voBookmarkRange.start)
$voGraphSectionRange:=WP Create range($voGraphSectionDoc;wk start text;wk end text)

WP INSERT DOCUMENT($voBookmarkRange;$voGraphSectionDoc;wk append)
WP EXPORT DOCUMENT($voMasterDoc;
$vtSaveFolder+Current method name+".4wp";
wk 4wp)

</code 4D>

Hello

the problem is when you use “WP INSERT DOCUMENT”

The documentation says :

The inserted wpDoc document can be any 4D Write Pro document object created using the WP New or WP Import document command. Only the body children elements are inserted (sections and bookmarks in the destination range are preserved). In addition, the elements are copied, so wpDoc can be re-used several times.

In your case, the ‘anchored’ pictures of the inserted document are not in the body !

Just reverse the way you do it and insert your “master document” inside the “graphics document” ?

OR…

Rather than using anchored pictures use inline pictures ?
(maybe use a two rows table with invisible borders ?)

Roland Lannuzel

Hey Roland,

Thanks for passing by!

I previously used inline pictures but the result was not good (in terms of image readability)…

Maybe I could use that bookmark, and expand its range by appending as many pages breaks as required, resulting in several new pages. And then anchor the images to each new pages…

To be continued…

Olivier

So it turns out, creating required pages by appending page breaks to my bookmark, and anchoring the images to the resulting new pages works fine.

But if I manually edit the built document and that results in adding/removing pages, the anchored images will not shift down/up.

Which after all is normal, because if they’d be movin’ they wouldn’t be anchored.

Time to go back to english class I guess.

Olivier