//
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
//
using System;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;
namespace ElementBuilderTestCS
{
///
/// Summary description for Class1.
///
class Class1
{
private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
static Class1() { }
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
PDFNet.Initialize();
// Relative path to the folder containing test files.
string input_path = "../../../../TestFiles/";
string output_path = "../../../../TestFiles/Output/";
try
{
using (PDFDoc doc = new PDFDoc(input_path + "newsletter.pdf"))
using (ElementBuilder builder = new ElementBuilder())
using (ElementWriter writer = new ElementWriter())
{
doc.InitSecurityHandler();
Page page = doc.GetPage(1);
writer.Begin(page, ElementWriter.WriteMode.e_overlay);
builder.PathBegin();
// draw rectangle
builder.MoveTo(200, 500);
builder.LineTo(500, 500);
builder.LineTo(500, 300);
builder.LineTo(200, 300);
builder.LineTo(200, 500);
// draw cutout
builder.MoveTo(400, 400);
builder.CurveTo(400, 427.614, 377.614, 450, 350, 450);
builder.CurveTo(322.386, 450, 300, 427.614, 300, 400);
builder.CurveTo(300, 372.386, 322.386, 350, 350, 350);
builder.CurveTo(377.614, 350, 400, 372.386, 400, 400);
// add additional cutouts here
// ..
Element element = builder.PathEnd();
element.SetWindingFill(false); // Important! to get the cutouts correct
element.SetPathStroke(false);
element.SetPathFill(true);
GState gs = element.GetGState();
gs.SetFillColorSpace(ColorSpace.CreateDeviceCMYK());
gs.SetFillColor(new ColorPt(1, 0, 0, 0)); // cyan
writer.WriteElement(element);
writer.End();
doc.Save(output_path + "clipping.pdf", SDFDoc.SaveOptions.e_linearized);
}
}
catch (PDFNetException e)
{
Console.WriteLine(e.Message);
}
}
}
}