I want to enable duplex-mode of a printer automatically by just opening a PDF file in a browser. this code works completely fine - also setting it to duplex-mode works. the only big problem is: it is setting the page-handling to booklet-style.
var pp = this.getPrintParams();
pp.printerName = "Company Printer Name";
pp.interactive = pp.constants.interactionLevel.silent;
pp.pageHandling = pp.constants.handling.booklet;
pp.booklet.binding = pp.constants.bookletBindings.Left;
pp.booklet.duplexMode = pp.constants.bookletDuplexModes.BothSides;
this.print(pp);
you find this example a couple of times, also in the official Adobe documentation: https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf
but it's always just referring to the booklet-page style.
is there a possibility to change to duplex-mode without being in booklet mode? (preferably with pdf js)
update:
I managed to set my duplexmode successfully by changing the PDF's source adding these lines (using FPDF):
/ViewerPreferences<<
/Duplex /DuplexFlipLongEdge
>>
the duplex-mode is set in the print dialog, but it is ignored when you silently print it with adobe js. it works when you manually click the "print" button in the print dialog though.
so my "bonus"-question is: how do i automatically (silently) print it with adobe js without ignoring the document's settings? maybe some delay could help here?
Related
I need to create PDF forms using Antenna House Formatter.
The forms need to have both digital-signature and image-input fields.
The digital signature with AHF-CSS works on its own:
input.signature{
display: -ah-form-field;
-ah-field-type: signature;
}
As does the image-input HTML/JavaScript:
<meta name="openaction"
content="#JavaScript=
var f = this.getField('imageInput');
f.setAction('MouseUp', 'event.target.buttonImportIcon();');
"/>
But if I use both together and try to enter a digital signature I get the message:
The document cannot be signed in its current state. Please save the
document, close it, reopen it, and then attempt to sign again.
Saving and reopening does not fix the problem. Is there a way to resolve this?
I had to ask Antenna House Support about this. (You could do it if your maintenance is current.) Their answer:
I don't think it will be possible with Formatter and CSS. The 'OpenAction' script modifies the document with this code:
f.setAction('MouseUp', 'event.target.buttonImportIcon();');
Even if you save the document the 'OpenAction' script will run again and modify it.
With XSL-FO you could avoid an OpenAction script by just setting the 'MouseUp' value directly:
<axf:form-field-event name="MouseUp" action-type="javascript">
event.target.buttonImportIcon();
</axf:form-field-event>
'form-field-event' isn't available with CSS.
One horrible work around is to add a check in the 'OpenAction' script to see if the button was already modified. Ex:
var f = this.getField('imageInput');
if (color.equal(f.fillColor, color.red)) {
/* do nothing, this will happen after document is saved */
} else {
f.fillColor = color.red;
f.setAction('MouseUp', 'event.target.buttonImportIcon();');
}
You could 'save' the Formatter generated PDF in Acrobat and then the saved result could get the signature.
There might also or instead be a place to set this.dirty = false; so that the document isn't seen as modified. (I've previously used this.dirty = false; in a JavaScript function that toggles layers off and on: I didn't want to be prompted to save the document on closing just because some layers had changed visibility.)
I try to upload an image on my instagram, so I need to select path for upload files
but I can't use form.file_field.send_keys(path) because Instagram manage upload via JS, so the form not exist, it's only when I click on button "+" then the "File Upload" window appear.
I try :
#browser.send_keys #path
#browser.send_keys :enter
but not works too...
I don't found a method to interact with this sub-windows "File Upload" to give the path of image.
Any idea?
EDIT :
<nav class="NXc7H f11OC "><div class="_8MQSO ZoygQ "><div class=""><div class="rBWT5"></div><div class="KGiwt"><div class="A8wCM"><div class="BvyAW"><div class="q02Nz"><a class="_0TPg" href="/"><span class="glyphsSpriteHome__outline__24__grey_9 u-__7" aria-label="Home"></span></a></div><div class="q02Nz"><a class="_0TPg" href="/explore/"><span class="glyphsSpriteSearch__outline__24__grey_9 u-__7" aria-label="Search & Explore"></span></a></div><div class="q02Nz _0TPg" role="menuitem" tabindex="0"><span class="glyphsSpriteNew_post__outline__24__grey_9 u-__7" aria-label="New Post" style=""></span></div><div class="q02Nz"><a class="_0TPg " href="/accounts/activity/"><span class="glyphsSpriteHeart__outline__24__grey_9 u-__7" aria-label="Activity"></span></a></div><div class="q02Nz"><a class="_0TPg" href="/tristan_grey_30/"><span class="glyphsSpriteUser__filled__24__grey_9 u-__7" aria-label="Profile"></span></a></div></div></div></div><form class="Q9en_" enctype="multipart/form-data" method="POST" role="presentation"><input accept="image/jpeg" class="tb_sK" type="file"></form></div></div></nav>
if I try using the <form> contain in <nav>, nothing happen, there is onClick event on "+" :
{
!0 !== this.$_MobileNav2 && (this.$_MobileNav2 = !0, r(d[1]).logAction_DEPRECATED('cameraIconClick'), this.$_MobileNav3 ? (this.$_MobileNav3.selectFile(), this.props.onStartCreation()) : (i(d[2])('No image form'), this.props.onImageFormError()), this.$_MobileNav2 = !1)
}
It's manage by JS I think...
You aren't going to like the answer, but Watir will not interact with that window opened up by the OS in any way. Going a step further, Ruby itself does not interact with these OS level dialogues.
There are a couple of things that you may want to reference to confirm this, and that's perfectly acceptable:
Watir's Philosophy on Downloads (and conversely Uploading)
An answer by Thomas Walpole explaining what I just did
A possible solution using Capybara::Node::Actions#attach_file
In any case, you are attempting to interact with an object that does not have a way of being interacted with through Ruby, let alone Watir, and thus your desired solution is impossible.
Your best case is the Capybara attach_file method. If that doesn't work, nothing is going to outside of a literal OS scripting language such as AutoIt or Sikuli
You can find the SikuliX project page here. DrapsTV did a roughly hour-long playlist about the setup and quickstart of SikuliX. The link to the first episode in the series is linked here.
Good luck.
I'm going to go with a bit of a JavaScript hack to expose the hidden <input type="file">. The first thing to do is identify the input type file on the page, then use some JavaScript to make it visible. Then once it is visible use send_keys to pass in the path to the local file and selenium should do the rest for you.
file_upload_element = #browser.file_field
#browser.execute_script("return arguments[0].setAttribute( 'style', 'display: inline !important')", file_upload_element)
file_upload_element.set(<path_to_local_file>)
Some caveats. I don't use Watir, I've tried to write the above code based on the Watir documentation and the code you have provided, it is a guess though. I can write it in a language I'm familiar with if that helps. I am hoping it's close enough to point you in the right direction though.
As mentioned the comments earlier, can you try appending the file input element to the html and then use that to upload the file.
# get the frame element or any button that opens the file upload window
ele = driver.find_element_by_id("frame/button id goes here")
# add a hidden file input ( might have to change the onchange event based on the events associated to the button in above line as you don't have a form)
driver.execute_script("var x= document.createElement('INPUT');x.setAttribute('type', 'file'); x.setAttribute('onchange','this.form.submit()');x.setAttribute('hidden', 'true'); arguments[0].appendChild(x);",ele)
# send the picture path here ( this should upload the file)
driver.find_element_by_xpath("//input[#type='file']").send_keys("picture path should go here")
Can you please try this and let me know your outcome.
#browser.file_field.set file_upload works for me
I had to update my Chrome Driver which was little bit tricky on Windows. Belows is my complete script for upload to a Dropbox File Request:
require 'watir'
#setting the path to my updated ChromeDriver:
Selenium::WebDriver::Chrome::Service.driver_path = 'C:\#Ruby\#no_pub\install\chromedriver.exe'
class Dropbox_Request
def initialize(url, file_upload)
#browser = Watir::Browser.new
#browser.goto url
#browser.file_field.set file_upload
#browser.text_field(:name => 'fname').set "first"
#browser.text_field(:name => 'lname').set "last"
#browser.text_field(:name => 'email').set "email#gmail.com"
#browser.button(:class => ["button-primary", "submission-form__submit"]).click()
end
end
There is a site which was working fine till a few days back. Its coded in PHP and has CKEditor as WYSIWYG editor integrated in the Admin panel pages, to update content.
However, since a few days, it only displays as a plain textarea instead of CKEditor (WYSIWYG interface). I checked the code, it seems all fine. Files and their Path references seems fine as well.
Could it be the PHP version upgrade or some server side update caused this issue? Here is my code below used for displaying the ckeditor (applying to textarea)
<textarea id="pbody" name="pbody" class="ckeditor"></textarea>
<?php
// Include CKEditor class.
include_once "../ckeditor/ckeditor.php";
include_once '../ckfinder/ckfinder.php' ;
// Create class instance.
$CKEditor = new CKEditor();
// Path to CKEditor directory, ideally instead of relative dir, use an absolute path:
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = '../ckeditor/';
$ckfinder = new CKFinder();
$ckfinder->BasePath = '../ckfinder/';
// Note: the BasePath property in the CKFinder class starts with a capital letter.
$ckfinder->SetupCKEditorObject($CKEditor);
// Replace textarea with id (or name) "editor1".
$CKEditor->replace("pbody");
?>
In my polymer app, when I open a paper-dialog using an iPhone, it's not centered, as opposed to opening it using Chrome or Safari using the a desktop Mac or PC.
I'm dynamically constructing the paper-dialog element and placing it in the DOM template using javascript, and then calling open():
var d = document.createElement('paper-dialog');
d.innerHTML = "<h2>Dialog Title</h2>"
"<p>some content</p>"+
'<div class="buttons">'+
"<paper-button >More Info...</paper-button>"+
"<paper-button dialog-dismiss>Decline</paper-button>"+
"<paper-button dialog-confirm autofocus>Accept</paper-button>"+
"</div>";
var b = Polymer.dom(this.root).appendChild(d);
b.open();
I'm not using any special styles or media queries.
The reason I'm adding the dialog programatically is because I have tons of different dialog messages and different contents to show at different times, and each of them should call a callback at a different screen, depends on who added the dialog. in other words, I need to have my dialogs added like in angular-material's $mdDialog, I know it's not that trivial for polymer, maybe not the intended use, but for my case that's what I need, unless there's a better way.
See screenshot of the problem below
iPhone:
Chrome:
The issue was that I called b.open(); right after var b = Polymer.dom(this.root).appendChild(d);.
Since I add the element dynamically, I should have put b.open(); under a this.async() call, as mentioned in polymer's documentation for similar cases.
Also fixed the code in my dialog-manager
There is a HTML textarea. I'm able to catch that event when a local file is dragged and dropped onto the textarea. But how to obtain the name of the dropped file? (To be modified and inserted into the textarea finally.)
The following expressions returns None in that case:
event.dataTransfer.files
event.dataTransfer.getData('text/plain')
I made a short example for Firefox 3 that is my target platform currently.
<script>
function init() {
document.getElementById('x').addEventListener('drop', onDrop, true)
}
function onDrop(event) {
var data = event.dataTransfer.getData('text/plain')
event.preventDefault()
alert('files: ' + event.dataTransfer.files + ' && data: ' + data + '.')
}
</script>
<body onload='init()'>
<textarea cols=70 rows=20 id='x'></textarea>
This is a bit late - but I think what you are looking for is this:
event.dataTransfer.files[0].name
You can also get the following properties:
event.dataTransfer.files[0].size
event.dataTransfer.files[0].type
And you can loop thru these files with the following:
var listOfNames='';
for(var i=0,tot=event.dataTransfer.files.length; i<tot; i++){
listOfNames+=event.dataTransfer.files[i].name + '\r\n';
}
Btw - if you are using jQuery then the dataTransfer object can be found here:
event.originalEvent.dataTransfer.files[0].name
Don't know if it's still relevant, but I faced the same problem. Here's how I solved it:
Create a normal upload form with a single input field (type="file")
Add this HTML attribute to the input field:
dropzone="copy file:image/png file:image/jpg file:image/jpeg"
Set JQuery listener or whatever to catch the "drop"-event on the input field
When you drag & drop a local image on the input field, the "value" attribute is filled automatically and you can process it like any other HTML form.
I also wrapped the form into another HTML element (div), set the size of the div and set overflow:hidden via CSS - this way, you can get rid of the "browse" button. It's not nice, but it works. I also used the AjaxForm plugin to upload the image in the background - works very nice.
as far as I know, you need to obtain an instance of nsIFile in order to get the file path (the File class does not offer this feature).
This MDC page explains how to do this: https://developer.mozilla.org/En/DragDrop/Recommended_Drag_Types#file.
Note that although not listed in the previous link, obtaining an nsIFile instance requires privileges escalation (cf. my answer to Can I drag files from the desktop to a drop area in Firefox 3.5 and initiate an upload? show how to do this).
im doing it by detecting mouseover and mousedown over the "Drop" zone
Alemjerus is correct, you don't have access to what you're looking for.
The behavior you mentioned in reply to his comment is the default behavior of certain browsers. For instance, with the stackoverflow textarea for this entry, if I use Safari and drag a file into it, it places the file's path into the textarea. With firefox 3.5, on the other hand, it attempts to open the file with the browser.
Basically, the "drag and drop" functionality you're attempting to implement is something thats handled by the browser and OS on the client machine -- you can't use Javascript for this purpose.
You can not do it with Javascript because of security reasons. Javascript VM has no direct access to OS file system. You can only drag and drop text.