I am very far for Web development. I need a Chrome extension which will copy page root directory html text to clipboard.
There is single file which is doing this job, but it working very slowly.
I make extension which downloads the page html with text file. But I want just copy . And in exe application paste.
function copyTextToClipboard()
{
var copyFrom=document.documentElement.innerHTML;
var file = new Blob([copyFrom], {type: 'text/plain'});
var atag = document.createElement("a");
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate()+' '+today.getHours()+today.getMinutes()+today.getSeconds();
atag.href=URL.createObjectURL(file);
atag.download=date+".txt";
atag.click();
atag.remove();
//console.log(date);
var t =setTimeout(function(){ copyTextToClipboard() },10000);
}
copyTextToClipboard();
Any suggestion?
I found solutation. This code copying html file, in txt format every 5 second.
function copyTextToClipboard()
{
var copyFrom=document.documentElement.innerText;
if(copyFrom!=null)
{
var area = document.createElement("textarea");
area.value=copyFrom;
document.body.appendChild(area);
area.select();
document.execCommand('copy');
document.body.removeChild(area);
}
var t =setTimeout(function(){ copyTextToClipboard() },5000);
}
copyTextToClipboard();
Related
I am making a PDF Viewer. I am using ADOBE View SDK. I have a File input but the problem is that I want to show the file in different views - Full Screen, Half Screen and In-Line. But when the user selects a file and selects a different view the whole page reloads and then the user has to select the file again. I don't want the user to select the file again.
File Input:
<input type='file' onchange="listenForFileUpload(this);" id="file-picker" accept="application/pdf">
listenForFileUpload function:
var fileToRead = document.getElementById("file-picker");
fileToRead.addEventListener("change", function (event) {
var files = fileToRead.files;
var input = document.getElementById('file-data').value
input = files
console.log(files)
document.getElementById('file-form').submit()
if (files.length > 0 && isValidPDF(files[0])) {
var fileName = files[0].name;
var reader = new FileReader();
reader.onloadend = function (e) {
var filePromise = Promise.resolve(e.target.result);
previewFile(filePromise, fileName);
};
reader.readAsArrayBuffer(files[0]);
}
}, false);
}
Please help me to change the view without reloading.
It's this line here:
document.getElementById('file-form').submit()
You are submitting the form there. I'd just remove it.
I'm using JsPDF to generate a number of PDF files and then download them. With Chrome and Edge it's correctly generating and downloading all of them, but with Firefox is downloading only the first one.
This is my code:
<script>
$( document ).ready(function() {
let doc = new jsPDF();
doc.text(20, 20, 'hello');
for(a = 0; a < 6; a++){
// doc.output('dataurlnewwindow'); < NOT WORKING ON RECENT BROWERS.
// doc.output('datauri');
// doc.addHTML($('#content'), 1, 1, function () {
// var blob = doc.output("blob");
// window.open(URL.createObjectURL(blob));
// });
doc.save('file_number_' + 'a' + '.pdf'); < DOWNLOADS ONLY THE FIRST FILE IN FIREFOX.
}
});
</script>
How could I be able to download all the generated files? It would be OK even if I could open them in a new window, as long as I'm able to specify the filename of the PDF.
Thanks in advance.
Edit: as indicated by pytness, it appears Firefox is blocking the process.
I just tried to delay the clicks in this way:
function clickAll(){
let waiter = 0;
$('.pdf_line').each(
function(){
if ($(this).find('input').prop('checked')){
//console.log('click! waiter = ' + waiter);
$(this).find('.print_document').delay(4000*waiter).click();
waiter++;
};
}
)
}
But after the first download Firefox halts the whole process.
It looks like you’re saving the file with the same name every time in your loop, so it’s just saving over it each time. Try changing the ‘a’ in your doc.save to a
Bellow I have attach my code.
I am trying to print the excel file using angular with out user pressing the ctrl+P. I did found the relevant code in below link and I am able to open the print popup but with just blank white page with no content on it. Thank you for you suggestions in advance.
printListXcel() {
this.listService.getListExcel(this.ListId).subscribe(data => {
const blobData = new Blob([data], {
type:'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet'});
const blobUrl = URL.createObjectURL(blobData);
const iframexcel = document.createElement('iframe');
iframexcel.style.display = 'none';
iframexcel.src = blobUrl;
document.body.appendChild(iframexcel);
iframexcel.contentWindow.print();
});
}
how to print pdf in Angular 2
I am trying to do an XML import automatically from a startup script when a document is loaded. I am successful in getting most of the content to populate, but images are being ignored. Everything works, including images, when I do a manual 'Import XML' through the UI, or through a manual script.
Below is my manual script:
var myDocument = app.activeDocument;
var xmlFile = File('/c/Full/Path/To/data.xml');
myDocument.importXML(xmlFile);
But the goal is to do it on startup. Below is my startup script:
#targetengine "session"
app.addEventListener('afterOpen', function(myEvent) {
if (myEvent.target.constructor.name !== 'Document') {
return;
}
var myDocument = myEvent.target;
var xmlFile = File('/c/Full/Path/To/data.xml');
myDocument.importXML(xmlFile);
});
Below is the XML tag for the image:
<Image href="file:///C:/Full/Path/To/Image/02.png" />
I'm wondering if there is an issue with the 'afterOpen' event callback, and that's the reason why it works manually using the same method, but not in the startup script.
I was able to get around the issue by avoiding the event listener altogether.
main();
function main () {
// create a path for a file object
var curFile = File('/c/Path/To/file.indd');
var xmlFile = File('/c/Path/To/data.xml');
// close app if files don't exist
if (!curFile.exists || !xmlFile.exists) {
app.quit(SaveOptions.NO);
}
// open the file
var curDoc = app.open(curFile);
// import the xml
curDoc.importXML(xmlFile);
// create a new file object
var pdfFile = new File(curFile.parent + '/' + curFile.name + '.pdf');
// export to pdf
curDoc.exportFile(ExportFormat.PDF_TYPE, pdfFile);
// close app
app.quit(SaveOptions.NO);
}
I'm building my own WYSIWYG editor, using an iframe, I'd like to find just a way to simply insert an image! I already got the Bold style, Italic style, H1 and H2, using JS:
function bold(){
editor.document.execCommand("bold", false, null)
}
function italic(){
editor.document.execCommand("italic", false, null)
}
function h1(){
editor.document.execCommand('formatBlock',false,'h1');
}
function h2(){
editor.document.execCommand('formatBlock',false,'h2');
}
That works very well but I'm struggling with "Insert image button"
Since I'm really new with coding, I was trying this:
function image(){
var image = prompt ("Paste or type a link", "http://")
editor.document.execCommand("createImage", false, image)
But that doesn't work. My intention is that the users have the possibility to upload images from their computer and/or from internet. Please, if anyone knows how to insert an image... help!
A LOT OF THANKS IN ADVANCE!
Have you tried formatting your image location using a relative link where the # symbol precedes the image location. Your code and explanation also doesn't explain are they uploading the image from their machine in a location like My Documents or if they are uploading the image strictly from and http link.
To upload from a local machine using Javascript and HTML, you might checkout this code. Your question is one that regularly comes up when writing custom Javascript functions.
<script type='text/javascript'>
function main()
{
var inputFileToLoad = document.createElement("input");
inputFileToLoad.type = "file";
inputFileToLoad.id = "inputFileToLoad";
document.body.appendChild(inputFileToLoad);
var buttonLoadFile = document.createElement("button");
buttonLoadFile.onclick = loadImageFileAsURL;
buttonLoadFile.textContent = "Load Selected File";
document.body.appendChild(buttonLoadFile);
}
function loadImageFileAsURL()
{
var filesSelected = document.getElementById("inputFileToLoad").files;
if (filesSelected.length > 0)
{
var fileToLoad = filesSelected[0];
if (fileToLoad.type.match("image.*"))
{
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var imageLoaded = document.createElement("img");
imageLoaded.src = fileLoadedEvent.target.result;
document.body.appendChild(imageLoaded);
};
fileReader.readAsDataURL(fileToLoad);
}
}
}
main();
</script>
You can check out the full article on this issue of image uploads using Javascript and HTML 5 here: https://thiscouldbebetter.wordpress.com/2012/12/20/uploading-and-displaying-an-image-from-a-file-using-html5-and-javascript/
It should be "insertimage" instead of createImage.
function image(){var image = prompt ("Paste or type a link", "http://")editor.document.execCommand("insertimage", false, image)}
you can use this post
var insertImgTag = document.createElement("div");
insertImgTag.id = "insertImgTag";
if (document.getSelection().anchorNode != null) {
document.getSelection().getRangeAt(0).insertNode(insertImgTag);}
$("#insertImgTag")
.parent()
.html(
"<img src=/images/" + $("#name").val() + " width='" + imgWidth + "%' alt='" + imgAlt + "'>"
);
that I used it in my own javascript editor according to this post