A click on the PDF opens a new tab with the PDF file. Unfortunately this tab is outside of my website, which like many of us probably do not want to get your users to "leave" your site.
The question now is how can I program it in such a way that when you click on the link (href) it open the pdf in a new page that is for example a subpage of my project page that dispaly the first pdf and then for example a second pdf.
The only thing I could think of is working with child pages, but then this will create more overhead/ burden to maintain instead of using the media picker in one page....
Though I'm more searching for a way that e.g. you list your PDF files neatly next to each other and when you click on one PDF, a new page opens on your site with the selected PDF.
Hmm not sure that will work on my Umbraco site.
I dynamically load in the PDFs that are in a certain folder that is bound to a project.
e.g.
Documents (PDFs) are saved under media -> Projects -> project 1 -> Documents.
Then I have a media picker that I use to select that "Documents" folder.
My template has this call
@* Show document(s) if any *@
@if(Model.Content.HasValue("documents"))
{
<div class="col-xs-12 col-sm-12 blog-content">
@Umbraco.RenderMacro("Documents", new {mediaIds = @Model.Content.GetPropertyValue("documents") })
</div>
}
Which in turn does the following
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
Macro to display a gallery of images from the Media section.
Works with either a 'Single Media Picker' or a 'Multiple Media Picker' macro parameter (see below).
How it works:
- Confirm the macro parameter has been passed in with a value
- Loop through all the media Ids passed in (might be a single item, might be many)
- Display any individual images, as well as any folders of images
Macro Parameters To Create, for this macro to work:
Alias:mediaIds Name:Select folders and/or images Type: Multiple Media Picker
Type: (note: You can use a Single Media Picker if that's more appropriate to your needs)
*@
@{
var mediaIds = Model.MacroParameters["mediaIds"] as string;
var fileCount = 0;
var multiple = "False";
}
@if (mediaIds != null)
{
@* Change H1 if multiple files are present *@
if(multiple == "false")
{
<h1 id="comments_title"><i class="far fa-file-pdf"></i> Document</h1>
}
else
{
<h1 id="comments_title"><i class="far fa-file-pdf"></i> Documents</h1>
}
<ul class="thumbnails" id="image_gallery_files">
@* Go over each mediaID in the list *@
@foreach (var mediaId in mediaIds.Split(','))
{
var media = Umbraco.TypedMedia(mediaId);
@* Media var has value *@
if (media.Children != null && media.Children.Any())
{
foreach(var file in media.Children)
{
<li>
<center>
<a href="@file.Url" class="ilightbox" target="_blank">
<img class="span2" class="img-responsive img-blog" src="@file.Url?Format=jpg&Width=200&Height=200" alt="@String.Format("{0}",Path.GetFileNameWithoutExtension(@file.Name))"/>
</a>
<br />
<a href="@file.Url" download><button type="button" class="btn btn-secondary"><i class="fas fa-download"></i> Download</button></a>
</center>
</li>
@* Increment the file counter*@
fileCount++;
@* Check if multiple files are present *@
if(@fileCount > 0)
{
multiple += "True";
}
else
{
multiple += "False";
}
}
}
@* No media folder was selected *@
else
{
<p>No document folder selected!</p>
}
}
</ul>
}
else
{
<p>Nothing loaded in</p>
}
Perhaps I can reroute the URL when you click on the image or download button to a new page that display the PDF as a subpage of my project?
Open PDF in a new page
So I have some projects that contain PDF files. I already have created the logic to fetch them from my content and list them in my views.
e.g. https://www.don-zalmrol.be/projects/philips-b6x12a/
A click on the PDF opens a new tab with the PDF file. Unfortunately this tab is outside of my website, which like many of us probably do not want to get your users to "leave" your site.
The question now is how can I program it in such a way that when you click on the link (href) it open the pdf in a new page that is for example a subpage of my project page that dispaly the first pdf and then for example a second pdf.
No one?
The only thing I could think of is working with child pages, but then this will create more overhead/ burden to maintain instead of using the media picker in one page....
No one has any idea how I might be able to tackle this?
Hi Laurens,
maybe this thread is helpfull:
https://stackoverflow.com/questions/6439634/view-pdf-as-part-of-the-page
Hope this helps!
/Michaël
Thx Michaël!
I'll look into it.
Though I'm more searching for a way that e.g. you list your PDF files neatly next to each other and when you click on one PDF, a new page opens on your site with the selected PDF.
Hi Laurens,
what you also can do is create a Pdf Viewer page in your content structure which allows a custom model that contains a property called PdfPath.
This property then you can set with the full path of the PDF in your Media Library and call the Pdf Viewer page.
Then in the view of this page you catch the path of the pdf file and put it into a iframe or something else to display it inline with the website.
Hope this helps!
/Michaël
Hmm not sure that will work on my Umbraco site. I dynamically load in the PDFs that are in a certain folder that is bound to a project.
e.g.
Documents (PDFs) are saved under media -> Projects -> project 1 -> Documents.
Then I have a media picker that I use to select that "Documents" folder. My template has this call
Which in turn does the following
Perhaps I can reroute the URL when you click on the image or download button to a new page that display the PDF as a subpage of my project?
Forgot to update this post, for those who are searching for the same thing, you can do this by using a modal.
is working on a reply...