webdriver print with desired pageWidth pageHeight - webdriver

I was searching and trying many things to change page size of generated PDF with webdriver.
I already read and studied those following links
https://w3c.github.io/webdriver/#print-page
https://webdriver.io/docs/api/webdriver/#printpage
https://github.com/jlipps/simple-wd-spec
as so far I was able to succesuflly use {"background": true} but when I try to change page size with using {"pageWidth": 29.70, "pageHeight": 42.00} (desired A3 format) then I have no success, I mean generated PDF is still 8,50x11,00 inches but I wanted A3 format which should be 11,69x16,54 inches.
Size of page in PDF I check using AcrobatReader:
So I wanted to ask if I pass {"pageWidth": 29.70, "pageHeight": 42.00} incorectly or there is another issue which I do not understand.

I just went through the spec and I see that it mentions this regarding page dimensions:
Let pageWidth be the result of getting a property with default named width and with a default of 21.59 from page.
Let pageHeight be the result of getting a property with default named height and with a default of 27.94 from page.
The wording is a bit misleading, but I interpret it as "get page height from a property called height", pageHeight seems to be an internal name used in the spec, the actual name of the property in the options object is simply height. (vice-a-versa for width)
So can you try this?: {"width": 29.70, "height": 42.00}

I finally was able find the proper way
{
"page":{
"width": 29.70
,"height": 42.00
}
,"margin":{
"top": 2
,"bottom": 2
,"left": 2
,"right": 2
}
,"scale": 0.5
,"orientation":"landscape"
,"shrinkToFit": true
,"background": true
,"pageRanges": ["1", "1-1"]
}

Related

AwesomeWM - open/close window callback

I have following idea:
I have a wallpaper in 2 version. One original and second a bit blurry. I want to change the wallpaper from original when first window/program opens on the screen. Once the last window/program is closed change the wallpaper back.
Also when I change between tags I want to check if any window/program is open or not and then adjust the wallpaper.
How can I do that?
P.S.
I use nitrogen to set wallpaper
AwesomeWM client created/removed callback
I found a way to set the wallpaper depending on the visible clients, but I have no idea how your Nitrogen calls look like. Just replace the naughty.notify lines with your Nitrogen invocations.
Somewhere in your rc.lua, you should find something like this:
awful.screen.connect_for_each_screen(function(s)
Add the following to that function
tag.connect_signal("property::selected", function(t)
if #s.clients > 0 then
naughty.notify({text = "set blurry wallpaper", timeout = 1})
else
naughty.notify({text = "set original wallpaper", timeout = 1})
end
end
)
table.getn is deprecated but this is the solution for older lua versions:
tag.connect_signal("property::selected", function(t)
if table.getn(s.clients) > 0 then
naughty.notify({text = "set blurry wallpaper", timeout = 1})
else
naughty.notify({text = "set original wallpaper", timeout = 1})
end
end
)

Django-CMS FilerImageField: Validator function

I'm trying to write a validator for a Django-CMS FilerImageField. The following validator function is used for a default ImageField. When I copy it to the new Model, it will crash with the message 'int' object has no attribute 'file'. Obviously a different type of value is being passed to the validator function. I can't seem to find information on what kind of data is being passed to the validator. How do I correctly reference the file so I can get_image_dimensions()?
def validate(fieldfile_obj):
width, height = get_image_dimensions(fieldfile_obj.file) #crash
if width > 1000:
raise ValidationError("This is wrong!")
Ok I found it. fieldfile_obj in this case contains the primary key of a Image record. The solution was to get an instance of filer.models.Image and pass this instance's file property to the validator function:
from filer.models import Image
# ... code ...
def validate(fieldfile_obj):
image = Image.objects.get(pk=fieldfile_obj)
width, height = get_image_dimensions(image.file)
if width > 1000:
raise ValidationError("This is wrong!")

Height required for UILabel dependent on string length (Swift, iOS 8)

I am struggling to get the height that is required for a UILabel based on variable sized text that it could accept. From hours of research, I have not yet discovered a viable way of achieving this. Currently my code is as follows:
func getHeightForTitle(postTitle: NSString) -> CGFloat {
// Get the height of the font
let constraintSize = CGSizeMake(self.cellTextWidth, CGFloat.max)
let attributes = [NSFontAttributeName: [UIFont.systemFontOfSize(16.0)]]
let labelSize = postTitle.boundingRectWithSize(constraintSize,
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: attributes,
context: nil)
return labelSize.height
}
This however throws the following error:
2014-08-02 12:09:37.370 Testing App[8365:351906] - [_TtCSs23_ContiguousArrayStorage00007FD26C15F708 pointSize]: unrecognized selector sent to instance 0x11e640050
This is always thrown at the let labelSize = postTitle... method and I believe it is down to the attributes variable. I however maybe wrong. Any help is appreciated, and much thanked!
Please note: This is for an iOS 8, Swift development project.
Two observations. First, what's wrong with your code is that this line is not Swift:
let attributes = [NSFontAttributeName: [UIFont.systemFontOfSize(16.0)]]
The stuff after the equals sign is Objective-C, and Swift is having trouble interpreting it. Remove the square brackets from around the UIFont call; you have turned this into an array, which is the source of the error you're seeing.
Second, and more important, there are many much simpler ways to do this, by letting the label tell you its size for the desired text:
Put the text into the label and call sizeToFit() on the label.
Put the text into the label and call sizeThatFits() on the label with the desired width and large height.
Under auto layout, set the label's preferredMaxLayoutWidth to the desired width and put the text into the label; it will size itself.
However, I would urge you not to do this if you don't have to. A label is already self-sizing under auto layout, and in iOS 8 there's a new feature where a table cell will self-adjust its height to its contents, so there is now very rarely a need to pre-measure a label's dimensions.
Put the text into the label and call sizeThatFits() on the label with the desired width and large height.
sub_label=UILabel(frame: CGRectMake(0, 0, self.view.bounds.width, 50))
sub_label.numberOfLines=0;
sub_label.textAlignment=NSTextAlignment.Left
sub_label.lineBreakMode=NSLineBreakMode.ByWordWrapping
let subfont = UIFont(name: "Helvetica", size: 20.0)
sub_label.font=subfont
sub_label.text="his is just a load of texthis is just a load of texthis is just a load of texthis is just a load of texthis is just a load of texthis is just a load of text"
sub_label.backgroundColor=UIColor.clearColor()
var textViewSizesub=sub_label.sizeThatFits(CGSizeMake(self.view.bounds.width, CGFloat.max))
sub_label.frame=CGRectMake(0, textViewSize.height, self.view.bounds.width-5, textViewSizesub.height)

Selectively removing node labels in D3 force directed diagram

Overall context: I have a db of cross-references among pages in a wiki space, and want an incrementally-growing visualization of links.
I have working code that shows clusters of labels as you mouseover. But when you move away, rather than hiding all the labels, I want to keep certain key labels (e.g. the centers of clusters).
I forked an existing example and got it roughly working.
info is at http://webseitz.fluxent.com/wiki/WikiGraphBrowser
near the bottom of that or any other page in that space, in the block that starts with "BackLinks:", at the end you'll find "Click here for WikiGraphBrowser" which will launch a window with the interface
equivalent static subset example visible at http://www.wikigraph.net/static/d3/cgmartin/WikiGraphBrowser/:
code for that example is at https://github.com/BillSeitz/WikiGraphBrowser/blob/master/js/wiki_graph.js
Code that works at removing all labels:
i = j = 0;
if (!bo) { //bo=False - from mouseout
//labels.select('text.label').remove();
labels.filter(function(o) {
return !(o.name in clicked_names);
})
.text(function(o) { return ""; });
j++;
}
Code attempting to leave behind some labels, which does not work:
labels.forEach(function(o) {
if (!(d.name in clicked_names)) {
d.text.label.remove();
}
I know I'm just not grokking the d3 model at all....
thx
The problem comes down to your use of in to search for a name in an array. The Javascript in keyword searches object keys not object values. For an array, the keys are the index values. So testing (d.name in clicked_names) will always return false.
Try
i = j = 0;
if (!bo) { //bo=False - from mouseout
//labels.select('text.label').remove();
labels.filter(function(o) {
return (clicked_names.indexOf(o.name) < 0);
})
.text(function(o) { return ""; });
j++;
}
The array .indexOf(object) method returns -1 if none of the elements in the array are equal (by triple-equals standards) to the parameter. Alternatively, if you are trying to support IE8 (I'm assuming not, since you're using SVG), you could use a .some(function) test.
By the way, there's a difference between removing a label and just setting it's text content to the empty string. Which one to use will depend on whether you want to show the text again later. Either way, just be sure you don't end up with a proliferation of empty labels clogging up your browser.

Parsing images via nokogiri and xpath

I currently have a piece of code which will grab a product title, description, and price and for that it works great. However, I also need it to get the image URL which is where my dilemma is. I tried using a xpath inside the loop I have at the bottom and it lists out ALL the images that are equal to 220 on EVERY product which I dont want at all. So basically I get something like this....
product 1 Title here
product 1 Description here
product 1 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
product 2 Title here
product 2 Description here
product 2 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
Where as I obviously want product 1 to just have http://www.test.com/product1.jpg and product 2 to have http://www.test.com/product2.jpg etc, etc. The images are just in a div tag with no class or ID hence why I didnt just easily put them into a css selector. Im really new to ruby/nokogiri so any help would be great.
require 'nokogiri'
require 'open-uri'
url = "http://thewebsitehere"
data = Nokogiri::HTML(open(url))
products = data.css('.item')
products.each do |product|
puts product.at_css('.vproduct_list_title').text.strip
puts product.at_css('.vproduct_list_descr').text.strip
puts product.at_css('.price-value').text.strip
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
end
Try changing:
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
to:
puts product.xpath('.//img[#width = 220]/#src').map {|a| a.value }
The point of the '.' there is to say you want all images that are children of the current node (e.g. so you're not peeking at product 2's images).
File#basename will return only the filename:
File.basename('http://www.test.com/product4.jpg')
#=> "product4.jpg"
So you probably want something like this:
puts product.xpath('//img[#width = 220]/#src').map {|a| File.basename(a.value) }

Resources