Unlock Seamless Multi-Format File Previews with kkFileView
kkFileView is an open‑source Spring Boot service that provides RESTful APIs for online preview of over 100 file types—including documents, images, media, CAD, and 3D models—offering high performance, caching, security mechanisms, and easy integration for enterprise applications.
Project Overview
File Online Preview (kkFileView) is an open‑source service built on Spring Boot that offers RESTful APIs for cross‑language, cross‑platform file preview. It can be integrated into Java, PHP, Python, Go, and other applications.
Project repository: https://gitee.com/kekingcn/file-online-preview
Core Features & Technical Highlights
1. Rich File Format Support
The project supports more than 100 file formats, covering:
Text files: txt, html, htm, asp, jsp, xml, json, md, log, java, py, c, cpp, sql, sh, bat
Image files: jpg, jpeg, png, gif, bmp, ico, webp
Office documents: doc, docx, xls, xlsx, ppt, pptx, csv, tsv, pages
PDF documents: pdf, ofd, rtf
Archive files: zip, rar, jar, tar, gzip, 7z
Media files: mp3, wav, mp4, avi, mov, mkv, webm, ogg
CAD drawings: dwg, dxf, stl, ifc
3D models: obj, 3ds, gltf, glb, stl, ply, fbx
Special formats: eml, epub, xmind, bpmn, dcm, drawio
2. Sophisticated Technical Implementation
File Preview Architecture
The system uses a "convert + render" two‑layer architecture.
File reception & identification: REST API receives a file URL and determines type by extension.
Intelligent conversion processing:
Office documents: OpenOffice/LibreOffice API converts to PDF.
PDF documents: PDF.js parses directly.
CAD drawings: Dedicated tools (e.g., AutoCAD) generate preview images.
3D models: Browser‑side rendering with Three.js.
Efficient caching: Conversion results are stored in Redis or local cache.
Front‑end rendering: PDF.js, FlexPaper, etc., provide smooth preview.
Performance Optimization Strategies
Asynchronous processing via Spring Boot @Async.
Paginated preview for large documents.
Memory management with chunked processing.
Cache keys based on file content hash.
Compressed transmission of converted files.
Security Mechanisms
File type whitelist.
Access permission validation.
Integrated virus scanning.
HTTPS and content encryption.
Rate limiting to prevent abuse.
Project Architecture & Tech Stack
Core framework: Spring Boot 2.7.x (Java 11).
Dependencies: OpenOffice/LibreOffice, Redis (optional), specialized conversion tools (AutoCAD, Blender, etc.).
Front‑end technologies: PDF.js, Three.js, FlexPaper.
Implementation Details
1. Office Document Conversion
Conversion is performed via the OpenOffice API. Key code:
public String convertToPdf(String fileUrl) {
// 1. Download file to temporary directory
File tempFile = downloadFile(fileUrl);
// 2. Start OpenOffice service
LibreOfficeConverter converter = new LibreOfficeConverter();
// 3. Convert document to PDF
File pdfFile = converter.convert(tempFile, OutputFormat.PDF);
// 4. Return PDF path
return pdfFile.getAbsolutePath();
}2. Encrypted PDF Preview
Handles encrypted PDFs using iText:
public String previewEncryptedPdf(String encryptedFileUrl, String password) {
// 1. Download encrypted file
File encryptedFile = downloadFile(encryptedFileUrl);
// 2. Use iText to process encryption
PdfReader reader = new PdfReader(encryptedFile, password.getBytes());
// 3. Create temporary decrypted file
File decryptedFile = new File(System.getProperty("java.io.tmpdir"), "decrypted_" + UUID.randomUUID() + ".pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(decryptedFile));
stamper.close();
// 4. Return preview URL of decrypted file
return fileService.uploadFile(decryptedFile);
}3. 3D Model Browser Rendering
Front‑end rendering with Three.js:
function load3DModel(modelUrl) {
const loader = new THREE.GLTFLoader();
loader.load(modelUrl, function(gltf) {
scene.add(gltf.scene);
// Set camera and lighting
camera.position.z = 5;
renderer.render(scene, camera);
});
}Project Advantages
Comprehensive functionality: supports 100+ formats.
Easy deployment: Spring Boot application can be started in three steps.
Excellent performance: multi‑layer optimizations ensure stability under high concurrency.
Secure and reliable: built‑in security mechanisms protect files.
Active iteration: latest v4.4.0 adds medical image (dcm) and drawio preview.
Quick Integration Guide
1. Local Deployment
# Clone the project
git clone https://github.com/kekingcn/file-online-preview.git
# Enter project directory
cd file-online-preview
# Run the service
mvn spring-boot:run2. API Call Example
GET /file/preview?fileUrl=https://example.com/document.pdf3. Response Example
{
"code": 200,
"data": {
"previewUrl": "http://your-server:8012/preview/file/12345.pdf",
"fileType": "pdf",
"isEncrypted": false
}
}Applicable Scenarios
Enterprise document management systems.
Cloud storage services.
Online education platforms.
E‑government portals.
Collaboration office software.
Conclusion
File Online Preview (kkFileView) offers a full‑stack, high‑performance, secure solution for file preview across a wide range of formats, making it a top choice for enterprise‑level applications. Its open‑source nature and active community further empower developers to build high‑quality solutions.
Project continues to evolve with new features such as DCM medical image preview, drawio diagram preview, and encrypted PDF preview.
Cognitive Technology Team
Cognitive Technology Team regularly delivers the latest IT news, original content, programming tutorials and experience sharing, with daily perks awaiting you.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
