static void Main(string[] args) { PDFNet.Initialize(); try { using (PDFDoc doc = new PDFDoc()) using (ElementWriter writer = new ElementWriter()) using (ElementBuilder eb = new ElementBuilder()) { // The following sample illustrates how to create and use tiling patterns Page page = doc.PageCreate(); writer.Begin(page); Element element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_bold), 1); writer.WriteElement(element); // Begin the text block element = eb.CreateTextRun("G"); element.SetTextMatrix(720, 0, 0, 720, 20, 240); GState gs = element.GetGState(); gs.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text); gs.SetLineWidth(4); // Set the fill color space to the Pattern color space. gs.SetFillColorSpace(ColorSpace.CreatePattern()); gs.SetFillColor(CreateTilingPattern(doc)); writer.WriteElement(element); writer.WriteElement(eb.CreateTextEnd()); // Finish the text block writer.End(); // Save the page doc.PagePushBack(page); //----------------------------------------------- /// The following sample illustrates how to create and use image tiling pattern page = doc.PageCreate(); writer.Begin(page); eb.Reset(); element = eb.CreateRect(0, 0, 612, 794); // Set the fill color space to the Pattern color space. gs = element.GetGState(); gs.SetFillColorSpace(ColorSpace.CreatePattern()); gs.SetFillColor(CreateImageTilingPattern(doc)); element.SetPathFill(true); writer.WriteElement(element); writer.End(); // Save the page doc.PagePushBack(page); //----------------------------------------------- /// The following sample illustrates how to create and use PDF shadings page = doc.PageCreate(); writer.Begin(page); eb.Reset(); element = eb.CreateRect(0, 0, 612, 794); // Set the fill color space to the Pattern color space. gs = element.GetGState(); gs.SetFillColorSpace(ColorSpace.CreatePattern()); gs.SetFillColor(CreateAxialShading(doc)); element.SetPathFill(true); writer.WriteElement(element); writer.End(); // save the page doc.PagePushBack(page); //----------------------------------------------- doc.Save(output_path + "patterns.pdf", SDFDoc.SaveOptions.e_remove_unused); Console.WriteLine("Done. Result saved in patterns.pdf..."); } } catch (PDFNetException e) { Console.WriteLine(e.Message); } }