Jump to content
Larry Ullman's Book Forums

How To Embed A Pdf Onto A Page


Recommended Posts

I want to be able to call a specific PDF and embed it onto a page using a variable in PHP.

 

I have 50 PDF files named as the 50 US States IE: Akabama.pdf, Alaska.pdf, etc.

 

I also have 50 pages, each titled as one of the 50 states IE: Alabama, Alaska, etc.

 

What I am trying to accomplish is when the visitor opens (for example) the "Alabama" page, she is served with the Alabama.pdf embeded onto the page (probably using google.docs)

 

So far, all I have been able to accomplish is to create the variable:

 

 

<?php

$pdf_title= get_the_title();

 

?>

 

What I want to do is embed http:www.thissite.com/$pdf_title.pdf

 

I've searched through the book, and done a few Google searches but am still rather clueless. Please forgive me, as I am just beginning to learn PHP, but I am a very fast learner.

 

Thanks for any tips and guidance.

 

Pam

Link to comment
Share on other sites

Pampurrs, we have no problem helping you, but the best way to learn may be to first attempt to go through the book by yourself, asking questions along the way.

If you read through the end of Chapter 11: Web Application Development, I think you'll have enough to do what you want to do. And if you're still stuck then, we'll be more than happy to help.

Link to comment
Share on other sites

Like I said, I searched though the book and didn't find anything. Thank you for pointing out which chapter to read, which was all I was asking for. As I pointed out,all I need is a little guidance and I can learn on my own.

 

BTW, I only got this book a couple of days ago and am devouring it rabidly. However, this is a project that I need to accomplish ASAP, which means I need to fast track to a solution. That was the only reason I posted the question. Sorry you found it so annoying.

 

Pam

Link to comment
Share on other sites

There is nothing in Chapter 11 or anywhere in this book about embedding a pdf. In fact, I searched "pdf" and came up with zero results. I also searched "embed" and didn't find anything that answers my question.

 

Is what I am trying to do impossible? Someone please tell me so I don't waste my time (or annoy anyone).

 

Thanks

 

Pam

Link to comment
Share on other sites

You don't need to necessarily embed the PDF, you can just get the browser to display the PDF file inline. You just need to prepare the browser to display the PDF using a few header() calls. However, some browsers still may request the user downloads it.

Link to comment
Share on other sites

Actually, with a little more sleuthing around, and a bit of help from a friend, I got it figured out. It seems there isn't a way to embed a PDF with PHP, but it can be done by combining PHP with OBJECT.

 

Here is what I came up with, and it works! B)

 

 

<?php

$url = "http://www.bkdiy.com/files/exemptions/";

$PDF_title = get_the_title();

?>

 

<object width="950" height="1200" type="application/pdf" data="<?php echo $url '. $PDF_title;?>.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0" id="pdf_content">

<p>Error: You are unable to view PDF files.</p>

</object>

Link to comment
Share on other sites

Pampurrs, I didn't say that the exact solution you wanted was in the book. I said that if you read everything through the end of Chapter 11, you'd probably have enough knowledge to figure things out on your own.

I simple Google search for "PHP display PDF" (without the quotes) turns up plenty of relevant results, namely the following:

http://stackoverflow.com/questions/4679756/show-a-pdf-files-in-users-browser-via-php-perl

 

In my mind though, it isn't a matter of whether we can tell you how to do what you want to do (we know exactly how to do what you want to do), it is a matter of whether the required code would make sense to you or not, which is why I recommended reading partway through the book first, and then discussing the matter if you still weren't sure what to do. Basically, I wanted you to figure it out on your own, if possible, as opposed to us spoon-feeding you the answer. (Also, I wasn't aware of the fact that you so urgently needed to achieve what you're after, so I apologize for that.)

 

Please note that while your method of displaying PDFs by using an object element in the HTML markup is possible, you'll get much more universal browser support by modifying the headers and displaying the PDF file that way, as both Jonathon and the above link recommend.

 

Please don't take my advice the wrong way, Pampurrs. We want to help, but we prefer to offer guidance and having meaningful discussions that lead to the person figuring things out on their own, as opposed to someone new suddenly coming to the forums and saying, "I have an urgent project that I need to get done now! Please tell me how to do this." Hopefully, you can see where we're coming from (after all, we're offering all this advice for free and taking time out of our schedules to help).

Link to comment
Share on other sites

Thanks Jonathon and Hartley. At least I got the pages working for now, albeit not the ideal solution. I am in the midst of reading this PHP book cover to cover, as well as another PHP book simultaneously. I will probably purchase an advanced PHP book after I have devoured these two. I did the same crash course several years ago when I was avidly involved with Cold Fusion. I am a knowledge and information sponge, I love to learn knew things and become the best at what I do.

 

I may have come across as asking the forum to provide me with a solution to my problem, for which I apologize. I like to learn by example so often times a small snippet of code can provide a clue as to what direction to go.

 

Cheers!

 

Pam

Link to comment
Share on other sites

Noted. Also, thank you for explaining your approach to learning PHP.

It sounds like the right way to do things.

 

And just for the record, I (we) have no problem helping you out. It's just that the regulars on this forum have seen so many people come and go where their very first post is always, "HELP! I have a deadline for this complex project that's way over my head!"

As such, I'm a bit wary about that sort of thing, that's all.

 

Anyway, I'll be more careful when responding to your posts in the future.

Please don't be afraid to ask more questions.

Link to comment
Share on other sites

 Share

×
×
  • Create New...