Printing PDF to folder in Google Drive - javascript

I am using a script to print a spreadsheet to PDF.I would like to print it to a location on the drive "PDF Folder". Anyone know how to do this?
Heres is my code :
function printpdf(){
var spreadsheet_id="0AkcI3cOVJXI3dHg3Nnk3Y2JUakViTkUzQzdXSUdLNEE";
var spreadsheetFile = DocsList.getFileById(spreadsheet_id);
var blob = spreadsheetFile.getAs('application/pdf');
DocsList.createFile(blob);
}

just add it to the folder like this :
(I reproduce the whole code)
function printpdf(){
var spreadsheet_id="0AkcI3cOVJXI3dHg3Nnk3Y2JUakViTkUzQzdXSUdLNEE";
var spreadsheetFile = DocsList.getFileById(spreadsheet_id);
var blob = spreadsheetFile.getAs('application/pdf');
var folder = DocsList.getFolder('PDF Folder'); //get the folder by its path
var pdf = DocsList.createFile(blob).addToFolder(folder);
}

Related

Download PDF file from link .NET Vue

I try to download a pdf file from my sql database.
I display list from database. My purpose is get pdf file from link.
Because of loop "for" I don't know how to get a correct path to download it.
///FRONTEND CODE
<tr v-for="not in notatki">
<td>{{not.NotatkaId}}</td>
<td>{{not.NotatkaName}}</td>
<td>{{not.Przedmiot}}</td>
<td>{{not.DateOfJoining}}</td>
<td><a href="http://localhost:37924/api/Notatki/{{not.NotatkaFileName}}" download>Download File</a></td>
<td>
///API CODE
public JsonResult SaveFile()
{
try
{
var httpRequest = Request.Form;
var postedFile = httpRequest.Files[0];
string filename = postedFile.FileName;
var physicalPath = _env.ContentRootPath + "/Notatki/" + filename;
using (var stream = new FileStream(physicalPath, FileMode.Create))
{
postedFile.CopyTo(stream);
}
return new JsonResult(filename);
}
It is link with error
[1]: https://i.stack.imgur.com/H5fqW.png

How can I send the .xlsx file created on the client to mail?

Here I`m creating a file using JQuery plugin table2excel:
$('.btn-primary-1').on('click', function(){
$("#table1").table2excel({
name:"Worksheet Name",
filename:"fileName",//do not include extension
fileext:".xlsx", // file extension
preserveColors:true
});
});
This is how I fill the table:
$('.one_busket').on('click', function(){
let $tovar1 = $('.title_one').html();
let $value1 = $('.one_number').val();
let $itog1 = $('.end1').text();
$('.tbody1').append('<tr><td class="td_tovar">'+$tovar1+'</td>'+'<td>'+$value1+'</td><td class="td_itog" id="td">'+$itog1+'</td></tr>');
});
I can't just send the dynamically created table, so I decided to send an .xlsx file by mail. Now I need not just download the file, but send this file by mail via PHP. How can i do this?
P.S
This is what a crutch looks like now, which can only send 6 goods.
PHP:
$input_tovar1 = $_POST['input_tovar1'];
$input_value1 = $_POST['input_value1'];
$input_itog1 = $_POST['input_itog1'];
$input_tovar2 = $_POST['input_tovar2'];
$input_value2 = $_POST['input_value2'];
$input_itog2 = $_POST['input_itog2'];
$input_tovar3 = $_POST['input_tovar3'];
$input_value3 = $_POST['input_value3'];
$input_itog3 = $_POST['input_itog3'];
$input_tovar4 = $_POST['input_tovar4'];
$input_value4 = $_POST['input_value4'];
$input_itog4 = $_POST['input_itog4'];
$input_tovar5 = $_POST['input_tovar5'];
$input_value5 = $_POST['input_value5'];
$input_itog5 = $_POST['input_itog5'];
$input_tovar6 = $_POST['input_tovar6'];
$input_value6 = $_POST['input_value6'];
$input_itog6 = $_POST['input_itog6'];

javascript .js file external url

I am using gnuplot-js https://github.com/chhu/gnuplot-JS when I am without my laptop at university.
Is it possible to use an external url for gnuplot.js file? I host index.html, gnuplot_api.js on https://mywebsite.com/ but I would like to use another url for gnuplot.js file (for example https://external.com/blabla/ok/no/gnuplot.js) because this file is really big!
Maybe this is the part I should edit on index.html. How? :
<script src='gnuplot_api.js'></script>
<script>
gnuplot = new Gnuplot('gnuplot.js');
gnuplot.onOutput = function(text) {
document.getElementById('output').value += text + '\n';
document.getElementById('output').scrollTop = 99999;
};
or maybe this part on gnuplot_api.js?:
var Gnuplot = function(js_filename) {
this.worker = new Worker(js_filename);
this.output = [];
this.error = [];
this.isRunning = false;
Thank you very much for your support
It appears Gnuplot use an onboard webworker, so the path provided to the constructor should be on the same domain than the script.
<script src='https://cdn.jsdelivr.net/gh/chhu/gnuplot-JS/www/gnuplot_api.js'></script>
<script>
gnuplot = new Gnuplot('https://cdn.jsdelivr.net/gh/chhu/gnuplot-JS/www/gnuplot.js');
</script>

Print Google Spreadsheet cells to PDF file

I want to print cells from a sheet to a PDF file. This PDF file should not be created in Google Drive but downloadable to disk.
Here is my code:
function PrintPDF(LigneDebut, ColonneDebut, LigneFin, ColonneFin) {
SpreadsheetApp.flush();
feuilleImprimer = SpreadsheetApp.getActiveSpreadsheet();
var sheet = feuilleImprimer.getActiveSheet();
var gid = sheet.getSheetId();
var pdfOpts = '&size=A4&fzr=false&portrait=true&fitw=true&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=false&gid='+gid;
var printRange = '&c1='+ColonneDebut + '&r1='+LigneDebut + '&c2='+ColonneFin + '&r2='+LigneFin; // B2:APn
var url = feuilleImprimer.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts + printRange;
var app = UiApp.createApplication().setWidth(200).setHeight(150);
app.setTitle('Printing ' + feuilleImprimer.getSheetName());
var link = app.createAnchor('Download PDF', url).setTarget('_new');
app.add(link);
feuilleImprimer.show(app);
}
Some APIs are out of date: UiApp, Anchor, and UiInstance.
This generates warning messages.
By what methods to replace these deprecated API?
Thanks for your help.
To address the deprecated issue, just go to the official Apps Script doc reference. For example, in the case Class UiApp, use the HTML Service instead.
For a working code of converting spreadsheet to pdf and download, check ixhd/gist:3660885 and Convert and Email Google Spreadsheets as PDF Files.

Google Apps Script WebApp Pass html to file

This is a followup on this post.
I'm now trying to use a template file so I can pull in some css, etc. I am publishing this as a web app. The output should be a list of the files in a Google Drive directory contained in an iframe.
The loading message appears in the iframe and I don't get any syntax errors but the list of files in the directory does not appear.
code.gs:
function doGet() {
return HtmlService.createHtmlOutputFromFile('page');
}
function FileList() {
// my folder ID
var dir = '[MY_FOLDER_ID]';
var folder = DriveApp.getFolderById(dir);
var contents = folder.getFiles();
var filelist = [];
var file, name, url, idName = [];
while (contents.hasNext()) {
file = contents.next();
name = file.getName();
idName = name.toUpperCase();
url = file.getUrl();
// add table row html to filelist array
filelist = filelist.concat('<tr><td><a id="' + idName + '" target="_blank" href="' + url + '">' + name + '</a></td></tr>');
}
// alpha sort filelist array
filelist.sort();
// turn filelist into a string
filelist = filelist.join("");
return filelist;
}
page.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onSuccess(foo) {
var table = document.getElementById('output');
table.innerHTML = foo;
}
google.script.run.withSuccessHandler(onSuccess).getFileList();
</script>
</head>
<body>
<table id="output">Loading Files...</table>
</body>
</html>
There is syntax/typo in your code here:
google.script.run.withSuccessHandler(onSuccess).getFileList();
it should be
google.script.run.withSuccessHandler(onSuccess).FileList();
Since the function name in google script is FileList and not getFileList().
Tip: You can use inspect or developer console in google chrome to see your errors when you run web app.(Not sure if you knew it.)
Hope that helps, good luck!

Categories

Resources