-1

How do I print a pdf of this url in an iframe using a html print button

http://assessormap.co.la.ca.us/Geocortex/Essentials/REST/sites/PAIS/VirtualDirectory/AssessorMaps/ViewMap.html?val=8734-031?

I tried two solutions using the answers from these threads:

  1. Print pdf from iframe

  2. Print PDF directly from JavaScript

My html is an iframe with the pdf url above and my js looks like:

<embed
type="application/pdf"
src="the url that is above. too long to fit here"
id="pdfDocument"
width="100%"
height="100%" />
<button id="printButton" onclick="javascript:printPage()"   
>

My js:

 function printPage(documentId) {
var doc = document.getElementById('pdfDocument');
 //Wait until PDF is ready to print    
if (typeof doc.print === 'undefined') {    
setTimeout(function(){printPage(documentId);}, 1000);
} else {
doc.print();
}
}

I have not had any luck. The button is non-responsive. Something must be wrong with the js. They have a printjs library. Maybe that is a better route. Any suggestions appreciated. Thanks.

brandon p
  • 29
  • 5
  • The posted question does not appear to include [any attempt](https://idownvotedbecau.se/noattempt/) at all to solve the problem. StackOverflow expects you to [try to solve your own problem first](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users), as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific problem you're having in a [mcve]. For more information, please see [ask] and take the [tour]. – Blue Mar 16 '19 at 01:16
  • Hey Franker.... I revised the question – brandon p Mar 16 '19 at 02:26
  • Saying "I tried", and linking 2 solutions, **without showing your actual attempt**, is no help. – Blue Mar 16 '19 at 02:47
  • I have tried several attempts. This is the current. – brandon p Mar 16 '19 at 03:42
  • Where are you calling it? This is the last time I'm going to try and ask for more clarification. Add a [mcve]. Tell us what you tried, tell us why it's not working. Any error message? – Blue Mar 16 '19 at 03:49
  • Hey Franker. Added a bit more. – brandon p Mar 16 '19 at 06:42
  • Your print page function takes a `documentId` variable, which you don't pass in your button. I think you may be looking for a developer, not help from SO. – Blue Mar 16 '19 at 14:02
  • I know that it is incorrect because it is not passing into the button. That is why posted to begin with. I found the example on stack that way. You are telling me what I already know. I have passed the variable properly on my PC still to no avail. Have you even gone to the other threads? – brandon p Mar 16 '19 at 21:52

1 Answers1

1

The URL you have is not returning a PDF document. It does instead return a HTML document with the PDF embedded in it. Therefore, you cannot print the document properly using an iframe or the Print.js library. To accomplish that, you would need to have a URL that returns the actual PDF document.

crabbly
  • 5,106
  • 1
  • 23
  • 46
  • http://maps.assessor.lacounty.gov/Geocortex/Essentials/REST/sites/PAIS/Resources/ParcelMap?f=file&MapId=8563-010-. This url is of the pdf. What is the best way to print it within an iframe using a button outside of the iframe on my page? – brandon p Apr 02 '19 at 15:59
  • This URL returns with a 307 redirect to another HTML page. Please check your request headers. You need a URL that returns the PDF document (application/pdf). – crabbly Apr 02 '19 at 19:51
  • Are you sure? The source showed as applicant/pdf when I checked – brandon p Apr 03 '19 at 14:42
  • Yes, I'm sure. Check it again. – crabbly Apr 03 '19 at 21:57