Convert RAR files to PDF in Java effortlessly with the help of Conholdate.Total for Java APIs, supporting all main archive file formats including ZIP, RAR, GZIP, BZ2, TAR, LZ, XAR, CAB, CPIO, XZ, SHAR, WIM and 7Z. Follow our straightforward Java code example to implement RAR to PDF conversions in your Java projects quickly. Not a developer? No worries, the user-friendly online RAR to PDF converter has got you covered — just upload a RAR, hit convert button, and download your PDF file in seconds.
Download// Supported file formats: https://docs.groupdocs.com/conversion/java/supported-document-formats/ | |
// Works with OpenJDK 17 | |
package com.mycompany.asposejavatest; | |
import java.io.*; | |
import java.util.ArrayList; | |
import org.apache.commons.compress.archivers.*; | |
import org.apache.commons.compress.compressors.*; | |
import com.groupdocs.conversion.*; | |
import com.groupdocs.conversion.Converter; | |
import com.groupdocs.conversion.options.convert.PdfConvertOptions; | |
import com.groupdocs.conversion.contracts.PossibleConversions; | |
import com.groupdocs.conversion.options.convert.ConvertOptions; | |
import com.groupdocs.merger.*; | |
import com.groupdocs.merger.Merger; | |
public class AsposeJavaTest { | |
public static void main(String[] args) { | |
try { | |
InputStream inputfile = new BufferedInputStream(new FileInputStream("input.zip")); | |
// For those formats that are separately archived and compressed. Like tar.gz tar.bz tar.xz Use | |
// CompressorInputStream and than use ArchiveInputStream to load the input file. | |
//CompressorInputStream cis = new CompressorStreamFactory().createCompressorInputStream(inputfile); | |
//ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(cis); | |
// For formats that have builtin support for compression. Like Zip RAR JAR 7zip | |
// ArchiveInputStream to load the input file without CompressorInputStream | |
//ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(inputfile); | |
ArchiveEntry entry = ais.getNextEntry(); | |
File outputDir = new File("/tmp/output"); | |
if (!outputDir.exists()) { | |
outputDir.mkdirs(); | |
} | |
while (entry != null) { | |
String filePath = outputDir.getAbsolutePath() + File.separator + entry.getName(); | |
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); | |
byte[] bytesIn = new byte[1024]; | |
int read; | |
while ((read = ais.read(bytesIn)) != -1) { | |
bos.write(bytesIn, 0, read); | |
} | |
ais.close(); | |
bos.close(); | |
entry = ais.getNextEntry(); | |
} | |
// Temporary List to hold names of extracted files from unzipped folder | |
ArrayList<String> filesList = new ArrayList<>(); | |
// Get the list of all files (with full paths) from unzipped folder | |
File[] files = outputDir.listFiles(); | |
// Loop through each unzipped file and convert each file to PDF | |
for (File file : files) { | |
// Load the extracted file | |
Converter converter = new Converter(file.getAbsolutePath()); | |
// Set the convert options for PDF format | |
PdfConvertOptions convertOptions = new PdfConvertOptions(); | |
// Convert to PDF format | |
String outPath = outputDir.getAbsolutePath() + File.separator + file.getName()+ ".pdf"; | |
converter.convert(outPath, convertOptions); | |
// Add the file names to temporary List after converting to PDF | |
filesList.add(outPath); | |
} | |
// Merge PDF files using GroupDocs.Merger API | |
// Instantiate Merger with first input PDF document in temporary List | |
Merger merger = new Merger(filesList.get(0)); | |
// Loop through list of converted PDF documents starting from second file | |
for (int i = 1; i < filesList.size(); i++) { | |
// Call Join method of Merger class instance and pass remaining source files one by one | |
merger.join(filesList.get(i)); | |
} | |
// Call Save method of Merger class instance to save merged PDF document | |
merger.save("/tmp/output.pdf"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
The Conholdate.Total for Java platform lets you try out different ways to convert archive files. Developers have two main options - they can use ready-made examples from GroupDocs for a straightforward approach, or go with Aspose examples for more control. You can also use these examples to work on both the front and back end of a project, or build your RAR to PDF conversion feature from scratch using popular Java-supporting tools like Eclipse or Visual Studio Code.
Conholdate.Total for Java brings together all the Java APIs from Aspose and GroupDocs. Although developers have various APIs to choose from for converting RAR to PDF, we chose to show easy-to-follow examples using GroupDocs.Conversion for Java in our code snippets.
Conholdate.Total for Java combines libraries from Aspose and GroupDocs, allowing Java programmers to work with many different file formats like Word, Excel, Visio, images and PDF in Java and J2SE apps. This means you can easily manipulate and manage these files in your Java projects.
RAR is a file format used for compressing and archiving files. It was developed by Eugene Roshal, a Russian software engineer, and was released in 1993. The RAR format is commonly used for sharing large files due to its high compression efficiency, which can often result in smaller file sizes than other compression methods. This makes it an ideal format for users who need to transfer large files over the internet or other networks.
The main advantage of RAR over other file formats is that it can be used to create multi-volume archives. This means that large files can be split into several smaller files, which can then be combined into a single file when needed. This allows for greater flexibility in storage and transmission, as users can transfer the smaller files more easily and then recombine them later.
RAR files can be password-protected and encrypted for added security. This is especially useful when transferring sensitive data over the internet. When creating a RAR file, users can choose to encrypt it with a password, which will be required to open the file. This makes RAR a popular choice for sharing confidential documents and files.
RAR files are typically identified by the .rar extension, and can be opened using WinRAR, a proprietary file archiving utility. WinRAR is available for Windows, Mac, and Linux operating systems, and supports a variety of compression formats, including RAR, ZIP, and 7Z. It also includes features such as file splitting, password protection, and recovery volumes, which can be used to recover data in case of a file corruption or system crash.
LearnPDF (Portable Document Format) is a widely used document file format developed by Adobe Systems in 1993. It was specifically designed to provide a platform-independent solution for storing and sharing documents across various operating systems and over the Internet. PDFs utilize a vector-based drawing model, storing graphical elements such as lines, shapes, and images as mathematical equations. This unique approach ensures that PDFs are resolution independent, guaranteeing consistent document quality regardless of the viewing device or program.
One of the key advantages of PDFs is their support for a range of security features. Encryption, password protection, digital signatures, and document watermarking are among the security measures available. These features make PDFs highly secure and suitable for sensitive documents, such as medical records, legal documents, government forms, and invoices. The printing industry also heavily relies on PDFs to facilitate electronic communication with customers.
Creating PDFs is a straightforward process, as they can be generated from various electronic document formats, including Word documents, PowerPoint presentations, and webpages. It’s important to note that PDFs are typically not editable directly. To modify the content of a PDF, it must first be converted to a different file format that supports editing. Numerous software programs, many of which are freely available for download, offer the functionality to convert PDFs to editable formats.
PDFs have gained immense popularity and have become a standard method for document sharing due to their versatility, security features, and consistent formatting. Their compatibility across different devices and operating systems ensures seamless document access for users. Additionally, PDFs preserve the layout, fonts, and images of the original document, making them an ideal choice for sharing visually rich content.
Learn(Portable Document Format)
(Word Processing Files)
(Digital Image Files)
(Spreadsheet Files)
(Microsoft Word Binary Format)
(Office 2007+ Word Document)
(Microsoft Word 2007 Marco File)
(Microsoft Word Template Files)
(Microsoft Word Template File )
(Microsoft Word 2007+ Template File)
(Text Document)
(Rich Text Format)
(Hyper Text Markup Language)
(Hypertext Markup Language File)
(Web Page Archive Format)
(MHTML Web Archive)
(Microsoft Excel Spreadsheet (Legacy))
(Open XML Workbook)
(Macro-enabled Spreadsheet)
(Excel Binary Workbook)
(Excel 97 - 2003 Template)
(Excel Template)
(Excel Macro-Enabled Template)
(Comma Seperated Values)
(Tab Seperated Values)
(StarOffice Calc Spreadsheet)
(OpenDocument Flat XML Spreadsheet)
(Microsoft PowerPoint 97-2003)
(Open XML presentation Format)
(PowerPoint Slide Show)
(PowerPoint Slide Show)
(Macro-enabled Slide Show)
(Microsoft PowerPoint Template Files)
(Microsoft PowerPoint Template Presentation)
(Macro-enabled Presentation File)
(Microsoft PowerPoint Template File)
(OpenDocument Text File Format)
(OpenDocument Standard Format)
(OpenDocument Standard Format)
(OpenDocument Presentation Format)
(OpenDocument Spreadsheet)
(Windows Compressed Enhanced Metafile)
(Compressed Windows Metafile)
(Scalar Vector Graphics)
(Compressed Scalable Vector Graphics)
(XML Paper Specifications)
(LaTeX Source Document)
(DICOM Image)
(Windows Metafile)
(Enhanced Metafile Format)
(Bitmap Image File)
(Portable Network Graphic)
(Graphical Interchange Format)
(Joint Photographic Expert Group Image)
(Tagged Image File Format)
(Icon File)
(Raster Web Image Format)
(JPEG 2000 Core Image)
(Truevision Graphics Adapter)
(Photoshop Large Document Format)
(Photoshop Document)
(Open eBook File)
(Markdown Language)
(XML File)
(JavaScript Object Notation File)
(Digital Imaging & Communications)
(Formula One for Data Presentation)
(Joint Photographic Expert Group Image)
(Amazon KF8 eBook File)
(Visio Drawing)