Dynamic PDF file size on MVC page

Sylvain C. asked on December 11, 2019 06:18

Hi, I have a generic page type with just a title field and a rich editor field. Editors can use it to create pages and use this rich editor field to add text, images, link, etc...

PDF files stored as pages under the CMS.File pagetype can then be linked into this page described above. I can do it now using the link button in the WYSIWYG editor.
However,I would need to display the size of the PDF automatically next to the title.

In portal engine, I saw some good example using transformations but how can I do it in MVC environment? It would need to be a dynamic feed so if the PDF is updated, its size will be reflected in the pages pointing to it.

What would be the best option to do so?

Thank you

Sylvain

Recent Answers


Trevor Fayas answered on December 12, 2019 15:34

Similar to the "Custom Transformation" example you saw, you can do the same really in MVC. Except in your View rendering it out, it would look something like this:

@MyFileHelper.GetFileSize(ThePdf.Guid)

assuming of course you created a MyFileHelper static class with a GetFileSize that took the PDF File guid and did the code to get the size. I can assist with the logic if you need, but the primary question was just "how do i render a custom value in MVC"

0 votesVote for this answer Mark as a Correct answer

Sylvain C. answered on December 24, 2019 00:31

Hello @Trevor-Fayas,

Sorry for the delay. I would be really interested if you could give some directions on how to insert customized tags into the HTML which would then be processed by my MVC project. Ideally, I would like to have a small widget which would help generating this kind of link (thepdf.guid) as the editor won't be able to add the GUID by himself and then get these tags being processed while being displayed on the view.

I saw for example, that in the CKEditor, there is a widget which is adding a Youtube video by adding customized tags such as {^widget|(name)YouTubeVideo|(... in HTML. I would like to do the same for PDFs where editor would run a small widget to choose them, then special tags being added in the HTML with the GUID and then having the code to process it front-end.

Hope it is clear enough

Sylvain

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on December 24, 2019 02:56

This isn't really very easy, there aren't inline widgets anymore. It may be possible to create some custom plugin for a text editor, then run the markup through some text filter, like if you could generate a macro method code and then create an html extension method that would render the macros, that may be doable (be sure if you use Kentico macros to run them with pubic user permissions so no one could run elevated commands).

But this would be a lot of work. Sorry but no real easy way to do it right now.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.