This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# name: Convert PDF to HTML5 Flipbook | |
# on: | |
# workflow_dispatch: # Allow manual trigger | |
# jobs: | |
# convert-to-flipbook: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v2 | |
# - name: Set up Node.js | |
# uses: actions/setup-node@v2 | |
# with: | |
# node-version: '14' | |
# - name: Create flipbookpdf folder | |
# run: mkdir -p flipbookpdf | |
# - name: Download PDF | |
# run: | | |
# curl -L -o flipbookpdf/Patoloji-Atlasi.pdf https://github.com/patolojiatlasi/patolojiatlasi.github.io/releases/latest/download/Patoloji-Atlasi.pdf | |
# - name: Download and extract pdf.js | |
# run: | | |
# cd flipbookpdf | |
# curl -L -o pdfjs.zip https://github.com/mozilla/pdf.js/releases/download/v2.9.359/pdfjs-2.9.359-dist.zip | |
# unzip -o pdfjs.zip -d pdfjs | |
# rm pdfjs.zip | |
# - name: Download turn.js | |
# run: | | |
# cd flipbookpdf | |
# curl -O https://raw.githubusercontent.com/blasten/turn.js/master/turn.min.js | |
# - name: Create flipbook HTML | |
# run: | | |
# cd flipbookpdf | |
# cat > "flipbook.html" <<EOL | |
# <!DOCTYPE html> | |
# <html lang="en"> | |
# <head> | |
# <meta charset="UTF-8"> | |
# <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
# <title>PDF Viewer</title> | |
# <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.9.359/pdf.min.js"></script> | |
# <style> | |
# #pdf-viewer { | |
# width: 100%; | |
# height: 800px; | |
# overflow: auto; | |
# background: #ccc; | |
# text-align: center; | |
# position: relative; | |
# } | |
# canvas { | |
# margin: 10px auto; | |
# } | |
# #controls { | |
# position: absolute; | |
# top: 10px; | |
# left: 50%; | |
# transform: translateX(-50%); | |
# display: flex; | |
# gap: 10px; | |
# } | |
# #loading { | |
# position: absolute; | |
# top: 50%; | |
# left: 50%; | |
# transform: translate(-50%, -50%); | |
# font-size: 20px; | |
# color: #000; | |
# } | |
# </style> | |
# </head> | |
# <body> | |
# <div id="pdf-viewer"> | |
# <div id="loading">Loading...</div> | |
# <div id="controls"> | |
# <button id="prev-page">Previous</button> | |
# <span id="page-info">Page <span id="current-page"></span> of <span id="total-pages"></span></span> | |
# <button id="next-page">Next</button> | |
# <button id="zoom-in">Zoom In</button> | |
# <button id="zoom-out">Zoom Out</button> | |
# </div> | |
# </div> | |
# <script> | |
# pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.9.359/pdf.worker.min.js'; | |
# var pdfPath = 'Patoloji-Atlasi.pdf'; | |
# var pdfDoc = null; | |
# var pageNum = 1; | |
# var scale = 1.5; | |
# var canvas = document.createElement('canvas'); | |
# var ctx = canvas.getContext('2d'); | |
# var viewer = document.getElementById('pdf-viewer'); | |
# viewer.appendChild(canvas); | |
# function renderPage(num) { | |
# pdfDoc.getPage(num).then(function (page) { | |
# var viewport = page.getViewport({ scale: scale }); | |
# canvas.height = viewport.height; | |
# canvas.width = viewport.width; | |
# var renderContext = { | |
# canvasContext: ctx, | |
# viewport: viewport | |
# }; | |
# page.render(renderContext).promise.then(function () { | |
# document.getElementById('loading').style.display = 'none'; | |
# document.getElementById('current-page').textContent = pageNum; | |
# document.getElementById('total-pages').textContent = pdfDoc.numPages; | |
# }).catch(function (error) { | |
# console.error('Error rendering page:', error); | |
# alert('Error rendering page: ' + error.message); | |
# }); | |
# }).catch(function (error) { | |
# console.error('Error getting page:', error); | |
# alert('Error getting page: ' + error.message); | |
# }); | |
# } | |
# function queueRenderPage(num) { | |
# if (pageNum !== num) { | |
# pageNum = num; | |
# renderPage(pageNum); | |
# } | |
# } | |
# function onPrevPage() { | |
# if (pageNum <= 1) { | |
# return; | |
# } | |
# queueRenderPage(pageNum - 1); | |
# } | |
# function onNextPage() { | |
# if (pageNum >= pdfDoc.numPages) { | |
# return; | |
# } | |
# queueRenderPage(pageNum + 1); | |
# } | |
# function zoomIn() { | |
# scale += 0.1; | |
# renderPage(pageNum); | |
# } | |
# function zoomOut() { | |
# if (scale > 0.5) { | |
# scale -= 0.1; | |
# renderPage(pageNum); | |
# } | |
# } | |
# document.getElementById('prev-page').addEventListener('click', onPrevPage); | |
# document.getElementById('next-page').addEventListener('click', onNextPage); | |
# document.getElementById('zoom-in').addEventListener('click', zoomIn); | |
# document.getElementById('zoom-out').addEventListener('click', zoomOut); | |
# pdfjsLib.getDocument(pdfPath).promise.then(function (pdfDoc_) { | |
# pdfDoc = pdfDoc_; | |
# renderPage(pageNum); | |
# }).catch(function (error) { | |
# console.error('Error loading PDF:', error); | |
# alert('Error loading PDF: ' + error.message); | |
# document.getElementById('pdf-viewer').innerHTML = 'Error loading PDF. Please check the console for details.'; | |
# }); | |
# </script> | |
# </body> | |
# </html> | |
# EOL | |
# - name: Commit and push changes | |
# run: | | |
# git config --local user.email "[email protected]" | |
# git config --local user.name "GitHub Action" | |
# git add flipbookpdf | |
# git commit -m "Update flipbook PDF" || echo "No changes to commit" | |
# git push |