I am developing a Word add-in using Office JS in which a user can decide to open a document from a remote server API. In that case I need to receive a file from the server API and open it in Word.
Currently, I am making an HTTP request to get the document contents from the remote server encoded in Base64.
Then I am using:
var body = context.document.body;
body.insertFileFromBase64 (fileData, Word.InsertLocation.replace);
// (where fileData is the Base64 content)
This works (document is actually opened), but I don't like it so much because it replaces the current document's contents instead of opening a new document.
Is there a way to make Word open a document as a new document instead of replacing the existing document's contents?
I described my use case above in case you can also suggest a better solution.
there is an API, in preview, you can use for this. here is a code snippet:
(note that the createDocument takes an optional parameter, a base64-encoded docx) if that's provided the opened document will include it.
in order to test the API make sure to use the preview CDN for Office.js avilable here https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
and that you have a fresh update of Office.
here is the code:
Word.run(function (context) {
context.application.createDocument().open(); // optionally on createDocument send a base-64 docx.
return context.sync();
})
Related
I am interesting in obtaining the file type (e.g. PDF, Word doc) of documents sent in an envelope. Of course this could be done just by getting the extension from the file name, but if a filename does not have an extension, is there an API call that would give me the file's type?
You cannot do this. Once the document is uploaded to DocuSign, it's always converted into a PDF. The original is not stored anywhere. You can have code that uses custom fields to store this information, but other than that - you would have to use the file name and the extension in there.
I need to convert word documents to PDF whenever a file is created or modified at Sharepoint. I've seen the component "Convert Word Document to PDF", but when I run the logic app and modify a file, an error shows up. So, what I really want is to convert ALL files I create/modify to PDF, not just one file.
Bad Request.
{
"status": 400,
"message": "There was an error accessing the file. Please try again or select a different file.\r\nclientRequestId: 484f1273-df35-4e9d-881b-086fce0c7ab3",
"source": "wordonlinebusiness-we.azconn-we.p.azurewebsites.net"
}
Screenshot of my logic app.
The action Convert Word Document to PDF, it can't convert doc from the triggerBody, it converts doc file from a location.
You could use other connectors to do it like Plumsail Documents or Encodian, I test with Plumsail Documents.Before you use this, you need to go to this site to register an account to get the API key.The whole flow would be like the below picture shows.
Hope this could help you, if you still have other questions, please let me know.
I'm trying to get all documents in an envelope as a single PDF, if I call this REST API URL:
/v2/accounts/{$accountId}/envelopes/{$envelopeId}/documents/combined
It returns a bunch of data, however, I can't find a way to store this data as a valid PDF. When I output the content with headers it does download a file, but it's not a valid PDF. Also when I store the content in a file, it will not be a valid PDF file.
Anyone encountered this problem and knows how to solve this?
The content comes back as a file, you have to read the temp file and save that to the desired file
Quick snippet using file_get_contents and file_put_contents
$docStream = $envelopeApi->getDocument($accountId, 1, $envelopeId);
file_put_contents("my_document.pdf", file_get_contents($docStream->getPathname()));
More info DocuSign REST API :: EnvelopeDocuments: get under Get a Single Document as a PDF File
I have my code working to upload a PDF document, but I am trying to get it to upload an HTML document and having trouble. My code that works for the PDF document is this:
$documents = new Document();
$documents->setName($doc_name . '.pdf');
$documents->setDocumentId(1);
$documents->setFileExtension('pdf');
$file = file_get_contents($file_url);
$documents->setDocumentBase64(base64_encode($file));
But when I try to do this with an HTML document it fails. My HTML attempt uses this:
$documents = new Document();
$documents->setName($doc_name . '.pdf');
$documents->setDocumentId(1);
$documents->setFileExtension('html');
$documents->setDocumentBase64(base64_encode($html));
When I try this using the REST API Explorer I get this error message:
System was unable to convert this document to a PDF. Unable to convert Document(SampleHTML) to a PDF. Error: UserId:xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx IPAddress:54.213.184.61 Source:ApiRESTv2:FileType UNKNOWN is ineligible for conversion.
I have read that html is an accepted file type, so I am pretty sure this is possible. I could cover to PDF on my server and send, but would rather pass that off to Docusign.
Any help is greatly appreciated.
Thom
The DocuSign platform does indeed accept multiple document formats, however there may be a difference between what the DS Apps accept and what the API accepts. The list of supported document types that you can send through the DocuSign Console can be found here:
https://support.docusign.com/guides/ndse-user-guide-supported-file-formats
However I'm not sure if .html is an accepted file format when sending through the API. I thought there might be security issues with that but not positive at this point. In either case, even though you are setting the fileExtension property it looks like you are still sending a document with a filename that ends with .pdf, have you tried removing that or changing to .html?
So, here's the thing, we have a bunch of pdf forms for users on our website to fill out, we have a submission button inside every pdf form that sends the filled data through a http post method. We are already doing a pre-filled form, where the user fill general information on a html form, data that are used to generate a partially filled multiple pdf files, so whatever the pdf form the user has selected to fill, all of them will be regenerated having the pre-filled information that he just typed on the html form. I accomplish this by using pdftk (http://www.pdflabs.com/docs/pdftk-man-page/) that enables me to just do that. But we get to a point that to make this more efficient, the user must be able to draw their signature on the html side at the pre filled form stage, so we are using signature-pad for this (http://thomasjbradley.ca/lab/signature-pad/), than we create an image from the canvas that the plugin generates. But as each pdf has its own position for the signature, we must insert a placeholder into the pdf that'll be replaced for the signature image. So I came up with the idea to create a disabled text field on the pdf with the name of "signature", so through a nodejs application with the pdf2json module (https://github.com/modesty/pdf2json) I can parse the pdf form and get the position (x,y,w,h) of that particular field, being able to attach an image over the text field placeholder. So the problem is that pdftk don't give me support to attach an image to an existing pdf or even attach it in a certain position, I tried to find a nodejs module that would enables me to do that, but the only worthing nodejs module that I found was pdfkit (http://pdfkit.org/) but it only works creating a new pdf, not editing an exiting one, I looked into pdfkit source code and I discarded it because I realize that it wont work to my case of an existing pdf. So I came to a long way, got to the final stage of this implementation, came to the last step to get this working, and I'm just stack.
This is the output that I have from the pdf2json module for nodejs that is helping with the placeholder approach.
{
page: 7,
index: 317,
name: 'signature',
type: 'alpha',
x: 43.806640625,
y: 14.64195833333333,
w: 30.546828125000005,
h: 1.9339166666666756
}
If someone know any server application that I could run through an unix command at my server to attach an image over an existing pdf document, it'll fit my needs, don't need to be an exclusively nodejs module.
Obs.: I already checked it out the adobe echosign product, but it doesn't fit our needs, it's not free and don't solve our problem of attaching a signature to multiple pdf files from a single html form.
I realize that I could use the nodejs module pdfkit to generate a new blank PDF with the signature in the right position and just over the two pdfs, having the blank pdf with the signature image on the top like a stamp. I could do this with pdftk by command line:
pdftk form.pdf stamp signature.pdf output form-signed.pdf
There's another free application tool like pdftk that I just found out, and it's pdfjam. Also, if you can't use nodejs module pdfkit (different from the application pdfkt) to generate a new pdf with an image to the right spot, you have the stampTK tool (http://www.pdflabs.com/tools/stamptk-the-pdf-stamp-maker/) where you can parse through command line the image to be a stamp in an existing pdf, but this tool is paid (not much, and its worth it), but as I have the pdfkit module for nodejs that enables me to do just that along side the pdfkt application for free, I'm using that, and I also have more control of multiple signatures on the pdfkit module for nodejs. Hope this answer helps someone.