Zoom to fit: PDF Embedded in HTML - html

I am embedding a local pdf file into a simple webpage and I am looking to set the initial zoom to fit to the object size. Here is what I tried but it is not affecting the zoom.
<embed src="filename.pdf?zoom=50" width="575" height="500">
does anyone know how to modify the code so its initial zoom is set to fit the object size.

Bit of a late response but I noticed that this information can be hard to find and haven't found the answer on SO, so here it is.
Try a differnt parameter #view=FitH to force it to fit in the horzontal space and also you need to start the querystring off with a # rather than an & making it:
filename.pdf#view=FitH
What I've noticed it is that this will work if adobe reader is embedded in the browser but chrome will use it's own version of the reader and won't respond in the same way. In my own case, the chrome browser zoomed to fit width by default, so no problem , but Internet Explorer needed the above parameters to ensure the link always opened the pdf page with the correct view setting.
For a full list of available parameters see this doc
EDIT: (lazy mode on)

For me this worked(I wanted to zoom in since the container of my pdf was small):
<embed src="filename.pdf#page=1&zoom=300" width="575" height="500">

This method uses "object", it also has "embed". Either method works:
<div id="pdf">
<object id="pdf_content" width="100%" height="1500px" type="application/pdf" trusted="yes" application="yes" title="Assembly" data="Assembly.pdf?#zoom=100&scrollbar=1&toolbar=1&navpanes=1">
<!-- <embed src="Assembly.pdf" width="100%" height="100%" type="application/x-pdf" trusted="yes" application="yes" title="Assembly">
</embed> -->
<p>System Error - This PDF cannot be displayed, please contact IT.</p>
</object>
</div>

just in case someone need it, in firefox for me it work like this
<iframe src="filename.pdf#zoom=FitH" style="position:absolute;right:0; top:0; bottom:0; width:100%;"></iframe>

Followed #Rich answer, I used view=FitH in my code to view PDF content base64 in Angular as below.
I shared for whom concern about view base64 content PDF file with object tag using Angular framework.
The option for view PDF
this.pdfContent =
URL.createObjectURL(this.b64toBlob(content, 'application/pdf')) +
'#toolbar=0&navpanes=0&scrollbar=0&view=FitH';
Read PDF content from API as
let content = DataHelper.getDataFromAPI();
When click show content button use
showData() {
let content = DataHelper.getDataFromAPI();
this.pdfContent =
URL.createObjectURL(this.b64toBlob(content, 'application/pdf')) +
'#toolbar=0&navpanes=0&scrollbar=0&view=FitH';
this.pdfview.nativeElement.setAttribute('data', this.pdfContent);
}
In HTML file use object tag as
<object #pdfview
[data]=''
type="application/pdf"
width="100%"
height="800px"
>
</object>
Link Angular demo https://stackblitz.com/edit/angular-ivy-tdmieb

Bit late response to this question, however I do have something to add that might be useful for others.
If you make use of an iFrame and set the pdf file path to the src, it will load zoomed out to 100%, which the equivalence of FitH

Use iframe tag do display pdf file with zoom fit
<iframe src="filename.pdf" width="" height="" border="0"></iframe>

This works fine for me
<embed src=".file-name.pdf#zoom=FitH" width="100%" height="1930px" />

Related

Embedding Excel file with iFrame not working correctly

I am using iframe to embed an Excel file into a HTM page using the Microsoft OneDrive embed function, and it will display the excel file, but it doesn't embed it, it makes the entire page the excel file.
So it takes over the entire page, I lose the sidebar and toolbar of my site that has the navigation.
I tried containing it within a div and apply class styles to both the div and the iframe, which is what I used for my PDFs that I embed that work fine, but it still did not restrict the excel file to an embedded window.
This is what I am using for the excel iframe:
<body>
<iframe width="100%" height="100%" frameborder="0" scrolling="no" src="https://onedrive.live.com/embed?resid=7CDAFECF25AB92FC%21110&authkey=%21AGaGmMnPaiFZ0Ew&em=2">
</iframe>
</body>
And this is what I use for my PDF iframe:
<body>
<div class="container"><iframe class="responsive-iframe" src="PS-U-A150FUI.pdf"></iframe>
</div>
</body>
EDIT: Here are images to better show the issue, first image is a PDF correctly imbedded within the webpage.
Second is the excel doc that has overtaken the webpage.
PDF Embed
Excel Embed
Your code reads:
<iframe width="100%" height="100%" frameborder="0" scrolling="no" src="https://onedrive.live.com/embed?resid=7CDAFECF25AB92FC%21110&authkey=%21AGaGmMnPaiFZ0Ew&em=2">
</iframe>
You have used 100% width and 100% width in your HTML. So the iframe takes up the complete screen.
Take an example: you need the frame to be 500px wide and 700px long, then you could have used the width=“500px”
and the height=“700px” attributes in your iframe or used the following css:
iframe {
width: 500px;
height: 700px;
}
What basically I want to say is, that you should use smaller pixel-values/percentages for the iframe.

html object css for resizing

I need to resize pdf object (ie to make control in the lower right corner pulled by mouse)
It doesnt react on my line resize='both'.
What should i write in css?
Heres my code:
<object data='http://aspirant.beget.tech/upload/images/1.Pdf'
type='application/pdf'
width='100%'
height='100%'
resize='both'>
<p>This browser does not support inline PDFs. Please download the PDF to view it: Download PDF</p>
</object>
It is easier if you wrap your object element to div sample answer

How to upload image in selenium webdriver.. element is not visible

ff.findElementByxpath(//object[# id='slPlugin2']).click();
is not recognizing the element.
And also suggest me the way to upload media through webdriver
<table class="imgTable photoTable" cellspacing="0">
<div id="fileUploadControl404" class="fileUpload t-toolbar t-grid-toolbar t-grid-top">
<object id="slPlugin2" width="117" height="32" data="data:application/x-silverlight," type="application/x-silverlight">
<param value="/LMM/ClientBin/FileUpload.xap" name="source">
<param value="Url =https://lmmwipqa.blob.core.windows.net/uploads?se=2013-12-28T07%3A18%3A43Z&sr=c&sp=w&sig=fxuPdwl4huKRISO%2BCPdZIQxh0i5cdnGjWKO8okj2O34%3D, Parent =fileUploadControl404, Caption =Add Photo" name="initParams">
</object>
</div>
//object[# id='slPlugin2']
The above parameter should be within double quotes,i.e., a string should be passed as parameter to findElementByXPath().
The required statement can be rewritten as follows :
ff.findElementByXPath("//object[#id='slPlugin2']").click();
With respect to clicking on invisible elements, the following statement can be used :
(Note : This assumes the page has jQuery on it)
((JavascriptExecutor)driver).executeScript("$('selector_of_element').click();");
For file upload you can refer this.
I think, ff.findElementById("slPlugin2") would be more shorter way to find the element,
but, anyway unfortunatelly, WebDriver will be not be able to handle the elements
inside the Silverlight embeded app.
I'd recomend to get the parent div: ff.findElementById("fileUploadControl404")
Get its coordinates with .getLocation();
Use Java Robot
or Sikuli in order to manipulate the embeded control.

Iframe is giving blank page

I am using iframe in jsp page.
<iframe frameborder="1" src="view/jsp/refreshChat.jsp" STYLE='width:20%;' />
But when I run that page its gives a blank page.
This is an example of an iframe code:
<iframe src="page_to_show_inside_iframe.jsp" style="width:100%; height:250px;">
<p>Text to show in browsers that don't support iframes.</p>
</iframe>
Perhaps you're lacking height value.
Also, be sure the value for src attribute is correctly referenced, ie. relative path is built OK ( if your parent page URL is http://localhost:8080/mysite/myparentpage.jsp try to load your child page pasting src value instead your parent page's name, http://localhost:8080/mysite/view/jsp/refreshChat.jsp , test this in a new window or tab)
Check if src="view/jsp/refreshChat.jsp" is proper. From what location You use this?
DO not forget to add http:// to your web url. Also, avoid localhost. Use the IP address.

How to Disable AutoLoad for <embed>?

I embedded a default media player into my webpage with the following html
<object height="20" width="200">
<embed src="url to music" autostart="false" loop="false" height="20" width="200">
</object>
Everytime I go to the website, this object automatically downloads the music. How can I disable the autodownload? I want it to load only when someone clicks on the play button.
I've been looking around today, and I see no way to instruct the browser to do exactly that.
The best way I can think of is instead of the <object ...>, you display an image which looks like the player, then you add an onclick property to the image, and you use javascript to replace the image with the real object. Something like :
<div><img src="player.png" onclick="this.parentNode.innerHTML = '<object height=\'20\' width=\'200\'> <embed src=\'url-to-music\' autostart=\'false\' loop=\'false\' height=\'20\' width=\'200\'> </object>'"></div>
I should add that you have to keep the <div> around the image (or put a <span>, or whatever tag you see fit) because the onclick action replaces parentNode.innerHTML, that is, the HTML contained in the parent, which in this case, is the image.