Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google docs iframe - change padding

I have an embedded iframe that has been created publishing a google doc. The iframe automatically applies a large padding to its body resulting in the text being a very narrow and ugly column. I have to change that.

I have tried to create a custom directive:

app.directive('iframeWithStyle', [function(){
return {
    restrict: 'A',
    link: function(scope, element, attrs){
        element.on('load', function(){
               var iframe = element[0];
               var grabbedElement = iframe.querySelector("body");
               // -> grabbedElement is null here
        });
    }
}}]);

which is applied to:

<iframe iframe-with-style
        src="https://docs.google.com/document/d/somethingABC123/pub?embedded=true">
</iframe>

but iframe.querySelector returns null and iframe.contentWindow.document results, as expected, in

Uncaught DOMException: Blocked a frame with origin "http://localhost:8100" from accessing a cross-origin frame.

I have looked at a workaround but I have a feeling that it's overkill (ex: safe cross-communication with messages).

I tried to fight the padding with some css applied to what I can reach. For example:

iframe {
  padding: 0px !important;
  margin-left: -50px;
  margin-right: 50px;
}

css applied to the body of the iframe seems to be simply ignored.

Once upon a time there were some convenience attributes, such as marginwidth. Tried that too. I was also wondering if google does not offer some "sugar" but googling around did not help.

Note: it really does not have to be an iframe, but I need to show that formatted gdoc within the app in a way that it is readable; and for that I need to reduce that padding.


Adding a plunker: https://plnkr.co/edit/XIkgPe7ecLyFfhq1Q3Sv?p=preview

like image 242
NoIdeaHowToFixThis Avatar asked Jun 13 '17 10:06

NoIdeaHowToFixThis


People also ask

Can you put iframe in Google Docs?

Embedding iFrames from Google Docs or Google Sheets 1. Copy the Google Doc or Sheets link from the URL bar. 2. Start a new iFrame block in the Card.

Why can't I change the margins in Google Docs?

Unfortunately, Android doesn't allow its users to change their margins in Google Docs. However, you can make many other changes to your Google Docs files on an Android device to adjust the look of your documents. For instance, you can modify the page color, size, or orientation using your Android phone.


1 Answers

Change the last portion of your url from true to false.

https://docs.google.com/document/d/1s2nOQZ39dKD-hsmox5twmmKKkuXzOopT1eXFbMh5DeE/pub?embedded=false

The demo includes use of all of the embedded elements:

<iframe>, <embed>, and <object>

Plunker

When you set embedded=true Google server will add a class named .c1 to the <body> of the content inside the <iframe>

.c1 {
    background-color: rgb(255, 255, 255);
    max-width: 468pt;
    padding: 72pt 72pt 72pt 72pt;
 }

That's just plain reckless of Google if you ask me. I suggest that you set padding on the content itself and set embedded=false.

like image 72
zer00ne Avatar answered Oct 07 '22 17:10

zer00ne