Skip to content

Instantly share code, notes, and snippets.

Avatar

GroupDocs GroupDocsGists

View GitHub Profile
@GroupDocsGists
GroupDocsGists / AddTextWatermarkToJPG.java
Last active Sep 12, 2020
Add Text Watermark to Images using Java (JPG , PNG)
View AddTextWatermarkToJPG.java
// Add Text Watermark to JPG using Java
TextWatermark watermark = new TextWatermark("GroupDocs", new Font("Arial", 30, FontStyle.Bold | FontStyle.Italic));
// Set Watermark properties
watermark.setForegroundColor(Color.getRed());
watermark.setTextAlignment(TextAlignment.Right);
watermark.setOpacity(0.4);
watermark.setX(70);
watermark.setY(130);
@GroupDocsGists
GroupDocsGists / ConvertEmlToPdf.java
Created Aug 26, 2020
Convert MSG and EML to PDF in Java
View ConvertEmlToPdf.java
// Convert EML message to PDF
public void convertEmltoPDF(String filePath)
{
Converter converter = new Converter(filePath + "emailMessage.eml");
PdfConvertOptions options = new PdfConvertOptions();
converter.convert(filePath + "eml-Message.pdf", options);
}
View DynamicBookmarkInsertionWord.cs
//setting up source
const String strDocumentTemplate = "Word Templates/Dynamic bookmarks.docx";
//Setting up destination
const String strDocumentReport = "Word Reports/Dynamic bookmarks.docx";
//Setting up Uri Expression
const String bookmark_expression = "gd_bookmark";
//Setting up Display Text Expression
const String displayTextExpression = "GroupDocs";
try
{
View PasswordProtection.cs
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET
public override void Load(System.IO.Stream input)
{
try
{
// check security and load document
SetAccessGranted(true);
}
catch (SomeSecurityException)
View DocumentFormatInstanceUsage.cs
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET
var config = RedactorConfiguration.GetInstance();
config.AvailableFormats.Add(new DocumentFormatConfiguration()
{
ExtensionFilter = ".log",
DocumentType = typeof(PlainTextDocument)
});
View DocumentFormatInstance .cs
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET
public class PlainTextDocument : DocumentFormatInstance, ITextualFormatInstance
{
private RedactorSettings Settings { get; set; }
private List<string> FileContent { get; set; }
public PlainTextDocument()
{
FileContent = new List<string>();
}
View ExtendSupportedExtensionList.cs
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET
var config = RedactorConfiguration.GetInstance();
var docxSettings = config.FindFormat(".docx");
docxSettings.ExtensionFilter = docxSettings.ExtensionFilter + ",.log";
using (Redactor redactor = new Redactor(@"C:\sample.log"))
{
// Here we can use document instance to perform redactions
}
View CustomLoggerUsage.cs
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET
using (Stream stream = File.Open(@"sample.docx", FileMode.Open, FileAccess.ReadWrite))
{
var logger = new CustomLogger();
using (Redactor redactor = new Redactor(stream, new LoadOptions(), new RedactorSettings(logger)))
{
// Here we can use document instance to make redactions
redactor.Apply(new DeleteAnnotationRedaction());
if (!logger.HasErrors)
{
View CustomLogger.cs
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET
using GroupDocs.Redaction.Options;
/// <summary>
/// This is an example of ILogger implementation, tracking count of error messages.
/// </summary>
public class CustomLogger : ILogger
{
public List<string> Errors { get; private set; }
public List<string> Traces { get; private set; }
public List<string> Warnings { get; private set; }
View RedactionPoliciesUsage.cs
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET
RedactionPolicy policy = RedactionPolicy.Load("RedactionPolicy.xml");
foreach (var fileEntry in Directory.GetFileNames("C:\\Inbound"))
{
using (Redactor redactor = new Redactor(Path.Combine("C:\\Inbound\\", fileEntry)))
{
RedactorChangeLog result = redactor.Apply(policy);
String resultFolder = result.Status != RedactionStatus.Failed ? "C:\\Outbound\\Done\\" : "C:\\Outbound\\Failed\\";
using (Stream fileStream = File.Open(Path.Combine(resultFolder, fileEntry), FileMode.Open, FileAccess.ReadWrite))
{
You can’t perform that action at this time.