Create Google Drive Document template from HTML and CSS












1















I've been implementing a google drive connector into a web application.



Basically when a known event is triggered in the page it launches a webhook which communicates with the 'drive-connector' in order to generate a document and fill it with some information.



This 'drive-connector' is a custom PHP which uses the Google Drive API to create folders and files. I am able to create the folders and files and give the files the desired content.



To give the content to the drive document I use an HTML template (https://developers.google.com/drive/api/v3/manage-uploads) which is allowed by the API, before uploading it I change some variables inside the template with the data that comes from the webhook, all well for now.



The problem



I'm able to upload the HTML document, once I replace the variables for the desired data, but It has to be very simple and without much css. When I try to upload the document from a more worked and beautiful template Google Drive doesn't recognize many CSS and it changes the appearence of the document. I can't put a header nor a footer. Many fields are moving from its places and making a mess of the whole document.



In order to make it easier for me to replace the variables in the template I choosed to use HTML anyways I'm starting to think that would be easier to use a .doc or .odt template ( I would need to use a library in order to do that )



My question



Is good to use an HTML document as template for the google drive document? Or should I change the way I am trying to achieve this?



Thanks in advance



Observation: Since I don't really have problem with my code I haven't put any line of code, how ever If you need the HTML template to guess if it has any problem, just tell me.



EDIT 1 -> I've found this: How can developers edit a Google Doc programmatically? Is there a Docs API?



It is not the answer of my question but seems to have some solutions to my problem. Anyways I don't get much clear in that post, I haven't found the proper documentation so I'm still fighting to get this.



EDIT 2-> Reading again the documentation I thought that I could make the document firstly in the google drive and then using the API download it as HTML, this way I would have the template but I'm not sure if I could modificate it has I wish. If this works I will reply my own question and close the post




After trying this I could not upload the HTML which was exported from the google doc. The error that the google api gives me is: code 400 message: bad request











share|improve this question





























    1















    I've been implementing a google drive connector into a web application.



    Basically when a known event is triggered in the page it launches a webhook which communicates with the 'drive-connector' in order to generate a document and fill it with some information.



    This 'drive-connector' is a custom PHP which uses the Google Drive API to create folders and files. I am able to create the folders and files and give the files the desired content.



    To give the content to the drive document I use an HTML template (https://developers.google.com/drive/api/v3/manage-uploads) which is allowed by the API, before uploading it I change some variables inside the template with the data that comes from the webhook, all well for now.



    The problem



    I'm able to upload the HTML document, once I replace the variables for the desired data, but It has to be very simple and without much css. When I try to upload the document from a more worked and beautiful template Google Drive doesn't recognize many CSS and it changes the appearence of the document. I can't put a header nor a footer. Many fields are moving from its places and making a mess of the whole document.



    In order to make it easier for me to replace the variables in the template I choosed to use HTML anyways I'm starting to think that would be easier to use a .doc or .odt template ( I would need to use a library in order to do that )



    My question



    Is good to use an HTML document as template for the google drive document? Or should I change the way I am trying to achieve this?



    Thanks in advance



    Observation: Since I don't really have problem with my code I haven't put any line of code, how ever If you need the HTML template to guess if it has any problem, just tell me.



    EDIT 1 -> I've found this: How can developers edit a Google Doc programmatically? Is there a Docs API?



    It is not the answer of my question but seems to have some solutions to my problem. Anyways I don't get much clear in that post, I haven't found the proper documentation so I'm still fighting to get this.



    EDIT 2-> Reading again the documentation I thought that I could make the document firstly in the google drive and then using the API download it as HTML, this way I would have the template but I'm not sure if I could modificate it has I wish. If this works I will reply my own question and close the post




    After trying this I could not upload the HTML which was exported from the google doc. The error that the google api gives me is: code 400 message: bad request











    share|improve this question



























      1












      1








      1


      1






      I've been implementing a google drive connector into a web application.



      Basically when a known event is triggered in the page it launches a webhook which communicates with the 'drive-connector' in order to generate a document and fill it with some information.



      This 'drive-connector' is a custom PHP which uses the Google Drive API to create folders and files. I am able to create the folders and files and give the files the desired content.



      To give the content to the drive document I use an HTML template (https://developers.google.com/drive/api/v3/manage-uploads) which is allowed by the API, before uploading it I change some variables inside the template with the data that comes from the webhook, all well for now.



      The problem



      I'm able to upload the HTML document, once I replace the variables for the desired data, but It has to be very simple and without much css. When I try to upload the document from a more worked and beautiful template Google Drive doesn't recognize many CSS and it changes the appearence of the document. I can't put a header nor a footer. Many fields are moving from its places and making a mess of the whole document.



      In order to make it easier for me to replace the variables in the template I choosed to use HTML anyways I'm starting to think that would be easier to use a .doc or .odt template ( I would need to use a library in order to do that )



      My question



      Is good to use an HTML document as template for the google drive document? Or should I change the way I am trying to achieve this?



      Thanks in advance



      Observation: Since I don't really have problem with my code I haven't put any line of code, how ever If you need the HTML template to guess if it has any problem, just tell me.



      EDIT 1 -> I've found this: How can developers edit a Google Doc programmatically? Is there a Docs API?



      It is not the answer of my question but seems to have some solutions to my problem. Anyways I don't get much clear in that post, I haven't found the proper documentation so I'm still fighting to get this.



      EDIT 2-> Reading again the documentation I thought that I could make the document firstly in the google drive and then using the API download it as HTML, this way I would have the template but I'm not sure if I could modificate it has I wish. If this works I will reply my own question and close the post




      After trying this I could not upload the HTML which was exported from the google doc. The error that the google api gives me is: code 400 message: bad request











      share|improve this question
















      I've been implementing a google drive connector into a web application.



      Basically when a known event is triggered in the page it launches a webhook which communicates with the 'drive-connector' in order to generate a document and fill it with some information.



      This 'drive-connector' is a custom PHP which uses the Google Drive API to create folders and files. I am able to create the folders and files and give the files the desired content.



      To give the content to the drive document I use an HTML template (https://developers.google.com/drive/api/v3/manage-uploads) which is allowed by the API, before uploading it I change some variables inside the template with the data that comes from the webhook, all well for now.



      The problem



      I'm able to upload the HTML document, once I replace the variables for the desired data, but It has to be very simple and without much css. When I try to upload the document from a more worked and beautiful template Google Drive doesn't recognize many CSS and it changes the appearence of the document. I can't put a header nor a footer. Many fields are moving from its places and making a mess of the whole document.



      In order to make it easier for me to replace the variables in the template I choosed to use HTML anyways I'm starting to think that would be easier to use a .doc or .odt template ( I would need to use a library in order to do that )



      My question



      Is good to use an HTML document as template for the google drive document? Or should I change the way I am trying to achieve this?



      Thanks in advance



      Observation: Since I don't really have problem with my code I haven't put any line of code, how ever If you need the HTML template to guess if it has any problem, just tell me.



      EDIT 1 -> I've found this: How can developers edit a Google Doc programmatically? Is there a Docs API?



      It is not the answer of my question but seems to have some solutions to my problem. Anyways I don't get much clear in that post, I haven't found the proper documentation so I'm still fighting to get this.



      EDIT 2-> Reading again the documentation I thought that I could make the document firstly in the google drive and then using the API download it as HTML, this way I would have the template but I'm not sure if I could modificate it has I wish. If this works I will reply my own question and close the post




      After trying this I could not upload the HTML which was exported from the google doc. The error that the google api gives me is: code 400 message: bad request








      php html google-drive-sdk google-docs google-docs-api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 '18 at 15:47







      Osakr

















      asked Nov 26 '18 at 12:47









      OsakrOsakr

      585117




      585117
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Finally I could find a work around!



          Anyways It is not a very effective and good way of doing it.



          As I explained in my EDIT 2, I tried to download a google drive document created in google drive by hand and export it has HTML, so I had the template in HTML. Then I added my variables for future dynamic replacements and everything works more or less fine.



          I solved the problem of the bad request modifying a bit the document, seems like you cannot have exacly the same document twice in the drive, after changing some lines of code It started to work.



          Anyways I don't feel like this is a definitive and fine way of doing what I want so I will keep the post open for if somebody knows a better way of achieving this.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53481449%2fcreate-google-drive-document-template-from-html-and-css%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Finally I could find a work around!



            Anyways It is not a very effective and good way of doing it.



            As I explained in my EDIT 2, I tried to download a google drive document created in google drive by hand and export it has HTML, so I had the template in HTML. Then I added my variables for future dynamic replacements and everything works more or less fine.



            I solved the problem of the bad request modifying a bit the document, seems like you cannot have exacly the same document twice in the drive, after changing some lines of code It started to work.



            Anyways I don't feel like this is a definitive and fine way of doing what I want so I will keep the post open for if somebody knows a better way of achieving this.






            share|improve this answer




























              2














              Finally I could find a work around!



              Anyways It is not a very effective and good way of doing it.



              As I explained in my EDIT 2, I tried to download a google drive document created in google drive by hand and export it has HTML, so I had the template in HTML. Then I added my variables for future dynamic replacements and everything works more or less fine.



              I solved the problem of the bad request modifying a bit the document, seems like you cannot have exacly the same document twice in the drive, after changing some lines of code It started to work.



              Anyways I don't feel like this is a definitive and fine way of doing what I want so I will keep the post open for if somebody knows a better way of achieving this.






              share|improve this answer


























                2












                2








                2







                Finally I could find a work around!



                Anyways It is not a very effective and good way of doing it.



                As I explained in my EDIT 2, I tried to download a google drive document created in google drive by hand and export it has HTML, so I had the template in HTML. Then I added my variables for future dynamic replacements and everything works more or less fine.



                I solved the problem of the bad request modifying a bit the document, seems like you cannot have exacly the same document twice in the drive, after changing some lines of code It started to work.



                Anyways I don't feel like this is a definitive and fine way of doing what I want so I will keep the post open for if somebody knows a better way of achieving this.






                share|improve this answer













                Finally I could find a work around!



                Anyways It is not a very effective and good way of doing it.



                As I explained in my EDIT 2, I tried to download a google drive document created in google drive by hand and export it has HTML, so I had the template in HTML. Then I added my variables for future dynamic replacements and everything works more or less fine.



                I solved the problem of the bad request modifying a bit the document, seems like you cannot have exacly the same document twice in the drive, after changing some lines of code It started to work.



                Anyways I don't feel like this is a definitive and fine way of doing what I want so I will keep the post open for if somebody knows a better way of achieving this.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 26 '18 at 16:07









                OsakrOsakr

                585117




                585117
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53481449%2fcreate-google-drive-document-template-from-html-and-css%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Homophylophilia

                    Updating UILabel text programmatically using a function

                    Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage