Create Google Drive Document template from HTML and CSS - php

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

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.

Related

how to fill in excel table from PHP

I need some library or good documentation of xlsx files for writing out xls files from website. all I need to do is fill in content into predefined and styled table. I have considered writing everything directly from php but could't get hang of merging cells and if I could it would be a hell writing code for changing any style into a document instead its much better if I have predefined file uploaded and then just fill in.
Please redirect me or help me find some proper documentation.
Project is in early stage and can consider switching to other language like Node.js if it makes this part super easy but trying to keep it low profile prefer using PHP so i'm open to all ideas.
Thanks in advance to everyone.
PS. this is my first question on stackoverflow
Kindly do a Google search before posting questions like this. But answering your question, PHPExcel is a nice place to start. Just go through their documentation.

how do i display pdf in html (responsive/crossbrowser solution)

i need to display a pdf on the website. i've tried many ways but none of it worked for me.
let me explain what i've tried and why this is not ok for me.
i tried to insert pdf into html with <object> and <embed> tags. its ok if client browser has flash. but android phones don't have it so this is not a solution. plus iphone streching pdf so it is not readable.
then i tried to use just an <iframe> element. works fine only if browser has pdf plugin. in other cases browser starts file downloading. so this is not a solution too.
then i tried to use https://docs.google.com/gview?embedded=true&url=myfile.pdf. well and here i got troubles because there is some bug in in google docs because file displays only one in for times. the rest attempts ended with error code 200 from google. so as you already understood this is not a solution too.
then i tried to download php libs which should convert pdf to html (or image) but none of them worked beacuse i'm not that good at php and sometimes it asked to install third party libs so at this point i've failed too.
so now i'm stuck. i need to do something to display pdf on the page. i need some crossbrowser/responsive solution. it would be great if you help me to find some service like https://docs.google.com/gview which is gonna work without bugs or suggest any other solution. may be some small php lib with good documentation.
any help appriciated!
You can achieve by using PDF.js
https://github.com/mozilla/pdf.js/
for usage you can check this example http://mozilla.github.io/pdf.js/examples/index.html#interactive-examples.

How to embed Neo4j Graph in a webpage ?

I have been trying to embed the Neo4j Graphs that I am able to see in the Neo4j browser, in a web application.
I was initially taking reference from this website.
https://github.com/neo4j-examples/movies-php-neoclient
and
http://neo4j.com/developer/example-project/#_example_project_description
These github examples don't seem to run. Can someone help me with this.
Thanks
You didn't clearly explain the problem you're having.
Anyway, this file static/movies.cypher in the source folder of the Github repo has been changed from this to a mere 15 line code. But that has made it inconsistent with the other files. So basically yeah, the project is broken.
Your page must be looking blank like this:
Now you can copy-paste the contents from the link into your local static/movies.cypher file and it should look similar to this site.
Alternatively, you can replace Actor with Person and ACTS_IN with ACTED_IN in that file and you'll get a smaller six node graph instead.
You might need these two links too:
http://localhost:8080/reset
This will delete the existing graph and try to re-import it.
You'll need to use it after everytime you modify the static/movies.cypher file.
http://localhost:8080/import
This will import the statics/movies.cypher and execute it.
So basically it'll re-create the graph.

Script I can buy to display attachments inline like slideshare

Are there any scripts that I can buy to display pdf, ppt, doc attachments on my site - inline, so users don't need to download them to view it.
I run a knowledgebase which contains various documents uploaded by users - so trying to find a way to make it easier for them to view the files before download.
Google document viewer may work - but the terms of service does not allow us to build a preview application like slideshare. Anything else anyone has used to do something like this?
Does your site run on wordpress ?
If yes,you can use the google doc embedder plugin.
I don't think there is presently any straightforward way to display, say, a .ppt in a browser; other than of course, converting it so as to be suitable for a flash player, or html5 player, as is SlideShare's case. I might however, be wrong on this.
SlideShare has a whole lot of document conversion architecture built on Amazon EC2 for the same. [Refer to this post on the SlideShare Engineering Blog].
Alternatively, there is Zoho Viewer - which is going to close down by the end of 2012. There was also PdfMeNot, but I don't think it exists anymore

Insert data into PDF, filled in an online form, on submit action

First of all my apologies to all the people who think this question is a repeated one or they find a similar question to this.
I am working on a project in which I have an online form and some PDFs stored on the server.
Functionality
On the submit action I have to get the data from the form, fill it to the copy of PDF and finally download it.
Approach
I followed these steps to achieve this functionality:
Converted the pdfs to html with this http://www.pdfdownload.org/free-pdf-to-html.aspx online tool.
Embedded the html with form variables and regenerated the PDFs with this library / dompdf library.
Problem
The approach is a brute force one as the html generated are far away from the real ones. So lot of effort is wasted in adjusting the html.
The process is so slow and not reliable as most of the time I get memory error or some other issues.
I need to to automate this process. What I have found through searching is I should create an FDF file that contains my variable and pass it to the PDF using some library and then download it.
I am able to create the FDF file but missing any library in PHP (I found one in JAVA) that I can use to create the PDF and download it. One library that I found is pdf tool kit but that is a command line tool and I am not able to use it on the server at run time and download the PDF file.
Anybody having done this before please help.
(Sorry for this long post)
Thanks,
Madhup
Check out FPDI. It allows you to load some existing PDF, draw on it programatically, and output a new PDF. Which, if I read your question right, is what you're trying to do.
There's some example code here.

Categories