View CountWordInDocuments.java
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
// 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); | |
} |
View RemoveListedPdfPages.java
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
// 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"); |
View redact_text_using_color_box.java
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
// 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(); | |
} |
View case_sensitive_redaction.java
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
// 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(); } |
View redact_exact_phrase.java
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
//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(); } |
View PageOrientationLandscape.java
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
// 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"); |
View RemoveAllWatermark.java
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
// 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"); |
View EditExcelSheets.java
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
// 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 |
View EditWordDocument.java
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
// 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"); |
View PdfToJpgGrayscale.java
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
// 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); |
NewerOlder