Paint a border around every image in a Word document - image

Is there a way to add a border around every image in Word? I know that I can create a custom paragraph style with a border and put the image in there, but maybe I can just specify a global image style, like in CSS:
img { border: 1px solid #000 }

Unfortunately, there is no picture style concept available in Word. Therefore, something like specifying a global style for images similar to CSS is not possible.
What you can do is write a VBA macro that adds the border to all images. The code is a little different depending on whether your image is formatted to be inline with text (InlineShape) or floating (Shape):
Sub AddBorderToPictures()
' Add border to pictures that are "inline with text"
Dim oInlineShape As inlineShape
For Each oInlineShape In ActiveDocument.InlineShapes
oInlineShape.Borders.Enable = True
oInlineShape.Borders.OutsideColor = wdColorBlack
oInlineShape.Borders.OutsideLineWidth = wdLineWidth100pt
oInlineShape.Borders.OutsideLineStyle = wdLineStyleSingle
Next
' Add border to pictures that are floating
Dim oShape As shape
For Each oShape In ActiveDocument.Shapes
oShape.Line.ForeColor.RGB = RGB(0, 0, 0)
oShape.Line.Weight = 1
oShape.Line.DashStyle = msoLineSolid
Next
End Sub
If apparently setting the line width to wdLineWidth100pt is an issue, you can try using the actual underlying integer value instead, e.g.:
oInlineShape.Borders.OutsideLineWidth = 8
This is how the constant is defined:
public enum WdLineWidth
{
wdLineWidth025pt = 2,
wdLineWidth050pt = 4,
wdLineWidth075pt = 6,
wdLineWidth100pt = 8,
wdLineWidth150pt = 12,
wdLineWidth225pt = 18,
wdLineWidth300pt = 24,
wdLineWidth450pt = 36,
wdLineWidth600pt = 48,
}

Related

Moviepy - Place textclips at relative position

How do I place a textclip, right below the other? I require to place an image at the left of the video and two lines of text to the right of image, that are placed one below the other.
Something like this:
I tried to use set_position, but doesn't scale well for different videos (of different resolutions). By adjusting the arguments of set_position, I am able to place the textclips one below the other without gap in one resolution, but when I go to a higher resolution video, it shows a gap (I understand why the gap comes, but not sure how to prevent it)
txt_clip1 = TextClip("This is line 1 of text", fontsize = 12, color = 'white', bg_color='black')
txt_clip1 = txt_clip1.set_duration(7).set_start(0).set_end(7)
txt_clip1 = txt_clip1.set_position((0.1,0.90), relative=True).set_opacity(0.6)
txt_clip2 = TextClip("This is line 2 of the text, smaller font", fontsize = 8, color = 'white', bg_color='black')
txt_clip2 = txt_clip2.set_duration(7).set_start(0).set_end(7)
txt_clip2 = txt_clip2.set_position((0.1,0.93), relative=True).set_opacity(0.6)
I tried to insert a new line character in the text, but that doesn't suit me because the second line of text has different font properties.
Hopefully this will help you
txt_clip1 = TextClip(
"Cool effect 2nd line", color="black", bg_color="red", font="Amiri-Bold", kerning=5, fontsize=20
)
cvc = CompositeVideoClip([txt_clip1.set_position("East")], size=screensize)
txt_clip1 = txt_clip1.set_position((5,35))
.set_position mother take to arguments 1st is the position from the left screen and second is the position from the top
so your code is like something
txt_clip1 = txt_clip1.set_position((5,500))
txt_clip2 = txt_clip2.set_position((5,535))
It will place the text in the position you want.
Hopefully, this will help.
Happy coding

Amcharts custom variable color

I want a dynamic color on my chart. I use a imported css file with some identity colors.
Like this:
:root
{
--brand-color: {{$color}};
}
I am using the AmChart World chart as visualisation but the a4mchart.color() does not like variables. How do I make sure that it does take in variables? here my code:
let style = getComputedStyle(document.body);
let brandColor = style.getPropertyValue('--brand-color');
const chartWorld = am4core.create(this.$refs.chartdiv, am4maps.MapChart);
polygonSeries.fill = am4core.color(brandColor);
And this is what it returns:
Color {_value: {
alpha: 1
alternative: Color
darkColor: Color
hex: "#000000"
lightColor: Color
rgb: Object
rgba: "rgb(0,0,0)"
_value: {r: 0, g: 0, b: 0, a: 1}
__proto__: Object…}}
It didn't change anything but the BrandColor does return the right string when I log it: "#A4A2A3"
Please help
From my testing, getPropertyValue returns everything after the property name, including any whitespace, which causes the color to not get parsed correctly by AmCharts; your log is likely returning " #A4A2A3". You'll want to call trim on the string beforehand:
polygonSeries.mapPolygons.template.fill = am4core.color(brandColor.trim());
Note that you need to set the fill on the series' mapPolygon template for it to apply to your map regions.

iText 7 - How to fill a canvas rectangle with a transparent color

In iText 7.1.9 I am taking a pdf created programmatically (not via iText) and need to apply a transparent rectangle along the left side and bottom to ensure the no content exists within a predefined clear zone (for print).
The below code places the yellow rectangles correctly but the desired result is the for the yellow fill to be semi-transparent or not 100% opaque so that visual inspection will show the content that that intersects with the rectangle instead of the rectangle clipping the content.
var page = pdf.GetPage(1);
PdfCanvas canvas = new PdfCanvas(page);
canvas.SaveState();
canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.YELLOW);
var pageHeight = page.GetPageSize().GetHeight();
var pageWidth = page.GetPageSize().GetWidth();
// left side
canvas.Rectangle(0, 0, 15, pageHeight);
// bottom
canvas.Rectangle(0, 0, pageWidth, 15);
canvas.Fill();
canvas.RestoreState();
I attempted to use a TransparentColor but canvas.SetFillColor won't accept a TransparentColor, are there any other options?
When we speak about low-level content stream instructions, color itself and transparency levels are specified separately in PDF syntax. The TransparentColor class that you speak about was designed to simplify lives of users who are less familiar with nuances of PDF syntax, but it it a higher-level class that you can use e.g. in layout module, and in your case you operate with the document on quite low level.
Long story short, to set color transparency you only need one additional line next to setting the color itself:
canvas.SetExtGState(new PdfExtGState().SetFillOpacity(0.5f));
So the code becomes:
var page = pdf.GetPage(1);
PdfCanvas canvas = new PdfCanvas(page);
canvas.SaveState();
canvas.SetFillColor(iText.Kernel.Colors.ColorConstants.YELLOW);
canvas.SetExtGState(new PdfExtGState().SetFillOpacity(0.5f));
var pageHeight = page.GetPageSize().GetHeight();
var pageWidth = page.GetPageSize().GetWidth();
// left side
canvas.Rectangle(0, 0, 15, pageHeight);
// bottom
canvas.Rectangle(0, 0, pageWidth, 15);
canvas.Fill();
canvas.RestoreState();

CATScript - Text, Lines and Frames in Black

The code is as below (CATScript):
Sub CATMain()
' enter sheet background
Set oView = oDrawingDocument.DrawingRoot.ActiveSheet.Views.Item("Background View")
oView.Activate
' select all views in current screen
Set oSelection = oDrawingDocument.Selection
oSelection.Search "Type=*,scr"
' set visual to black
oSelection.VisProperties.SetRealColor 0, 0, 0, 0
' exit sheet background
Set oView = oDrawingDocument.DrawingRoot.ActiveSheet.Views.Item("Main View")
oView.Activate
End Sub
The code works seamlessly except that oSelection.VisProperties.SetRealColor 255, 255, 255, 0 does not change any of the selected lines and frames to black in my 2D drawing. Manually I can do this so pretty sure I'm just using the wrong syntax. SetVisibleColor neither works, but then also I can only find that these syntaxes are used for changing color in 3D and I am using it for a 2D drawing. Anyone here knows the syntax to manipulate the color icon in the 'Graphic Properties' workspace for a 2D drawing?
This is the solution I found after some research and trial&error:
'CHANGE LINE COLOR
Set oSelectionGI = oDrawingDocument.Selection
oSelectionGI.Search("CATDrwSearch.CATEarlyGenItem,all")
oSelectionGI.VisProperties.SetRealColor 0,0,0,0
'CHANGE TEXT COLOR
Set oSelectionDC = oDrawingDocument.Selection
oSelectionDC.Search("CATDrwSearch.DrwText,all")
oSelectionDC.VisProperties.SetRealColor 0,0,0,0
'CHANGE TABLE COLOR
Set oSelectionDT = oDrawingDocument.Selection
oSelectionDT.Search("CATDrwSearch.DrwTable,all")
oSelectionDT.VisProperties.SetRealColor 0,0,0,0

Sub 10 height request layouts/views not allowed

I'm trying to add line dividers between views. However, there is a forced margin on every element I try (Image, BoxView, Frame, Label). I set the margin to be 0, the HeightRequest is always 3, but as you can see the view bounds expand past the actual view. Is there a specific view I'm supposed to be using? I just want the gray line and nothing more.
var line2 = new Frame
{
WidthRequest = (App.ScreenDpWidth / 2),
MinimumHeightRequest = 3,
HeightRequest = 3,
BackgroundColor = Color.FromHex("#229EBB"),
Margin = new Thickness(0, 0)
};
I assume you are layouting your elements either in a Grid or a StackLayout.
By default, the StackLayout.Spacing, Grid.RowSpacing and Grid.ColumnSpacing properties are set to 6d.
Without more information, I think that's what you're seeing in your code. Change those values to 0d.
Also, if you only want a gray line, you can use a BoxView which will draw a gray box, and set it's Height to 1d.

Resources