I'd like a snipe of code to convert a google docs text document template in a PDF file. I know how to create a new document as a google text document, but not how to transform it in a PDF file.
I find this piece of code:
var pdf = UrlFetchApp.fetch("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+key+"&exportFormat=pdf&gid=1&gridlines=0&printtitle=0&size=7&fzr=true&portrait=1&fitw=1", requestData).getBlob().setName(name);
return pdf;
But I don't need spreadsheet customization (actually, I don't need spreadsheet, but text file).
How can I can do it? Only with UrlFetchApp.fetch class?
One more question: can I automaticaly send this PDF file to be printed after I've created it?
Thanks!
If I understand you correctly your question is about getting a text document as pdf ?
There is a dedicated method for that :
DocsList.getFileById('document ID').getAs('application/pdf');
see related documentation here
Related
I have to present for an exam a portfolio which allows visitors to download some documentations about my projects as pdf files.
I tried using an tag with a "download" attribute, unfortunately when I try to download the file by clicking on the link, the file is proposed to be recorded as .html or all files.
Whatever option I choose, after downloading the file, I'm not able to open it because it seems damaged or in the wrong format.
Here's the code I use :
My "demo" var is contained in an object Work as you can see on the screenshot :
In case it matters, my pdf file is stored here:
Thanks for you help ! =)
As a wild guess :
your path is wrong (documents/pdt-test.pdf)
your html is missing a doctype or a proper structure
you need a doctype/pdf somewhere. Something like in here Download a by ByteArray as pdf /handle error in React
I'm trying to create a pdf for easy reference of jobs on google careers however when I try to create a PDF using wkhtmltopdf I'm getting a blank page.
I believe this has something to do with the html of the page itself? When I try to inspect the page source the html code is very short. There's also a few javascript links.
The URL I'm trying is this one
And here's the code I'm using:
pdfkit.from_url("https://careers.google.com/jobs/results/125555613246595782-partner-engineer-google-cloud/", 'test.pdf',
options={'--javascript-delay': 5000})
Using wkhtmltopdf like this also returns a blank pdf:
wkhtmltopdf https://careers.google.com/jobs/results/125555613246595782-partner-engineer-google-cloud/ test.pdf
Google used client-side rendering for this page.
This is an old link, but maybe it will be useful to you
https://github.com/devongovett/node-wkhtmltopdf/issues/70
I have a dynamic pdf file which needs to be filled programmatically. I am using itext libraries to do so. Below are the steps I followed.
Extract the dynamic pdf and get the data xml file.
Fill the xml data file.
Call the itext apis to generate new pdf by passing the template pdf and xml data file.
The issue I face is if there is a repeater inside the container (which has a close button) in the template pdf, its not copied into the generated interactive pdf file. None of the javascript functionalities are triggered when creating the new pdf and because of which some of the fields become read only.
Is it possible to trigger the javascript in the pdf while generating the new pdf or while opening the new pdf?
Much appreciate any help.
I want to dynamically manage and update a section of a Google Sites page (think HTML).
I understand this needs to be done via a Gadget (to get it on the page), Google Script, and via HTMLService.
The Google Script Editor has a .gs tab and HTML tab for writing the script and HTML. However, I want to separately manage and update the HTML in a document on Google Drive, and have the script use that to feed the HTML back to the page.
Is there a way to reference the document to .createHTMLOutputFromFile(), so that I can have it use the HTML in the doc on Google Drive, rather than having to compose HTML in the Google Script Editor? Please see .gs function example below:
return HtmlService.createHtmlOutputFromFile
(replace **'Index'** with **'Google Docs URL to Google Docs HTML document'**);
I tried different methods for providing the URL, but the script editor can never find the HTML document using the URL I provide. If this is possible, where can I find an example of how to provide the proper URL?
I'd use HtmlService.createHtmlOutput and stream the text in.
var template_welcome = HtmlService.createTemplateFromFile('welcome_template_view');
return template_welcome.evaluate().setTitle("Template Welcome");
that is an example of how to use an html file that is in your google scripts directory. The welcome_template_view is an html file in my directory.
How can I open a text file, read the contents, and then insert the contents into a document in InDesign?
Here's an example of reading a file from InDesign. If you want to write to a file as well, you will need to open the file in write mode w instead.
// Choose the file from a dialog
var file = File.openDialog();
// Or use a hard coded path to the file
// var file = File("~/Desktop/hello world.txt");
// Open the file for reading
file.open("r");
// Get the first text frame of the currently active document
var doc = app.activeDocument;
var firstTextframe = doc.pages[0].textFrames[0];
// Add the contents of the file to the text frame
firstTextframe.contents += file.read();
Here is a link to the File object's documentation online. You can also find the rest of InDesign's scripting DOM documentation here.
This is the pdf for InDesign JavaScript scripting. There's a few mentions of a File object in there, but it's not documented.
http://www.adobe.com/products/indesign/scripting/pdfs/InDesignCS4_ScriptingGuide_JS.pdf
That's because the core utilities for all CS5 products are documented here
https://www.adobe.com/content/dam/Adobe/en/devnet/indesign/cs55-docs/InDesignScripting/InDesign-ScriptingTutorial.pdf
or the general documentation:
http://www.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_guide.pdf
Look for: File System Access
Thanks for the pointer to the various PDFs.
The response to this question is in the execute() command.
fileObj.execute()
Javascript does not allow access to your computer's operating system, files or directories for security reasons, therefore there is no way to access the text file directly using Javascript.
Usually a server-side technology such as PHP, Adobe Coldfusion, Java or .NET (for example) is used to upload the file via a HTML form submission, read it and do whatever it needs to do.
I hope that helps.