Download imagestopdf.html from Talha912/PDFIX: direct link, hf CLI and curl.
- Browser
- Download file 19.6 kB
-
https://huggingface.co/spaces/Talha912/PDFIX/resolve/main/imagestopdf.html
- Command line
-
hf download hf://spaces/Talha912/PDFIX/imagestopdf.html
-
curl -L -o imagestopdf.html https://huggingface.co/spaces/Talha912/PDFIX/resolve/main/imagestopdf.html
19.6 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>PDFix — Images to PDF</title> | |
| <style> | |
| :root{--ink:#172033;--muted:#667085;--line:#e3e8f0;--blue:#185abd;--blue-dark:#104a9e;--bg:#f4f7fb;--soft:#edf4ff} | |
| *{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font-family:"Segoe UI",Arial,sans-serif} | |
| header{height:70px;background:#fff;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;padding:0 25px;gap:14px}.brand{display:flex;align-items:center;gap:11px;text-decoration:none;color:inherit;font-size:21px;font-weight:800}.logo{width:38px;height:38px;border-radius:10px;background:linear-gradient(140deg,#185abd,#6c63ff);display:grid;place-items:center;color:#fff;font-weight:900}.brand small{display:block;color:var(--muted);font-size:10px;letter-spacing:1.7px;margin-top:2px}.back{border:1px solid var(--line);background:#fff;border-radius:9px;padding:10px 13px;text-decoration:none;color:var(--ink);font-size:13px;font-weight:700} | |
| main{max-width:1160px;margin:32px auto;padding:0 18px}.hero{text-align:center;margin:0 auto 25px;max-width:760px}.badge{display:inline-block;background:var(--soft);color:var(--blue);padding:7px 11px;border-radius:999px;font-size:11px;font-weight:800;letter-spacing:.5px}.hero h1{font-size:clamp(30px,4.5vw,44px);letter-spacing:-1.2px;margin:14px 0 8px}.hero p{color:var(--muted);line-height:1.65;margin:0} | |
| .layout{display:grid;grid-template-columns:minmax(290px,370px) minmax(0,1fr);gap:18px;align-items:start}.card{background:#fff;border:1px solid var(--line);border-radius:16px;box-shadow:0 8px 25px rgba(25,39,70,.055);overflow:hidden}.card-head{padding:18px 20px;border-bottom:1px solid var(--line)}.card-head h2{font-size:16px;margin:0 0 5px}.card-head p{font-size:12px;color:var(--muted);line-height:1.5;margin:0}.card-body{padding:20px} | |
| .drop{border:2px dashed #bdcbe2;border-radius:13px;background:#f9fbff;text-align:center;padding:28px 14px;transition:.2s}.drop.drag{border-color:var(--blue);background:var(--soft)}.drop-icon{font-size:37px}.drop h3{font-size:16px;margin:9px 0 6px}.drop p{font-size:12px;color:var(--muted);line-height:1.55;margin:0} | |
| .btn{border:1px solid var(--line);background:#fff;color:var(--ink);border-radius:9px;padding:10px 13px;font-size:13px;font-weight:700;cursor:pointer}.btn.primary{background:var(--blue);border-color:var(--blue);color:#fff}.btn.primary:hover{background:var(--blue-dark)}.btn:disabled{opacity:.45;cursor:not-allowed}.choose{margin-top:15px} | |
| .field{margin-top:16px}.field label{display:block;font-size:12px;font-weight:750;margin-bottom:7px}.field select,.field input[type=number]{width:100%;padding:10px;border:1px solid var(--line);border-radius:9px;background:#fff;font:inherit;font-size:13px}.field p{font-size:11px;color:var(--muted);line-height:1.5;margin:6px 0 0}.check{display:flex;align-items:flex-start;gap:9px;font-size:12px;line-height:1.5;color:#475467;margin-top:14px}.check input{margin-top:3px} | |
| .actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:19px}.actions .btn{flex:1}.status{font-size:12px;color:var(--muted);line-height:1.5;margin-top:12px;min-height:18px} | |
| .preview-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:15px 18px;border-bottom:1px solid var(--line)}.preview-head strong{font-size:14px}.preview-head span{font-size:11px;color:var(--muted)}.preview-area{min-height:500px;max-height:760px;overflow:auto;background:#edf0f5;padding:18px}.empty{text-align:center;color:var(--muted);font-size:13px;line-height:1.6;max-width:320px;margin:100px auto}.empty .paper{font-size:42px;margin-bottom:15px} | |
| .image-list{display:flex;flex-direction:column;gap:9px}.image-item{display:grid;grid-template-columns:58px minmax(0,1fr) auto;align-items:center;gap:10px;padding:9px;border:1px solid var(--line);background:#fff;border-radius:10px}.image-item img{width:58px;height:58px;object-fit:cover;border-radius:6px;background:#f3f5f8}.image-info{min-width:0}.image-info strong{font-size:12px;display:block;overflow-wrap:anywhere}.image-info small{display:block;font-size:10px;color:var(--muted);margin-top:4px}.image-controls{display:flex;flex-direction:column;gap:4px}.image-controls button{font-size:10px;padding:5px 7px} | |
| .page-preview{background:white;box-shadow:0 4px 18px rgba(25,39,70,.14);margin:0 auto 16px;position:relative;overflow:hidden;display:flex;align-items:center;justify-content:center}.page-preview img{display:block;width:100%;height:100%;object-fit:contain} | |
| .progress{display:none;margin-top:12px}.track{height:7px;background:#e9edf4;border-radius:20px;overflow:hidden}.bar{width:0;height:100%;background:linear-gradient(90deg,#185abd,#7464ff);transition:width .2s}.progress small{display:block;margin-top:6px;color:var(--muted);font-size:11px} | |
| .limits{margin-top:18px;border:1px solid #ead8a6;background:#fffaf0;border-radius:13px;padding:16px 18px}.limits h3{font-size:13px;margin:0 0 8px;color:#7a5a15}.limits ul{padding-left:18px;margin:0;display:grid;grid-template-columns:1fr 1fr;gap:7px 22px}.limits li{font-size:11px;line-height:1.55;color:#6c5b36} | |
| .features{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-top:18px}.feature{background:#fff;border:1px solid var(--line);border-radius:12px;padding:14px}.feature b{font-size:12px}.feature p{font-size:11px;color:var(--muted);line-height:1.5;margin:6px 0 0}footer{text-align:center;color:var(--muted);font-size:11px;padding:27px 12px}#fileInput{display:none} | |
| @media(max-width:850px){.layout{grid-template-columns:1fr}.preview-area{min-height:300px}.features{grid-template-columns:1fr}}@media(max-width:600px){header{padding:0 12px}.brand{font-size:18px}.back{font-size:11px;padding:8px}main{margin-top:22px;padding:0 11px}.card-body{padding:14px}.limits ul{grid-template-columns:1fr}.preview-area{padding:10px}.preview-head{padding:12px}} | |
| </style></head><body> | |
| <header><a class="brand" href="index.html"><span class="logo">P</span><span>PDFix<small>PDF TOOLS</small></span></a><a class="back" href="index.html">← All PDF tools</a></header> | |
| <main> | |
| <section class="hero"><span class="badge">IMAGE CONVERTER</span><h1>Convert Images to PDF</h1><p>Combine JPG, PNG, WebP and other common images into a PDF. Reorder images, choose page settings and preview pages before downloading.</p></section> | |
| <div class="layout"> | |
| <section class="card"><div class="card-head"><h2>Images & settings</h2><p>Add multiple images, arrange their order, and customize the PDF output.</p></div><div class="card-body"> | |
| <div class="drop" id="dropZone"><div class="drop-icon">🖼️</div><h3>Drop images here</h3><p>Choose one or multiple image files.<br>Supported image types depend on your browser.</p><button class="btn primary choose" id="chooseBtn" type="button">Choose images</button></div> | |
| <input id="fileInput" type="file" accept="image/*" multiple> | |
| <div class="actions"><button class="btn" id="addMoreBtn" disabled>Add more images</button><button class="btn" id="clearBtn" disabled>Clear all</button></div><div id="imageList" class="image-list" style="margin-top:12px"></div> | |
| <div class="field"><label for="pageSize">Page size</label><select id="pageSize"><option value="a4">A4</option><option value="letter">US Letter</option><option value="legal">US Legal</option><option value="fit">Fit page to image</option></select></div> | |
| <div class="field"><label for="orientation">Orientation</label><select id="orientation"><option value="auto">Auto (based on image)</option><option value="portrait">Portrait</option><option value="landscape">Landscape</option></select></div> | |
| <div class="field"><label for="fitMode">Image fitting</label><select id="fitMode"><option value="contain">Fit inside page (no cropping)</option><option value="fill">Fill page (may crop)</option></select></div> | |
| <div class="field"><label for="margin">Page margin (points)</label><input id="margin" type="number" min="0" max="100" value="24"><p>72 points = 1 inch. Margins apply to fixed page sizes.</p></div> | |
| <label class="check"><input id="oneImagePerPage" type="checkbox" checked><span>Put each image on a separate PDF page.</span></label> | |
| <label class="check"><input id="ocrEnabled" type="checkbox"><span><b>Run OCR (make text searchable)</b> — detect text inside images and add a searchable text layer to the PDF. This can take longer.</span></label> | |
| <div class="field" id="ocrLanguageWrap" style="display:none"><label for="ocrLanguage">OCR language</label><select id="ocrLanguage"><option value="eng">English</option><option value="urd">Urdu</option><option value="eng+urd">English + Urdu</option><option value="ara">Arabic</option><option value="hin">Hindi</option><option value="fra">French</option><option value="deu">German</option><option value="spa">Spanish</option></select><p>Language data is downloaded from a CDN when OCR runs. Results depend on image quality and selected language.</p></div> | |
| <div class="actions"><button class="btn primary" id="convertBtn" disabled>Create PDF ↓</button></div><div class="status" id="status">Add images to begin.</div><div class="progress" id="progress"><div class="track"><div class="bar" id="bar"></div></div><small id="progressText">Preparing…</small></div> | |
| </div></section> | |
| <section class="card"><div class="preview-head"><strong>PDF page preview</strong><span id="previewMeta">No images added</span></div><div class="preview-area" id="previewArea"><div class="empty" id="empty"><div class="paper">📑</div><strong>Your PDF preview will appear here</strong><br>Add images to see how pages will look.</div><div id="pagesPreview" style="width:100%"></div></div></section> | |
| </div> | |
| <section class="limits"><h3>Important limitations</h3><ul> | |
| <li>Images are processed in your browser; very large files or many images may use significant memory.</li> | |
| <li>Animated formats such as GIF usually contribute only the first displayed frame.</li> | |
| <li>Transparency in PNG/WebP may be flattened onto a white background.</li> | |
| <li>Fit-to-page mode uses image dimensions; fixed page sizes may add whitespace or crop edges depending on your fitting choice.</li> | |
| <li>Optional OCR can add a searchable text layer, but it does not make the original image text fully editable like a Word document.</li> | |
| <li>OCR can make mistakes with blurry photos, handwriting, unusual fonts, tables, low contrast, skewed pages or mixed languages. Always proofread important results.</li> | |
| <li>Colour profiles, EXIF orientation and image metadata may not be preserved exactly.</li> | |
| <li>Browser support for image formats varies. If an image cannot be decoded, convert it to JPG or PNG and try again.</li> | |
| <li>The PDF library loads from a CDN, so an internet connection is required. Images are not uploaded to a PDFix server by this page.</li> | |
| </ul></section> | |
| <section class="features"><div class="feature"><b>↕️ Reorder images</b><p>Move images up or down to control the page sequence.</p></div><div class="feature"><b>📄 Flexible pages</b><p>Choose A4, Letter, Legal or fit each page to its image.</p></div><div class="feature"><b>🔒 Browser processing</b><p>Images are converted locally in your browser.</p></div></section> | |
| </main><footer>PDFix · Images to PDF · Review your pages before sharing</footer> | |
| <script src="https://unpkg.com/pdf-lib@1.17.1/dist/pdf-lib.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js"></script> | |
| <script> | |
| const $=id=>document.getElementById(id);let images=[],nextId=1; | |
| function setStatus(s){$('status').textContent=s}function humanSize(n){return n<1024?n+' B':n<1048576?(n/1024).toFixed(1)+' KB':(n/1048576).toFixed(2)+' MB'} | |
| function addFiles(files){const accepted=[...files].filter(f=>f.type.startsWith('image/'));if(!accepted.length){if(files.length)alert('Please choose supported image files.');return}for(const file of accepted)images.push({id:nextId++,file,url:URL.createObjectURL(file),name:file.name,size:file.size});renderList();renderPreview();updateControls();setStatus(`${images.length} image(s) ready.`)} | |
| function renderList(){const list=$('imageList');list.innerHTML='';images.forEach((it,index)=>{const row=document.createElement('div');row.className='image-item';const img=document.createElement('img');img.src=it.url;img.alt='';const info=document.createElement('div');info.className='image-info';const name=document.createElement('strong');name.textContent=it.name;const meta=document.createElement('small');meta.textContent=humanSize(it.size);info.append(name,meta);const controls=document.createElement('div');controls.className='image-controls';[['↑',index===0,()=>move(index,-1)],['↓',index===images.length-1,()=>move(index,1)],['×',false,()=>removeImage(it.id)]].forEach(([label,disabled,fn])=>{const b=document.createElement('button');b.className='btn';b.textContent=label;b.disabled=disabled;b.onclick=fn;controls.appendChild(b)});row.append(img,info,controls);list.appendChild(row)})} | |
| function move(i,d){const j=i+d;if(j<0||j>=images.length)return;[images[i],images[j]]=[images[j],images[i]];renderList();renderPreview()} | |
| function removeImage(id){const i=images.findIndex(x=>x.id===id);if(i>=0){URL.revokeObjectURL(images[i].url);images.splice(i,1)}renderList();renderPreview();updateControls();setStatus(images.length?`${images.length} image(s) ready.`:'Add images to begin.')} | |
| function clearAll(){images.forEach(i=>URL.revokeObjectURL(i.url));images=[];$('fileInput').value='';renderList();renderPreview();updateControls();setStatus('Add images to begin.')} | |
| function updateControls(){const has=images.length>0;$('addMoreBtn').disabled=!has;$('clearBtn').disabled=!has;$('convertBtn').disabled=!has;$('previewMeta').textContent=has?`${images.length} image(s) · ${images.length} page(s)`:'No images added'} | |
| $('chooseBtn').onclick=()=>$('fileInput').click();$('addMoreBtn').onclick=()=>$('fileInput').click();$('fileInput').addEventListener('change',e=>{addFiles(e.target.files);e.target.value=''});$('clearBtn').onclick=clearAll; | |
| const drop=$('dropZone');['dragenter','dragover'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.add('drag')}));['dragleave','drop'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.remove('drag')}));drop.addEventListener('drop',e=>addFiles(e.dataTransfer.files)); | |
| function loadImage(it){return new Promise((resolve,reject)=>{const img=new Image();img.onload=()=>resolve(img);img.onerror=()=>reject(new Error(`Could not read image: ${it.name}`));img.src=it.url})} | |
| function pageDimensions(img){const sizes={a4:[595.28,841.89],letter:[612,792],legal:[612,1008]};let [w,h]=sizes[$('pageSize').value]||[img.naturalWidth,img.naturalHeight];if($('pageSize').value==='fit'){const scale=Math.min(1,1200/Math.max(img.naturalWidth,img.naturalHeight));w=Math.max(1,img.naturalWidth*scale);h=Math.max(1,img.naturalHeight*scale)}let ori=$('orientation').value;if(ori==='auto')ori=img.naturalWidth>img.naturalHeight?'landscape':'portrait';if(ori==='landscape'&&h>w)[w,h]=[h,w];if(ori==='portrait'&&w>h)[w,h]=[h,w];return[w,h]} | |
| async function renderPreview(){const box=$('pagesPreview');box.innerHTML='';$('empty').style.display=images.length?'none':'block';for(const it of images){try{const img=await loadImage(it);const [pw,ph]=pageDimensions(img),scale=Math.min(300/pw,380/ph);const wrap=document.createElement('div');wrap.className='page-preview';wrap.style.width=pw*scale+'px';wrap.style.height=ph*scale+'px';const im=document.createElement('img');im.src=it.url;im.alt='';im.style.objectFit=$('fitMode').value==='fill'?'cover':'contain';wrap.appendChild(im);box.appendChild(wrap)}catch(e){console.warn(e)}}updateControls()} | |
| ['pageSize','orientation','fitMode','margin'].forEach(id=>$(id).addEventListener('change',renderPreview)); | |
| $('ocrEnabled').addEventListener('change',()=>{$('ocrLanguageWrap').style.display=$('ocrEnabled').checked?'block':'none'}); | |
| function canvasJpeg(img,fit,w,h,margin){const scale=2,canvas=document.createElement('canvas');canvas.width=Math.max(1,Math.round(w*scale));canvas.height=Math.max(1,Math.round(h*scale));const ctx=canvas.getContext('2d');ctx.fillStyle='#fff';ctx.fillRect(0,0,canvas.width,canvas.height);const ax=Math.max(1,(w-2*margin)*scale),ay=Math.max(1,(h-2*margin)*scale),ratio=fit==='fill'?Math.max(ax/img.naturalWidth,ay/img.naturalHeight):Math.min(ax/img.naturalWidth,ay/img.naturalHeight),dw=img.naturalWidth*ratio,dh=img.naturalHeight*ratio;ctx.save();ctx.beginPath();ctx.rect(margin*scale,margin*scale,ax,ay);ctx.clip();ctx.drawImage(img,margin*scale+(ax-dw)/2,margin*scale+(ay-dh)/2,dw,dh);ctx.restore();return canvas.toDataURL('image/jpeg',.92)} | |
| $('convertBtn').onclick=async()=>{if(!images.length)return;const btn=$('convertBtn');btn.disabled=true;$('progress').style.display='block';$('bar').style.width='2%';let worker=null;try{const {PDFDocument,StandardFonts,rgb}=PDFLib,pdf=await PDFDocument.create(),margin=Math.max(0,Math.min(100,+$('margin').value||0)),fit=$('fitMode').value,doOCR=$('ocrEnabled').checked;let ocrFont=null;if(doOCR){$('progressText').textContent='Starting OCR engine…';worker=await Tesseract.createWorker($('ocrLanguage').value,1,{logger:m=>{if(m.status==='recognizing text'){$('progressText').textContent=`OCR: ${Math.round((m.progress||0)*100)}%`;}}});ocrFont=await pdf.embedFont(StandardFonts.Helvetica);} | |
| for(let i=0;i<images.length;i++){setStatus(`Preparing image ${i+1} of ${images.length}…`);$('progressText').textContent=`Processing ${images[i].name}`;const img=await loadImage(images[i]),[pw,ph]=pageDimensions(img),m=$('pageSize').value==='fit'?0:margin,page=pdf.addPage([pw,ph]),jpeg=canvasJpeg(img,fit,pw,ph,m),data=Uint8Array.from(atob(jpeg.split(',')[1]),c=>c.charCodeAt(0)),embedded=await pdf.embedJpg(data);page.drawImage(embedded,{x:0,y:0,width:pw,height:ph}); | |
| if(doOCR){$('progressText').textContent=`Recognizing text · image ${i+1} of ${images.length}`;const result=await worker.recognize(images[i].url);const words=(result.data&&result.data.words)||[];const imgW=img.naturalWidth,imgH=img.naturalHeight;const availW=Math.max(1,pw-2*m),availH=Math.max(1,ph-2*m);const ratio=fit==='fill'?Math.max(availW/imgW,availH/imgH):Math.min(availW/imgW,availH/imgH);const drawW=imgW*ratio,drawH=imgH*ratio,offsetX=(pw-drawW)/2,offsetY=(ph-drawH)/2;for(const word of words){const text=String(word.text||'').trim();if(!text)continue;const b=word.bbox||{};const x=offsetX+m+(b.x0||0)*ratio;const yTop=ph-(offsetY+m+(b.y0||0)*ratio);const height=Math.max(4,((b.y1||b.y0+10)-(b.y0||0))*ratio);const fontSize=Math.max(4,Math.min(40,height));try{page.drawText(text,{x:Math.max(0,x),y:Math.max(0,yTop-fontSize),size:fontSize,font:ocrFont,color:rgb(0,0,0),opacity:0.001});}catch(e){/* skip words unsupported by standard font */}}} | |
| $('bar').style.width=Math.round((i+1)/images.length*85)+'%'} | |
| if(worker){await worker.terminate();worker=null} | |
| $('progressText').textContent='Building PDF…';const out=await pdf.save(),blob=new Blob([out],{type:'application/pdf'}),url=URL.createObjectURL(blob),a=document.createElement('a');a.href=url;a.download=doOCR?'PDFix-images-searchable.pdf':'PDFix-images.pdf';a.click();setTimeout(()=>URL.revokeObjectURL(url),2000);$('bar').style.width='100%';$('progressText').textContent='Complete';setStatus(doOCR?`Searchable PDF created with OCR for ${images.length} image(s).`:`PDF created successfully with ${images.length} page(s).`)}catch(err){console.error(err);if(worker){try{await worker.terminate()}catch(e){}}setStatus(err.message||'Could not create PDF. Try smaller images.');alert(err.message||'Could not create PDF.')}finally{btn.disabled=false}} | |
| </script></body></html> |