Printing the pdf version from the files showed in the iframe content

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MIkersson
    New Member
    • Mar 2010
    • 11

    #1

    Printing the pdf version from the files showed in the iframe content

    Hello everybody!

    I have a page index.html with a iframe that contains a photo "001.jpg" and what I need to do is to print the "001,pdf" version of that photo stored in a pdf/ folder

    HOW should I do that with JavaScript? Im not a programmer I just need to get some rules then I can make it works.

    Thank you verymuch!
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you cannot directly print but you might use a hidden iframe ... load the corresponding pdf to it by setting the src-attrib ... and then use the window print method to call the print dialog ...

    kind regards

    Comment

    • MIkersson
      New Member
      • Mar 2010
      • 11

      #3
      Interesting method, just that I dont know how to do that

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        what do you want to improve there? :)

        you replaced 'improve' with 'do' ... so with what would you have problems?

        Comment

        • MIkersson
          New Member
          • Mar 2010
          • 11

          #5
          Onclik open and print pdf

          Hello everybody!

          I have a link
          Code:
          <p><a href="pdf/arm029.pdf"><span class="text">Board of Directors</span></a></p>
          What I wish to get after to click on the link is rather than just show the pdf, to can SHOW AND PRINT at same time the pdf

          pdf/arm029.pdf

          I hope you get what I mean: show and print a PDF onCLick the link or the thumbnail.

          Thank you

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            threads merged ... don't multipost questions and keep everything related to one issue in ONE thread ...

            MOD

            Comment

            • MIkersson
              New Member
              • Mar 2010
              • 11

              #7
              Hello, it was a mistake. Anyway, maybe I can get the proper answer thorugh that :)

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                there is already an answer up there ... you need to explain with what you have problems ... nobody will feed you with the entire solution here without seeing that you put any effort in it ...

                and btw.: it is not possible to print a pdf directly with javascript ... you would need to implement a workaround like the mentioned one ...

                Comment

                • MIkersson
                  New Member
                  • Mar 2010
                  • 11

                  #9
                  Hello. Im not a programmer, Im a fine artist and web designer, interested in JavaScript and to can edit some code until I can start some complementary studies about it,
                  Im working day and night looking for some solution about what I have asked and if my effort is not good enough Im sorry, but I dont use to ask without previously look around or google it for a while.
                  If you think it have not been searching enough or made an effort, then dont botter to spend your time for write any response.

                  Anyway I apreciate you light my mind with some details.

                  Have a good day

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    you need to show! that ... nobody knows what you have done or what you think unless you express that here ... i'm not saying that you didn't do anything ... but i cannot see what you have done ... and if you just want a copy and paste solution ... you are wrong here ... but in case you would be open to start to work together then we could start to implement it together ... but just telling - i don't know how to do it - doesn't tell me anything ... because then i don't know where to start ...

                    Comment

                    • MIkersson
                      New Member
                      • Mar 2010
                      • 11

                      #11
                      ok, I have:
                      Code:
                      <html>
                      <head>
                      <title>PDF to print.</title>
                      <script language="Javascript" src="../js/scripting.js"></script>
                      <script type="text/javascript"><script type="text/javascript">
                        function PrintFrame(xFile){
                          parent.iframePDF.location.href = xFile;
                          document.getElementById("spanMess").style.display="block";
                          parent.iframePDF.onload = new function(){
                            setTimeout("parent.iframePDF.print();
                            parent.document.getElementById('spanMess').style.display='none';",5000);
                          }
                        }
                      </head>
                      <body>
                      <div id="container">
                      	<div id="div_header"> 
                       		 <div class="navBar">    <p><a href="pdf/arm029.pdf"><span class="text">Board of Directors</span></a></p>
                      		</div>
                        	</div>
                      
                      	<div id="div_content">
                      	 	 <iframe id="iframeContent" name="iframeContent" height="1114" width="100%" frameborder="0" scrolling="no"></iframe>
                      		 <iframe id="iframePDF" src="about:blank" style="display:none"></iframe>
                      	</div>
                      
                      	<div id="footer"> 
                      	</div>
                      </div>
                      </body>
                      </html>
                      Where
                      Code:
                      <p><a href="pdf/arm029.pdf"><span class="text">Board of Directors</span></a></p>
                      is the link to print a PDF hidden in the "iframePDF" :

                      The javaScript code that I post here do not works at all probably because its an old solution since 2005.

                      I created the hidden "iframePDF" because the page will show a photo arm001.jpg
                      Code:
                      <iframe id="iframeContent" name="iframeContent" height="1114" width="100%" frameborder="0" scrolling="no"></iframe>
                      that everybody can see, but for print, I need the arm001.pdf file
                      Code:
                      <iframe id="iframePDF" src="about:blank" style="display:none"></iframe>
                      its printed rather than the JPG.

                      I have all the funtions done and working. I just need to print the PDF from the hidden iframe.
                      All my other JavaScrirpt functions are in
                      Code:
                      <script language="Javascript" src="../js/scripting.js"></script>
                      file because are too long.

                      Thank you
                      Last edited by gits; Apr 7 '10, 01:29 PM. Reason: fix quote to code tags

                      Comment

                      • gits
                        Recognized Expert Moderator Expert
                        • May 2007
                        • 5390

                        #12
                        first you might notice that the PrintFrame method is not included correctly in script-tags. there are two opening tags in line 5 but closing tags are missing.

                        next ... the iframe has an id ... so the function should look more like this:

                        Code:
                        function PrintFrame( xFile ) {
                            var f = document.getElementById('iframePDF');
                            f.src = xFile;
                        
                            f.onload = function() {
                                f.print();
                            }
                        }

                        Comment

                        • MIkersson
                          New Member
                          • Mar 2010
                          • 11

                          #13
                          Still dont works

                          Thank you. The missed tags are ok in my end, it was a mistake to copy an paste.

                          I replaced the function using yours but still dont works with the link I provided in the menu bar.

                          Ok, Im done with this. I'll look for a non JS function


                          Thank yo for the support.

                          Comment

                          • gits
                            Recognized Expert Moderator Expert
                            • May 2007
                            • 5390

                            #14
                            as you wish ... probably the line 6 should be:

                            Code:
                            f.contentWindow.print();
                            and there might be a mechanism needed that ensures that the frame is fully loaded before printing ... so since you just gave up ... i'm out of this from here ...

                            regards

                            Comment

                            Working...