Skip to content

Instantly share code, notes, and snippets.

View conholdate-docs-gists's full-sized avatar

conholdate-docs-gists

View GitHub Profile
// Constants.InputXlsx is an absolute or relative path to your document. Ex: @"C:\Docs\source.xlsx"
using (Metadata metadata = new Metadata(Constants.InputXlsx))
{
if (metadata.FileFormat != FileFormat.Unknown)
{
IDocumentInfo info = metadata.GetDocumentInfo();
Console.WriteLine("File format: {0}", info.FileType.FileFormat);
Console.WriteLine("File extension: {0}", info.FileType.Extension);
Console.WriteLine("MIME Type: {0}", info.FileType.MimeType);
Console.WriteLine("Number of pages: {0}", info.PageCount);
// Constants.InputPptx is an absolute or relative path to your document. Ex: @"C:\Docs\source.pptx"
using (Metadata metadata = new Metadata(Constants.InputPptx))
{
// Fetch all the properties satisfying the predicate:
// property contains the name of the last document editor OR the date/time the document was last modified
var properties = metadata.FindProperties(p => p.Tags.Contains(Tags.Person.Editor) || p.Tags.Contains(Tags.Time.Modified));
foreach (var property in properties)
{
Console.WriteLine("Property name: {0}, Property value: {1}", property.Name, property.Value);
using (Metadata metadata = new Metadata(Constants.InputPdf))
{
// Remove detected metadata packages
var affected = metadata.Sanitize();
Console.WriteLine("Properties removed: {0}", affected);
metadata.Save(Constants.OutputPdf);
}
// Constants.InputVsdx is an absolute or relative path to your document. Ex: @"C:\Docs\source.vsdx"
using (Metadata metadata = new Metadata(Constants.InputVsdx))
{
// Set the value of each property that satisfies the predicate:
// property contains the date/time the document was created OR modified
var affected = metadata.SetProperties(
p => p.Tags.Contains(Tags.Time.Created) || p.Tags.Contains(Tags.Time.Modified),
new PropertyValue(DateTime.Now));
Console.WriteLine("Properties set: {0}", affected);
metadata.Save(Constants.OutputVsdx);
using (Viewer viewer = new Viewer("sample.docx"))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
viewOptions.Minify = true;
viewer.View(viewOptions);
}
TiffImageLoadOptions loadOptions = new TiffImageLoadOptions();
// Constants.InImageTiff is an absolute or relative path to your document. Ex: @"C:\Docs\image.tiff"
using (Watermarker watermarker = new Watermarker(Constants.InImageTiff, loadOptions))
{
// Initialize text or image watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
// Add watermark to the first frame
TiffImageWatermarkOptions options = new TiffImageWatermarkOptions();
options.FrameIndex = 0;
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf"
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf))
{
PossibleWatermarkCollection watermarks = watermarker.Search(new TextSearchCriteria(new Regex(@"someurl\.com")));
for (int i = watermarks.Count - 1; i >= 0; i--)
{
// Ensure that only hyperlinks will be removed.
if (watermarks[i] is HyperlinkPossibleWatermark)
{
// Output the full url of the hyperlink
// Constants.InImagePng is an absolute or relative path to your document. Ex: @"C:\Docs\image.png"
using (Watermarker watermarker = new Watermarker(Constants.InImagePng))
{
// Initialize the font to be used for watermark
Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic);
// Create the watermark object
TextWatermark watermark = new TextWatermark("Test watermark", font);
// Set watermark properties
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
EmailLoadOptions loadOptions = new EmailLoadOptions();
// Constants.InMessageMsg is an absolute or relative path to your document. Ex: @"C:\Docs\message.msg"
using (Watermarker watermarker = new Watermarker(Constants.InMessageMsg, loadOptions))
{
EmailContent content = watermarker.GetContent<EmailContent>();
foreach (EmailAttachment attachment in content.Attachments)
{
// Check if the attached file is supported by GroupDocs.Watermark
IDocumentInfo info = attachment.GetDocumentInfo();
PdfLoadOptions loadOptions = new PdfLoadOptions();
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf"
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf, loadOptions))
{
PdfAnnotationWatermarkOptions options = new PdfAnnotationWatermarkOptions();
// Add text watermark
TextWatermark textWatermark = new TextWatermark("This is a annotation watermark", new Font("Arial", 8));
textWatermark.HorizontalAlignment = HorizontalAlignment.Left;
textWatermark.VerticalAlignment = VerticalAlignment.Top;
watermarker.Add(textWatermark, options);