Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
GroupDocsGists / CountWordInDocuments.java
Last active May 16, 2022
Count words, unique words, and their occurrence count in Java
View CountWordInDocuments.java
// Count Words in PDF document using Java
// Count Unique Words and their occurrences in PDF document using Java
try (Parser parser = new Parser("path/document.pdf")) {
TextReader reader = parser.getText();
String text = reader.readToEnd();
String[] words = text.split("\\s+|\\.|\\,|\\?|\\:|\\;");
System.out.println("Length:" + words.length);
}
@GroupDocsGists
GroupDocsGists / RemoveListedPdfPages.java
Created Apr 24, 2022
Remove Pages from PDF Documents in Java | Even , Odd, List of Pages and Pages Range
View RemoveListedPdfPages.java
// Remove selective pages from the PDF in Java
RemoveOptions removeOptions = new RemoveOptions(new int[] { 2, 4 });
Merger merger = new Merger("path/document-pdf");
merger.removePages(removeOptions);
merger.save("path/selected-pages-removed.pdf");
@GroupDocsGists
GroupDocsGists / redact_text_using_color_box.java
Last active Apr 29, 2022
Text Redaction Via Color Box Using Java
View redact_text_using_color_box.java
// Supported file formats: https://docs.groupdocs.com/redaction/java/supported-document-formats/
final Redactor redactor = new Redactor("sample.pdf");
try
{
redactor.apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(java.awt.Color.RED)));
redactor.save();
}
finally { redactor.close();
}
@GroupDocsGists
GroupDocsGists / case_sensitive_redaction.java
Last active Apr 29, 2022
Case-Sensitive Textual Redaction via Exact Phrase using Java
View case_sensitive_redaction.java
// Supported file formats: https://docs.groupdocs.com/redaction/java/supported-document-formats/
final Redactor redactor = new Redactor("sample.pdf");
try
{
redactor.apply(new ExactPhraseRedaction("John Doe", true /*isCaseSensitive*/, new ReplacementOptions("[personal]")));
redactor.save();
}
finally { redactor.close(); }
@GroupDocsGists
GroupDocsGists / redact_exact_phrase.java
Last active Apr 29, 2022
Textual Redaction via Exact Phrase using Java
View redact_exact_phrase.java
//Supported file formats: https://docs.groupdocs.com/redaction/java/supported-document-formats/
final Redactor redactor = new Redactor("sample.pdf");
try
{
redactor.apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
redactor.save();
}
finally { redactor.close(); }
@GroupDocsGists
GroupDocsGists / PageOrientationLandscape.java
Last active Apr 10, 2022
Change Orientation of Word Document in Java
View PageOrientationLandscape.java
// How to change page orientation of Word document to Landscape in Java
OrientationOptions orientationOptions = new OrientationOptions(OrientationMode.Landscape, new int[] { 1, 2 });
Merger merger = new Merger("path/document.docx");
merger.changeOrientation(orientationOptions);
merger.save("path/orientation-landscape-document.docx");
@GroupDocsGists
GroupDocsGists / RemoveAllWatermark.java
Last active Apr 9, 2022
Remove watermarks from PDF File and other documents in Java
View RemoveAllWatermark.java
// Remove the watermarks from PDF & other Documents in Java
Watermarker watermarker = new Watermarker("filepath/document-with-watermarks.pdf");
PossibleWatermarkCollection possibleWatermarks = watermarker.search();
for (int i = 0 ; i < watermarks.getCount(); i++)
{
// Remove every watermark by mentioning the index within the document.
possibleWatermarks.removeAt(i);
}
watermarker.save("filepath/no-watermarks.pdf");
@GroupDocsGists
GroupDocsGists / EditExcelSheets.java
Last active Apr 4, 2022
How to Edit Excel Spreadsheets in Java
View EditExcelSheets.java
// Edit the Excel XLS/XLSX documents in Java
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setPassword("password-if-any");
// Loading Spreadsheet
Editor editor = new Editor("path/sample_sheet.xlsx", loadOptions);
// Edit 1st tab of the Spreadsheet
SpreadsheetEditOptions editOptions = new SpreadsheetEditOptions();
editOptions.setWorksheetIndex(0); // index is 0-based, so this is 1st tab
@GroupDocsGists
GroupDocsGists / EditWordDocument.java
Last active Apr 3, 2022
How to Edit Word Document in Java
View EditWordDocument.java
// Edit the Word DOC/DOCX documents in Java
Options.WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
loadOptions.setPassword("password-if-any");
Editor editor = new Editor("path/document.docx", loadOptions);
EditableDocument defaultWordProcessingDoc = editor.edit();
// Either edit using any WYSIWYG editor or edit programmatically
String allEmbeddedInsideString = defaultWordProcessingDoc.getEmbeddedHtml();
String allEmbeddedInsideStringEdited = allEmbeddedInsideString.replace("document", "edited document");
@GroupDocsGists
GroupDocsGists / PdfToJpgGrayscale.java
Last active Mar 25, 2022
Convert Document to Grayscale Images in Java
View PdfToJpgGrayscale.java
// Convert PDF to Grayscale PNG in Java
Converter converter = new Converter("path/document.pdf");
ImageConvertOptions options = new ImageConvertOptions();
options.setFormat(ImageFileType.Jpg);
options.setGrayscale(true);
/*
options.setFlipMode(ImageFlipModes.FlipY);
options.setBrightness(50);
options.setContrast(50);