[Solved] Deleting page without leaving page-anchored images

Discuss the word processor
Post Reply
Kazerad
Posts: 3
Joined: Tue Mar 01, 2016 10:47 am

[Solved] Deleting page without leaving page-anchored images

Post by Kazerad »

I have a relatively complex document with a lot of images, most of them with their Anchor set at "To page". At the time, I assumed this was the only way to freely position them.

However, now I need to delete several pages earlier in the document! When I do this by simply backspacing through everything on the page, all the page-anchored images remain on the same page number.

Is there a way to delete entire pages that will update the image anchoring on future pages (e.g. an image anchored to Page 43 will now be anchored to Page 42)? Or will I just have to manually re-anchor nearly a hundred images to paragraphs, and re-position them appropriately?
Last edited by Kazerad on Wed Mar 02, 2016 12:29 am, edited 1 time in total.
OpenOffice 4.1.2 on Windows 10
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Deleting a page without leaving behind page-anchored ima

Post by musikai »

Welcome to the wondrous world of page anchors :-)

I really think it would be best to change all anchors to paragraph as the page anchor really isn't of much use.
So I was about to recommend the extension "PicTool" for changing all images's anchors, but OpenOffice then repositions all images. (when you use PicTool on a single selected image and change the anchor to paragraph it restores the position at least.)
Before I manage to rewrite the extension you can try this macro that changes all images that have a page anchor to a paragraph anchor and restores the position:

Code: Select all

sub PageAnchorToParagraphAnchor
go = ThisComponent.getGraphicObjects
counter = 0
     For i = 0 to go.Count-1
       g = go.getByIndex(i)

		if g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE then		
		oldposx = g.HoriOrientPosition
		oldposy = g.VertOrientPosition

		g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
		
		g.HoriOrientPosition = oldposx
		g.VertOrientPosition = oldposy
		counter = counter + 1
		end if

     next i
     msgbox "Ready. Changed " & counter & " image(s)."
end sub
edit: Or install the attached extension. (Unzip before installation)
Hope it works for you and preserves your layout.
Attachments
PageAnchorsToParagraph-1.0.0-OpenOffice.oxt.zip
(4.9 KiB) Downloaded 202 times
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Kazerad
Posts: 3
Joined: Tue Mar 01, 2016 10:47 am

Re: Deleting a page without leaving behind page-anchored ima

Post by Kazerad »

Oh wow! I appreciate the fast response (and even with a custom extension to solve the problem!)

I tried it out, and the extension sort of works. The Page-anchored images are successfully converted to Paragraph-anchored and retain their proper positions on the page, except every Page-anchored image in the document seems to appear on every page. At the same time, though, moving an image on one page seems to move all of its copies on the other pages?
OpenOffice 4.1.2 on Windows 10
User avatar
RoryOF
Moderator
Posts: 35064
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Deleting a page without leaving behind page-anchored ima

Post by RoryOF »

Then your anchors are in the Header or Footer of the page.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Deleting a page without leaving behind page-anchored ima

Post by musikai »

That's true. I now tried it on a document with header, and some pictures get anchored to it. This is the behaviour of OpenOffice. To solve this by macro is difficult I believe.
Only idea is if the header isn't complicated you could delete it, run the macro and rebuild the header.
Or if you only use 1 or 2 pagestyles then build new ones based on these, remove header on them and replace the existing pagestyles, run the macro and reapply the original pagestyles.

Another possibility:
If you only delete pages from the start of your document then this macro shifts the pageanchors towards the start.
You can edit the number "shiftimagestowardsbeginby"

Code: Select all

sub PageAnchorsToNewPage

shiftimagestowardsbeginby = 1 'page(s)   negative = towards end

go = ThisComponent.getGraphicObjects
     For i = 0 to go.Count-1
       g = go.getByIndex(i)
		if g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE then		
		oldpageno = g.AnchorPageNo
		newpageno = oldpageno-shiftimagestowardsbeginby
			if newpageno>=1 then g.AnchorPageNo = newpageno
		end if
     next i
     msgbox "Ready!"
end sub
Last edited by musikai on Wed Mar 02, 2016 12:58 am, edited 1 time in total.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Kazerad
Posts: 3
Joined: Tue Mar 01, 2016 10:47 am

Re: Deleting a page without leaving behind page-anchored ima

Post by Kazerad »

Ah! Amazing catch, that seems to have been the problem.

I went ahead and disabled Headers (this seemed to anchor the images to the pages proper instead), ran Musikai's plugin, then enabled headers again. All the images are properly linked now, and earlier pages can be deleted without issue.

Thanks a bunch, both of you! You saved me hours and hours of work. :D
OpenOffice 4.1.2 on Windows 10
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Deleting a page without leaving behind page-anchored ima

Post by musikai »

Wonderful! Glad it worked.
Meanwhile I edited my post above. There's a macro now that can shift the pageanchors to another page.
But for you I think it is now much better to already have a document with paragraph anchors.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Post Reply