I’m using linked image in my database, and I need them to be rotated 90° in an report I’m creating (the other reports uses their normal position)
is this even possible?
I’m using linked image in my database, and I need them to be rotated 90° in an report I’m creating (the other reports uses their normal position)
is this even possible?
In 7.1.5 LO
You can click on the “Edit Document” button at the top of the report preview, right-click on the image and select “Rotate or flip” → “90 Left” or “90 Right”.
I don’t know how many times in a report you would need to do this. It seems like it should be possible to concoct a macro to do this. Andrew Pitonyak’s “Useful Macro Information” book has an example for a macro to find all images in a document (a Base report is really a writer document). Then all you would need is what property needs set to “flip” the image 90 degrees.
Just thinking here… You might search for a macro solution that may already out there?
indeed, this is working, now I just need a macro that’s doing this. Thx for the info
I have worked out a crude little macro to rotate linked images in a report preview in Base. In order to run it from the menu bar of the report, I had to put the macro in the “My Macros”, “Standard” library because there was no access to the Base file or report “draft” macro storage. I hope that makes sense. If not, maybe read some of the LO documents on working with macros.
Here is the code:
'Rotate all images in a Base Report document preview
'uses the document drawpage to rotate images in a report
'thanks to Andrew Pitonyak and Xray
'example only
'NOTES: place in "My Macros", "Standard" library to run from Macro Menu in a Base report view.
' simple, no error checks, use at your own risk, etc.
Sub RotateImages()
Dim oDoc As Object
Dim oDP As Object
Dim oGraph As Object
Dim j As Integer
Dim iDeg As Integer
iDeg = InputBox("Rotate images how many degrees left?","Rotate Images",90)
REM Get the document draw page and then enumerate the images.
oDoc = ThisComponent
oDP = oDoc.getDrawPage()
For j=0 To oDP.getCount()-1
oGraph = oDP.getByIndex(j)
'integer degrees * 50, rotates top to left
oGraph.SetPropertyValue("GraphicRotation",(iDeg*50))
Next
End Sub
'
Well, I only want the report to turn them 90° when printing, I can’t rotate all images by hand…
Thx a lot!, I would never have been able to fix it myself.
@echo8hink finally i got the obnoxious report to work… fairly, but your script didn’t work…
any idea what could be wrong?
The Report-Builder hasn’t been changed since the start of LO. Only one function (Auto Grow) has been added. So the images couldn’t be turned like they couldn’t be turned in Writer at the moment the Report Builder has been created.
Could be a command from Imagemagick will work for you:
mogrify -flip -rotate 90 *.jpg
This will rotate all images in the folder 90".
The macro must be executed after the report has been executed. If you start the report from a form, you could start all like this:
oReport = ThisDatabaseDocument.ReportDocuments.getByName("MyReport").open
oDP = oReport.getDrawPage()
…
Have tested the code and it works here.
@RobertG I’m creating the report by DoubleClick on the reports name in the “main” window, I’ve tried both after the report has been created (it shows the report has been created in read-only mode, and shows me an edit button) and I’ve tested after pressing that button, but the same result…
I don’t see an image, which could be rotated. Are there other figures in the report, which can’t be rotated? The macro will try this with all figures it will find …
That was actually an good idea!
there are images, via links, otherwise it’s only rectangles, labels and fields…
The macro I posted doesn’t take any other “Graphics” into account. It assumes the only thing in the DrawPages is a linked image. Remember, I called it “crude.” The error looks to me like there are graphics other than images in the report.
The report writer usually names images in the report: Image0, Image1, Image2, etc.
If this is the case, you could try to avoid things other than linked images with the following modification to the macro:
(I’m having trouble with the editor here today. Hope you can follow…)
'Rotate all images in a Base Report document preview
'uses the document drawpage to rotate images in a report
'thanks to Andrew Pitonyak and Xray
'example only
'NOTES: place in “My Macros & Dialogs”, “Standard” library to run from Macro Menu in a Base report view.
’ simple, no error checks, use at your own risk, etc.
Sub RotateImages()
Dim iDeg As Integer
Dim oDoc As Object
Dim oDP As Object
Dim oGraph As Object
Dim j As Integer
iDeg = InputBox("Rotate images how many degrees left?","Rotate Images",90)
REM Get the document draw page and then enumerate the images.
oDoc = ThisComponent
oDP = oDoc.getDrawPage()
For j=0 To oDP.getCount()-1
oGraph = oDP.getByIndex(j)
'integer degrees * 50, rotates top to left
If left(oGraph.Name,5) = "Image" then '<- do we have an image and not a drawing, etc.
oGraph.SetPropertyValue("GraphicRotation",(iDeg*50))
EndIf
Next
End Sub
Wouldn’t it be better to get the implementation name? Works for all images:
IF oGraph.ImplementationName = “SwXTextGraphicObject” THEN
oGraph.SetPropertyValue(“GraphicRotation”,(iDeg*50))
END IF
I’m all for whatever works. I did very little basic testing on the code. I had used it on a simple report with just text and linked images that I used for a grocery list report. Then, after the error mentioned here, I checked a recipe report that had an graphic behind a text and some other images, the same error occurred to me. I added the “IF” and it worked.
I never checked what all property objects “GraphicRotation” works with. I just knew it worked for Base report linked images. I didn’t think beyond that.
That’s where your knowledge and experience can come in and make the solution even better.
Thanks @RobertG !
@echo8hink Your latest code worked great, yours too @RobertG , once I removed your quotation marks “ ” and used citation " " instead!
Thanks a lot for the help!
I’m glad it worked out for you.
Also, I thought I would pass along that I really couldn’t explain why the multiplier 50 works. I did some checking and it looks like “GraphicRotation” uses a number that is actually in tenths of a degree. In other words, you could use an integer from 0 to 3599 to rotate and be accurate to .1 degree. 900 would be 90.0 degrees. 225 would be 22.5 degrees. I have changed my multiplier to 10 and it seems to work for whole degrees like: 45, 90, etc. I don’t like to think in fractions of degrees, minutes, seconds anyway! Negative numbers appear to rotate to the right. I have noted that in my code and will probably rewrite it at some point. I have not tested any of this. Feel free to experiment with it. Cheers!
Interesting. I think I looked for “RotateAngle” and couldn’t find it in the context of base report/writer table linked image?? “GraphicRotation” was available and worked for me. I think there may be some differences. I took pieces of Andrew Pitonyak’s code and some xray info and pieced it together. I really couldn’t find much on parameters for either in on-line searching. It’s been since ??2018?? when I first worked on this. Anyway, thanks for the additional reference.