MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

PDF Implementation



  • Hey guys,
    I have been looking pretty much everywhere by now for a module to embed pdf files and could not find anything except that some people say it ain’t possible what ain’t right.
    I know it’s possible since I somehow got it to work for a short time but I’m not a coder so I don’r really know on how to make a module…

    The purpose of it:
    I need the screen to always pull the latest PDF file from a google drive folder each time it boots up. No Scrolling, no user interface, no controls needed.

    Here are some Infos that I found:
    PDF HTML embedding:
    https://www.w3docs.com/tools/code-editor/1087

    I don’t remember where, but I recently found a few libaries in node for displaying PDF in electron.

    Is there any talented Coder who would be so kind to help me, and many others who have been looking for it, to help?

    Thx guys 😉


  • Module Developer

    Your source already shows implementation of an iframe.
    So I would use MMM-iframe 🙂
    https://github.com/alberttwong/MMM-iFrame
    Can apparently show “any content”



  • @JohnDelta

    You could also convert the PDF to JPG or similar with the ‘convert’ utility from imagemagick and then just display it as an image.



  • MMM-Iframe has been overhauled and become MMM-SmartWebDisplay.

    This module allows one to point to a website URL (one or multiple-that are displayed upon a time interval)

    What one could do is install that module and then point it to the address of the URL with a static file name.

    Then create a simple batch script that changes the name of the latest .pdf file to the .pdf file named in the url that is within the config.js file under the MMM-SmartWebDisplay settings.

    This batch file would rename the .pdf file locally on the hard drive of a PC and then automatically FTP the file up to a server. Google Drive allows ftp right?

    Want to send me a link to the .pdf file so I can try to display it within MMM-SmartDisplay?

    You can PM if that is needed as well.



  • @ember1205 so I’ve tried. But that’s just a few unnecessary steps to take once a week so I find.
    And also what I have done for now is using the MMM-GooglePhotos. I created an album where there is always simply one file supposed to be inside (the latest) and it pulls it down from there.
    But the issue I’m facing with that method except it just being a bit complicated is also that every now and then the picture fades out and in (Pic - Black - Pic) which is kinda annoying as well.

    so thx there for an idea as well : )

    {
    			module: "MMM-GooglePhotos",
    			position: "middle_center",
    		config: {
    albumId: ["ALBUM_ID"], // your album id(s) from result of `auth_and_test.js`
    				// refreshInterval: 1000*60,  
    				// ! scanInterval: 1000*60*10, // too many scans might cause API quota limit also.
    
    				sort: "time", //'time', 'reverse', 'random'
    				showWidth: "50%", 
    				showHeight: "650px",
    				originalWidthPx: 2339, 
    				originalHeightPx: 1653, 
    				mode: "hybrid", // "cover" or "contain" 
    					}
    		},
    


  • @BD0G hey thx mate. That sounds very good.
    I’ll try that out.

    However regarding the latest file is where I’m still having some problem solving to do.
    The thing is that I want on Google Drive to have a folder where a few people have access to. I want them to be able to just delete the old file and drop the new file there (with the same file name or what ever action they have to do).
    Now here is the problem. Drive gives each file a new ID so the thing with a static file Name doesn’t work unfortunately.



  • @JohnDelta said in PDF Implementation:

    @ember1205 so I’ve tried. But that’s just a few unnecessary steps to take once a week so I find.

    That was why I had mentioned doing it with ‘convert’ from ImageMagick - you can script it and then make it into a cron job. Pull the PDF down to the local device, detect that it’s a different PDF (not necessary), and run the convert tool to make it into an image file stored someone on the local filesystem. Done.



  • If others load one .pdf file to the google drive and then delete all other files in that directory well then the file extension would still be .pdf (right) ? So then one could script it using *.pdf (file that ends in .pdf)

    So whatever actions that were taken were performed upon a file that ended with .pdf

    The file name becomes inconsequential. Just grab all .pdf files (as there will only be one) , download them to a specific directory you create on a local system (ftp sounds like it may be a good option for this) and then use the convert action that @ember1205 speaks of within ImageMagick, upload back to Google Drive via ftp and then (damn! Google Drive will then rename it with another file ID and then the URL that is within the config.js that points to the url will be broken and not display -ugggggg) . I think I understand now.

    Here is a Google Chrome Add on that allows one to Overwrite the same file without changing the file name. It “may” be helpful?
    https://chrome.google.com/webstore/detail/drive-overwrite-file-repl/llanhaaigblafdecdihpppjaeekpddfl?hl=en-US

    It really sounds like you may have to delve into Google App Script to accomplish this. https://developers.google.com/apps-script

    If you have questions about using this scripting tool then I think there is support over on www.stackoverflow.com

    I am not a Google Script Coder so I cannot be of any help there.



  • @BD0G said in PDF Implementation:

    If others load one .pdf file to the google drive and then delete all other files in that directory well then the file extension would still be .pdf (right) ? So then one could script it using *.pdf (file that ends in .pdf)

    So whatever actions that were taken were performed upon a file that ended with .pdf

    The file name becomes inconsequential. Just grab all .pdf files (as there will only be one) , download them to a specific directory you create on a local system (ftp sounds like it may be a good option for this) and then use the convert action that @ember1205 speaks of within ImageMagick, upload back to Google Drive via ftp and then (damn! Google Drive will then rename it with another file ID and then the URL that is within the config.js that points to the url will be broken and not display -ugggggg) . I think I understand now.

    Here is a Google Chrome Add on that allows one to Overwrite the same file without changing the file name. It “may” be helpful?
    https://chrome.google.com/webstore/detail/drive-overwrite-file-repl/llanhaaigblafdecdihpppjaeekpddfl?hl=en-US

    It really sounds like you may have to delve into Google App Script to accomplish this. https://developers.google.com/apps-script

    If you have questions about using this scripting tool then I think there is support over on www.stackoverflow.com

    I am not a Google Script Coder so I cannot be of any help there.

    Download from Google drive to the MM device. Convert. Store converted file locally. Load local file.

    Less complicated than downloading, converting, pushing back up, figuring out new ID, etc.



  • @BD0G said in PDF Implementation:

    If others load one .pdf file to the google drive and then delete all other files in that directory well then the file extension would still be .pdf (right) ? So then one could script it using *.pdf (file that ends in .pdf)

    So whatever actions that were taken were performed upon a file that ended with .pdf

    The file name becomes inconsequential. Just grab all .pdf files (as there will only be one) , download them to a specific directory you create on a local system (ftp sounds like it may be a good option for this) and then use the convert action that @ember1205 speaks of within ImageMagick, upload back to Google Drive via ftp and then (damn! Google Drive will then rename it with another file ID and then the URL that is within the config.js that points to the url will be broken and not display -ugggggg) . I think I understand now.

    Here is a Google Chrome Add on that allows one to Overwrite the same file without changing the file name. It “may” be helpful?
    https://chrome.google.com/webstore/detail/drive-overwrite-file-repl/llanhaaigblafdecdihpppjaeekpddfl?hl=en-US

    It really sounds like you may have to delve into Google App Script to accomplish this. https://developers.google.com/apps-script

    If you have questions about using this scripting tool then I think there is support over on www.stackoverflow.com

    I am not a Google Script Coder so I cannot be of any help there.

    Thank you buddy.
    I still haven’t really found a way that works but the Chrome Addon did actually help me in another case as well.

    I’m now going to try to connect google drive with the Pi via rclone4pi and then somehow try to adapt the thoughts from @BD0G with creating a script that converts them into .jpeg and moves the images into a specific folder.
    (Happy for any help since I’m not a coder at all)


Log in to reply