private FormXObject CreateWatermark(Document document) { SKSize size = document.GetSize(); // 1. Create an external form object to represent the watermark! FormXObject watermark = new FormXObject(document, size); // 2. Inserting the contents of the watermark... // 2.1. Create a content composer! PrimitiveComposer composer = new PrimitiveComposer(watermark); // 2.2. Inserting the contents... // Set the font to use! composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, true, false), 120); // Set the color to fill the text characters! composer.SetFillColor(new DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d)); // Apply transparency! { ExtGState state = new ExtGState(document); state.FillAlpha = .3; composer.ApplyState(state); } // Show the text! composer.ShowText( "PdfClown", // Text to show. new SKPoint(size.Width / 2f, size.Height / 2f), // Anchor location: page center. XAlignmentEnum.Center, // Horizontal placement (relative to the anchor): center. YAlignmentEnum.Middle, // Vertical placement (relative to the anchor): middle. 50 // Rotation: 50-degree-counterclockwise. ); // 2.3. Flush the contents into the watermark! composer.Flush(); return(watermark); }
private void exportPDFProcess(string filename, FPDFSave dialog) { org.pdfclown.files.File file = new org.pdfclown.files.File(); org.pdfclown.documents.Document document = file.Document; Page page; Stream stream; org.pdfclown.documents.contents.entities.JpegImage currentImage; int i = 1; foreach (CScannedImage img in images.Values) { ThreadStart setstatus = delegate { dialog.SetStatus(i, images.Count); }; dialog.Invoke(setstatus); Size pageSize = new Size((int)(img.BaseImage.Width / img.BaseImage.HorizontalResolution * 72), (int)(img.BaseImage.Height / img.BaseImage.VerticalResolution * 72)); PointF point = new PointF(0, 0); Resources resources = new Resources(document); //page = new Page(document,pageSize,resources); page = new Page(document); document.Pages.Add(page); stream = new MemoryStream(); img.BaseImage.Save(stream, ImageFormat.Jpeg); PrimitiveComposer composer = new PrimitiveComposer(page); currentImage = new org.pdfclown.documents.contents.entities.JpegImage(stream); composer.ShowXObject(currentImage.ToXObject(document), point, pageSize); stream.Flush(); composer.Flush(); i++; } file.Save(filename, SerializationModeEnum.Standard); dialog.Invoke(new ThreadStart(dialog.Close)); }
private void BuildContent( Document document ) { // Set default page size (A4)! document.PageSize = PageFormat.GetSize(); // Add a font to the fonts collection! document.Resources.Fonts[ResourceName_DefaultFont] = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); // Add a page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // Create a content composer for the page content stream! PrimitiveComposer composer = new PrimitiveComposer(page); string[] steps = new string[5]; colorSpaces::Color[] colors = new colorSpaces::Color[5]; SizeF pageSize = page.Size; BuildSteps(composer, steps, colors, pageSize); BuildLegend(composer, steps, colors, pageSize); composer.Flush(); }
private void Populate(Document document) { PdfType1Font bodyFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false); Pages pages = document.Pages; PageFormat.SizeEnum[] pageFormats = (PageFormat.SizeEnum[])Enum.GetValues(typeof(PageFormat.SizeEnum)); PageFormat.OrientationEnum[] pageOrientations = (PageFormat.OrientationEnum[])Enum.GetValues(typeof(PageFormat.OrientationEnum)); foreach (PageFormat.SizeEnum pageFormat in pageFormats) { foreach (PageFormat.OrientationEnum pageOrientation in pageOrientations) { // Add a page to the document! Page page = new Page(document, PageFormat.GetSize(pageFormat, pageOrientation)); // Instantiates the page inside the document context. pages.Add(page); // Puts the page in the pages collection. // Drawing the text label on the page... SKSize pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); composer.SetFont(bodyFont, 32); composer.ShowText( pageFormat + " (" + pageOrientation + ")", // Text. new SKPoint( pageSize.Width / 2, pageSize.Height / 2 ), // Location: page center. XAlignmentEnum.Center, // Places the text on horizontal center of the location. YAlignmentEnum.Middle, // Places the text on vertical middle of the location. 45 // Rotates the text 45 degrees counterclockwise. ); composer.Flush(); } } }
public void Gerar() { if (_FoiGerado) { throw new InvalidOperationException("O Danfe já foi gerado."); } var identificacaoEmitente = new BlocoIdentificacaoEmitenteNFC(ViewModel, EstiloPadrao, _primitiveComposer); var tableProdutos = new TabelaProdutosServicosNFC(ViewModel, EstiloPadrao, _primitiveComposer, identificacaoEmitente.Y_NFC); var produtoServicoTotal = new BlocoProdutoServicoTotalNFC(ViewModel, EstiloPadrao, _primitiveComposer, tableProdutos.Y_NFC); var formaPagamento = new BlocoFormaPagamentoNFC(ViewModel, EstiloPadrao, _primitiveComposer, produtoServicoTotal.Y_NFC); var informacaoFiscal = new BlocoInformacaoFiscal(ViewModel, EstiloPadrao, _primitiveComposer, formaPagamento.Y_NFC); var consultaChave = new BlocoConsultaChaveNFC(ViewModel, EstiloPadrao, _primitiveComposer, informacaoFiscal.Y_NFC); var destinatarioRemetente = new BlocoDestinatarioRemetenteNFC(ViewModel, EstiloPadrao, _primitiveComposer, consultaChave.Y_NFC); var identificacaoNFC = new BlocoIdentificacaoNFC(ViewModel, EstiloPadrao, _primitiveComposer, destinatarioRemetente.Y_NFC); var qrCodeNFC = new BlocoQrCodeNFC(ViewModel, EstiloPadrao, _primitiveComposer, identificacaoNFC.Y_NFC, PdfDocument); // 4. Flush the contents into the page! _primitiveComposer.Flush(); _FoiGerado = true; }
/// <summary> /// Renderiza o bloco para um XObject. /// </summary> public virtual org.pdfclown.documents.contents.xObjects.XObject ToXObject() { if (_RenderedObject == null) { _RenderedObject = new org.pdfclown.documents.contents.xObjects.FormXObject(Danfe.Document, Size); PrimitiveComposer composer = new PrimitiveComposer(_RenderedObject); var obj = composer.BeginLocalState(); composer.SetLineWidth(DanfeDocumento.LineWidth); if (PossuiCabecalho) { RectangleF rect = GetHeaderInnerRectangle(); //Danfe.PrintCabecalhoBloco2(composer, rect.Top, rect.Left, rect.Width, Cabecalho); PrintCabecalho(composer); } ToXObjectInternal(composer); foreach (var campo in Campos) { campo.Print(composer, Danfe.Font, Danfe.FontBold); } composer.Stroke(); composer.End(); composer.Flush(); } return(_RenderedObject); }
private void ImagesToPdf(CancellationToken token) { using (org.pdfclown.files.File file = new org.pdfclown.files.File()) { var images = Directory.GetFiles(imageTempDir, "*.jpg"); for (int index = 0; index < images.Length; index++) { using (var steam = new FileStream($"{imageTempDir}\\output_{index}.jpg", FileMode.Open)) { var image = org.pdfclown.documents.contents.entities.Image.Get(steam); var size = new SizeF(image.Width, image.Height); Page page = new Page(file.Document, size); file.Document.Pages.Add(page); PrimitiveComposer primitiveComposer = new PrimitiveComposer(page); primitiveComposer.ShowXObject(image.ToXObject(file.Document), new PointF(0, 0), size); primitiveComposer.Flush(); } } if (token.IsCancellationRequested) { ClearTempImages(); token.ThrowIfCancellationRequested(); } file.Save(outputFile, SerializationModeEnum.Standard); } ClearTempImages(); }
private void BuildContent(Document document) { // Set default page size (A4)! document.PageSize = PageFormat.GetSize(); // Add a font to the fonts collection! document.Resources.Fonts[ResourceName_DefaultFont] = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); // Add a page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // Create a content composer for the page content stream! PrimitiveComposer composer = new PrimitiveComposer(page); string[] steps = new string[5]; colorSpaces::Color[] colors = new colorSpaces::Color[5]; SKSize pageSize = page.Size; BuildSteps(composer, steps, colors, pageSize); BuildLegend(composer, steps, colors, pageSize); composer.Flush(); }
private void Apply( ComboBox field ) { Document document = field.Document; Widget widget = field.Widgets[0]; Appearance appearance = widget.Appearance; if (appearance == null) { widget.Appearance = appearance = new Appearance(document); } widget.BaseDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg"); FormXObject normalAppearanceState; { SizeF size = widget.Box.Size; normalAppearanceState = new FormXObject(document, size); PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState); float lineWidth = 1; RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); if (GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } composer.BeginMarkedContent(PdfName.Tx); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Helvetica, false, false ), FontSize ); composer.ShowText( (string)field.Value, new PointF(0, size.Height / 2), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.End(); composer.Flush(); } appearance.Normal[null] = normalAppearanceState; }
private void Apply( PushButton field ) { Document document = field.Document; Widget widget = field.Widgets[0]; Appearance appearance = widget.Appearance; if (appearance == null) { widget.Appearance = appearance = new Appearance(document); } FormXObject normalAppearanceState; { SizeF size = widget.Box.Size; normalAppearanceState = new FormXObject(document, size); PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState); float lineWidth = 1; RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); if (GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } string title = (string)field.Value; if (title != null) { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle); composer.SetFillColor(ForeColor); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Helvetica, true, false ), size.Height * 0.5 ); blockComposer.ShowText(title); blockComposer.End(); } composer.Flush(); } appearance.Normal[null] = normalAppearanceState; }
public void Flush( ) { // Ensuring that there's room for the new content chunks inside the page's content stream... /* * NOTE: This specialized stamper is optimized for content insertion without modifying * existing content representations, leveraging the peculiar feature of page structures * to express their content streams as arrays of data streams. */ PdfArray streams; { PdfDirectObject contentsObject = page.BaseDataObject[PdfName.Contents]; PdfDataObject contentsDataObject = File.Resolve(contentsObject); // Single data stream? if (contentsDataObject is PdfStream) { /* * NOTE: Content stream MUST be expressed as an array of data streams in order to host * background- and foreground-stamped contents. */ streams = new PdfArray(); streams.Add(contentsObject); page.BaseDataObject[PdfName.Contents] = streams; page.Update(); // Fundamental to override original page contents collection. } else { streams = (PdfArray)contentsDataObject; if (!File.Update(contentsObject)) { page.Update(); } // Fundamental to override original page contents collection. } } // Background. // Serialize the content! background.Flush(); // Insert the serialized content into the page's content stream! streams.Insert( 0, (PdfReference)background.Scanner.Contents.BaseObject ); // Foreground. // Serialize the content! foreground.Flush(); // Append the serialized content into the page's content stream! streams.Add( (PdfReference)foreground.Scanner.Contents.BaseObject ); }
/** * <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); colors::Color textColor = new colors::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d); composer.SetFillColor(textColor); composer.SetLineDash(new LineDash(new double[] { 10 })); composer.SetLineWidth(.25); BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(300, 400, 200, 100), XAlignmentEnum.Left, YAlignmentEnum.Middle); composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, true), 12); blockComposer.ShowText("PrimitiveComposer.ShowText(...) methods return the actual bounding box of the text shown, allowing to precisely determine its location on the page."); blockComposer.End(); // 3. Inserting contents... // Set the font to use! composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false), 72); composer.DrawPolygon( composer.ShowText( "Text frame", new PointF(150, 360), XAlignmentEnum.Left, YAlignmentEnum.Middle, 45 ).Points ); composer.Stroke(); composer.SetFont(fonts::Font.Get(document, GetResourcePath("fonts" + System.IO.Path.DirectorySeparatorChar + "Ruritania-Outline.ttf")), 102); composer.DrawPolygon( composer.ShowText( "Text frame", new PointF(250, 600), XAlignmentEnum.Center, YAlignmentEnum.Middle, -25 ).Points ); composer.Stroke(); // 4. Flush the contents into the page! composer.Flush(); }
public override void Run( ) { // 1. Instantiate the source PDF file! string filePath = PromptFileChoice("Please select a PDF file to use as source"); using (var sourceFile = new File(filePath)) { // 2. Instantiate a new PDF file! File file = new File(); // 3. Source page combination into target file. Document document = file.Document; Pages pages = document.Pages; int pageIndex = -1; PrimitiveComposer composer = null; SizeF targetPageSize = PageFormat.GetSize(PageFormat.SizeEnum.A4); foreach (Page sourcePage in sourceFile.Document.Pages) { pageIndex++; int pageMod = pageIndex % 2; if (pageMod == 0) { if (composer != null) { composer.Flush(); } // Add a page to the target document! Page page = new Page( document, PageFormat.GetSize(PageFormat.SizeEnum.A3, PageFormat.OrientationEnum.Landscape) ); // Instantiates the page inside the document context. pages.Add(page); // Puts the page in the pages collection. // Create a composer for the target content stream! composer = new PrimitiveComposer(page); } // Add the form to the target page! composer.ShowXObject( sourcePage.ToXObject(document), // Converts the source page into a form inside the target document. new PointF(targetPageSize.Width * pageMod, 0), targetPageSize, XAlignmentEnum.Left, YAlignmentEnum.Top, 0 ); } composer.Flush(); // 4. Serialize the PDF file! Serialize(file, "Page combination", "combining multiple pages into single bigger ones", "page combination"); } }
public override xObjects::XObject ToXObject(Document context) { xObjects::FormXObject xObject = new xObjects::FormXObject(context, Size); { PrimitiveComposer composer = new PrimitiveComposer(xObject); this.ToInlineObject(composer); composer.Flush(); } return(xObject); }
public org.pdfclown.documents.contents.xObjects.XObject ToXObject(org.pdfclown.documents.Document context) { var xObject = new org.pdfclown.documents.contents.xObjects.FormXObject(context, Size); PrimitiveComposer composer = new PrimitiveComposer(xObject); this.ToInlineObject(composer); composer.Flush(); return(xObject); }
/** * <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Inserting contents... // Set the font to use! composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 30); // Show the text onto the page (along with its box)! /* * NOTE: PrimitiveComposer's ShowText() method is the most basic way to add text to a page * -- see BlockComposer for more advanced uses (horizontal and vertical alignment, hyphenation, * etc.). */ composer.ShowText( "Hello World!", new PointF(32, 48) ); composer.SetLineWidth(.25); composer.SetLineCap(LineCapEnum.Round); composer.SetLineDash(new LineDash(new double[] { 5, 10 })); composer.SetTextLead(1.2); composer.DrawPolygon( composer.ShowText( "This is a primitive example" + "\nof centered, rotated multi-" + "\nline text." + "\n\nWe recommend you to use" + "\nBlockComposer instead, as it" + "\nautomatically manages text" + "\nwrapping and alignment with-" + "\nin a specified area!", new PointF(pageSize.Width / 2, pageSize.Height / 2), XAlignmentEnum.Center, YAlignmentEnum.Middle, 15 ).Points ); composer.Stroke(); // 4. Flush the contents into the page! composer.Flush(); }
/// <summary> /// Imprime o cabeçalho do bloco. /// </summary> private void PrintCabecalho(PrimitiveComposer comp) { BlockComposer bComp = new BlockComposer(comp); RectangleF rect = new RectangleF(0, 0, Size.Width, Danfe.CabecalhoBlocoAltura); rect = rect.GetPaddedRectangleMm(0, 0, 1, 0.3F); comp.SetFont(Danfe.FontBold, 5); bComp.SafeBegin(rect, XAlignmentEnum.Left, YAlignmentEnum.Bottom); bComp.ShowText(Cabecalho.ToUpper()); bComp.End(); comp.Flush(); }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Hyphenation = true; blockComposer.Begin( new RectangleF( Margin, Margin, (float)pageSize.Width - Margin * 2, (float)pageSize.Height - Margin * 2 ), XAlignmentEnum.Justify, YAlignmentEnum.Top ); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont, 32); blockComposer.ShowText("Inline image sample"); blockComposer.ShowBreak(); composer.SetFont(bodyFont, 16); blockComposer.ShowText("Showing the GNU logo as an inline image within the page content stream."); blockComposer.End(); } // Showing the 'GNU' image... { // Instantiate a jpeg image object! entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")); // Abstract image (entity). // Set the position of the image in the page! composer.ApplyMatrix(200, 0, 0, 200, (pageSize.Width - 200) / 2, (pageSize.Height - 200) / 2); // Show the image! image.ToInlineObject(composer); // Transforms the image entity into an inline image within the page. } composer.Flush(); }
private void Populate( Document document ) { StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); Pages pages = document.Pages; PageFormat.SizeEnum[] pageFormats = (PageFormat.SizeEnum[])Enum.GetValues(typeof(PageFormat.SizeEnum)); PageFormat.OrientationEnum[] pageOrientations = (PageFormat.OrientationEnum[])Enum.GetValues(typeof(PageFormat.OrientationEnum)); foreach(PageFormat.SizeEnum pageFormat in pageFormats) { foreach(PageFormat.OrientationEnum pageOrientation in pageOrientations) { // Add a page to the document! Page page = new Page( document, PageFormat.GetSize( pageFormat, pageOrientation ) ); // Instantiates the page inside the document context. pages.Add(page); // Puts the page in the pages collection. // Drawing the text label on the page... SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); composer.SetFont(bodyFont,32); composer.ShowText( pageFormat + " (" + pageOrientation + ")", // Text. new PointF( pageSize.Width / 2, pageSize.Height / 2 ), // Location: page center. XAlignmentEnum.Center, // Places the text on horizontal center of the location. YAlignmentEnum.Middle, // Places the text on vertical middle of the location. 45 // Rotates the text 45 degrees counterclockwise. ); composer.Flush(); } } }
public void Renderizar(int pagina, int nPaginas) { PosicionarBlocos(); foreach (var bloco in BlocosSuperiores.Union(BlocosInferiores)) { _Composer.ShowXObject(bloco.ToXObject(), bloco.Posicao); } PrintNumeroFolhas(pagina, nPaginas); if (_Danfe.Model.TipoAmbiente != 1) { PrintMarcaDAgua("SEM VALOR FISCAL"); } PrintCreditos(); _Composer.Flush(); }
/** * <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Inserting contents... // Set the font to use! composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); // Show the text onto the page! /* * NOTE: PrimitiveComposer's ShowText() method is the most basic way to add text to a page * -- see BlockComposer for more advanced uses (horizontal and vertical alignment, hyphenation, * etc.). */ composer.ShowText( "Hello World!", new PointF(32, 48) ); // 4. Flush the contents into the page! composer.Flush(); }
/** <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Inserting contents... // Set the font to use! composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); // Show the text onto the page! /* NOTE: PrimitiveComposer's ShowText() method is the most basic way to add text to a page -- see BlockComposer for more advanced uses (horizontal and vertical alignment, hyphenation, etc.). */ composer.ShowText( "Hello World!", new PointF(32,48) ); // 4. Flush the contents into the page! composer.Flush(); }
private void BuildTextBlockPage2( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int stepCount = 5; int step = (int)(pageSize.Height) / (stepCount + 1); BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width - 60, step * .8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block line alignment"); blockComposer.End(); } // Drawing the text block... { fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); entities::Image sampleImage = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "gnu.jpg")); xObjects::XObject sampleImageXObject = sampleImage.ToXObject(document); IList <LineAlignmentEnum> lineAlignments = new List <LineAlignmentEnum>((LineAlignmentEnum[])Enum.GetValues(typeof(LineAlignmentEnum))); float frameHeight = (pageSize.Height - 130 - 5 * lineAlignments.Count * 2) / (lineAlignments.Count * 2); float frameWidth = (pageSize.Width - 60 - 5 * lineAlignments.Count) / lineAlignments.Count; int imageSize = 7; for (int index = 0, length = lineAlignments.Count; index < length; index++) { LineAlignmentEnum lineAlignment = lineAlignments[index]; for (int imageIndex = 0, imageLength = lineAlignments.Count; imageIndex < imageLength; imageIndex++) { LineAlignmentEnum imageAlignment = lineAlignments[imageIndex]; for (int index2 = 0, length2 = 2; index2 < length2; index2++) { RectangleF frame = new RectangleF( 30 + (frameWidth + 5) * imageIndex, 100 + (frameHeight + 5) * (index * 2 + index2), frameWidth, frameHeight ); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top); { composer.SetFont(mainFont, 3); blockComposer.ShowText("Text: " + lineAlignment); blockComposer.ShowBreak(); blockComposer.ShowText("Image: " + imageAlignment); } blockComposer.End(); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Middle); { composer.SetFont(sampleFont, 3); blockComposer.ShowText("Previous row boundary."); blockComposer.ShowBreak(); composer.SetFont(sampleFont, index2 == 0 ? 3 : 6); blockComposer.ShowText("Alignment:"); composer.SetFont(sampleFont, index2 == 0 ? 6 : 3); blockComposer.ShowText(" aligned to " + lineAlignment + " ", lineAlignment); blockComposer.ShowXObject(sampleImageXObject, new SizeF(imageSize, imageSize), imageAlignment); blockComposer.ShowBreak(); composer.SetFont(sampleFont, 3); blockComposer.ShowText("Next row boundary."); } blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[] { 1, 4 }, 4)); composer.DrawRectangle(blockComposer.Frame); composer.Stroke(); } composer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[] { 1, 1 }, 1)); composer.DrawRectangle(blockComposer.BoundBox); composer.Stroke(); } composer.End(); } } } } // 4. Flush the contents into the page! composer.Flush(); }
private void BuildMiscellaneousPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(30, 0, pageSize.Width - 60, 50), XAlignmentEnum.Center, YAlignmentEnum.Middle); blockComposer.ShowText("Miscellaneous"); blockComposer.End(); } composer.BeginLocalState(); composer.SetLineJoin(LineJoinEnum.Round); composer.SetLineCap(LineCapEnum.Round); // 3.1. Polygon. composer.DrawPolygon( new PointF[] { new PointF(100, 200), new PointF(150, 150), new PointF(200, 150), new PointF(250, 200) } ); // 3.2. Polyline. composer.DrawPolyline( new PointF[] { new PointF(300, 200), new PointF(350, 150), new PointF(400, 150), new PointF(450, 200) } ); composer.Stroke(); // 3.3. Rectangle (both squared and rounded). int x = 50; int radius = 0; while (x < 500) { if (x > 300) { composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); } composer.SetFillColor(new DeviceRGBColor(1, x / 500d, x / 500d)); composer.DrawRectangle( new RectangleF(x, 250, 150, 100), radius // NOTE: radius parameter determines the rounded angle size. ); composer.FillStroke(); x += 175; radius += 10; } composer.End(); // End local state. composer.BeginLocalState(); composer.SetFont( composer.State.Font, 12 ); // 3.4. Line cap parameter. int y = 400; foreach (LineCapEnum lineCap in (LineCapEnum[])Enum.GetValues(typeof(LineCapEnum))) { composer.ShowText( lineCap + ":", new PointF(50, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetLineWidth(12); composer.SetLineCap(lineCap); composer.DrawLine( new PointF(120, y), new PointF(220, y) ); composer.Stroke(); composer.BeginLocalState(); composer.SetLineWidth(1); composer.SetStrokeColor(DeviceRGBColor.White); composer.SetLineCap(LineCapEnum.Butt); composer.DrawLine( new PointF(120, y), new PointF(220, y) ); composer.Stroke(); composer.End(); // End local state. y += 30; } // 3.5. Line join parameter. y += 50; foreach (LineJoinEnum lineJoin in (LineJoinEnum[])Enum.GetValues(typeof(LineJoinEnum))) { composer.ShowText( lineJoin + ":", new PointF(50, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetLineWidth(12); composer.SetLineJoin(lineJoin); PointF[] points = new PointF[] { new PointF(120, y + 25), new PointF(150, y - 25), new PointF(180, y + 25) }; composer.DrawPolyline(points); composer.Stroke(); composer.BeginLocalState(); composer.SetLineWidth(1); composer.SetStrokeColor(DeviceRGBColor.White); composer.SetLineCap(LineCapEnum.Butt); composer.DrawPolyline(points); composer.Stroke(); composer.End(); // End local state. y += 50; } composer.End(); // End local state. // 3.6. Clipping. /* * NOTE: Clipping should be conveniently enclosed within a local state * in order to easily resume the unaltered drawing area after the operation completes. */ composer.BeginLocalState(); composer.DrawPolygon( new PointF[] { new PointF(220, 410), new PointF(300, 490), new PointF(450, 360), new PointF(430, 520), new PointF(590, 565), new PointF(420, 595), new PointF(460, 730), new PointF(380, 650), new PointF(330, 765), new PointF(310, 640), new PointF(220, 710), new PointF(275, 570), new PointF(170, 500), new PointF(275, 510) } ); composer.Clip(); // Showing a clown image... // Instantiate a jpeg image object! entities::Image image = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity). xObjects::XObject imageXObject = image.ToXObject(document); // Show the image! composer.ShowXObject( imageXObject, new PointF(170, 320), GeomUtils.Scale(imageXObject.Size, new SizeF(450, 0)) ); composer.End(); // End local state. // 4. Flush the contents into the page! composer.Flush(); }
private void BuildSimpleTextPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Inserting contents... // Set the font to use! composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)); YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)); int step = (int)(pageSize.Height) / ((xAlignments.Length - 1) * yAlignments.Length + 1); BlockComposer blockComposer = new BlockComposer(composer); RectangleF frame = new RectangleF( 30, 0, pageSize.Width - 60, step / 2 ); blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle); blockComposer.ShowText("Simple alignment"); blockComposer.End(); frame = new RectangleF( 30, pageSize.Height - step / 2, pageSize.Width - 60, step / 2 - 10 ); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Bottom); composer.SetFont(composer.State.Font, 10); blockComposer.ShowText( "NOTE: showText(...) methods return the actual bounding box of the text shown.\n" + "NOTE: The rotation parameter can be freely defined as a floating point value." ); blockComposer.End(); composer.SetFont(composer.State.Font, 12); int x = 30; int y = step; int alignmentIndex = 0; foreach (XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum))) { /* * NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension, * applying the justified alignment has no effect (it degrades to center alignment); * in order to get such an effect, use BlockComposer instead. */ if (xAlignment.Equals(XAlignmentEnum.Justify)) { continue; } foreach (YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum))) { if (alignmentIndex % 2 == 0) { composer.BeginLocalState(); composer.SetFillColor(BackColor); composer.DrawRectangle( new RectangleF( 0, y - step / 2, pageSize.Width, step ) ); composer.Fill(); composer.End(); } composer.ShowText( xAlignment + " " + yAlignment + ":", new PointF(x, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); y += step; alignmentIndex++; } } float rotationStep = 0; float rotation = 0; for ( int columnIndex = 0; columnIndex < 2; columnIndex++ ) { switch (columnIndex) { case 0: x = 200; rotationStep = 0; break; case 1: x = (int)pageSize.Width / 2 + 100; rotationStep = 360 / ((xAlignments.Length - 1) * yAlignments.Length - 1); break; } y = step; rotation = 0; foreach (XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum))) { /* * NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension, * applying the justified alignment has no effect (it degrades to center alignment); * in order to get such an effect, use BlockComposer instead. */ if (xAlignment.Equals(XAlignmentEnum.Justify)) { continue; } foreach (YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum))) { float startArcAngle = 0; switch (xAlignment) { case XAlignmentEnum.Left: // OK -- NOOP. break; case XAlignmentEnum.Right: case XAlignmentEnum.Center: startArcAngle = 180; break; } composer.DrawArc( new RectangleF( x - 10, y - 10, 20, 20 ), startArcAngle, startArcAngle + rotation ); DrawText( composer, "PDF Clown", new PointF(x, y), xAlignment, yAlignment, rotation ); y += step; rotation += rotationStep; } } } // 4. Flush the contents into the page! composer.Flush(); }
private void Apply( ListBox field ) { Document document = field.Document; Widget widget = field.Widgets[0]; Appearance appearance = widget.Appearance; { PdfDictionary widgetDataObject = widget.BaseDataObject; widgetDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg"); widgetDataObject[PdfName.MK] = new PdfDictionary( new PdfName[] { PdfName.BG, PdfName.BC }, new PdfDirectObject[] { new PdfArray(new PdfDirectObject[] { PdfReal.Get(.9), PdfReal.Get(.9), PdfReal.Get(.9) }), new PdfArray(new PdfDirectObject[] { PdfInteger.Default, PdfInteger.Default, PdfInteger.Default }) } ); } FormXObject normalAppearanceState; { SKSize size = widget.Box.Size; normalAppearanceState = new FormXObject(document, size); PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState); float lineWidth = 1; SKRect frame = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); if (GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } composer.BeginLocalState(); if (GraphicsVisibile) { composer.DrawRectangle(frame, 5); composer.Clip(); // Ensures that the visible content is clipped within the rounded frame. } composer.BeginMarkedContent(PdfName.Tx); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Helvetica, false, false ), FontSize ); double y = 3; foreach (ChoiceItem item in field.Items) { composer.ShowText( item.Text, new SKPoint(0, (float)y) ); y += FontSize * 1.175; if (y > size.Height) { break; } } composer.End(); composer.End(); composer.Flush(); } appearance.Normal[null] = normalAppearanceState; }
private void BuildTextBlockPage2( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int stepCount = 5; int step = (int)(pageSize.Height) / (stepCount + 1); BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width-60, step*.8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block line alignment"); blockComposer.End(); } // Drawing the text block... { fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); entities::Image sampleImage = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "gnu.jpg")); xObjects::XObject sampleImageXObject = sampleImage.ToXObject(document); IList<LineAlignmentEnum> lineAlignments = new List<LineAlignmentEnum>((LineAlignmentEnum[])Enum.GetValues(typeof(LineAlignmentEnum))); float frameHeight = (pageSize.Height - 130 - 5 * lineAlignments.Count * 2) / (lineAlignments.Count * 2); float frameWidth = (pageSize.Width - 60 - 5 * lineAlignments.Count) / lineAlignments.Count; int imageSize = 7; for(int index = 0, length = lineAlignments.Count; index < length; index++) { LineAlignmentEnum lineAlignment = lineAlignments[index]; for(int imageIndex = 0, imageLength = lineAlignments.Count; imageIndex < imageLength; imageIndex++) { LineAlignmentEnum imageAlignment = lineAlignments[imageIndex]; for(int index2 = 0, length2 = 2; index2 < length2; index2++) { RectangleF frame = new RectangleF( 30 + (frameWidth + 5) * imageIndex, 100 + (frameHeight + 5) * (index * 2 + index2), frameWidth, frameHeight ); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top); { composer.SetFont(mainFont, 3); blockComposer.ShowText("Text: " + lineAlignment); blockComposer.ShowBreak(); blockComposer.ShowText("Image: " + imageAlignment); } blockComposer.End(); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Middle); { composer.SetFont(sampleFont, 3); blockComposer.ShowText("Previous row boundary."); blockComposer.ShowBreak(); composer.SetFont(sampleFont, index2 == 0 ? 3 : 6); blockComposer.ShowText("Alignment:"); composer.SetFont(sampleFont, index2 == 0 ? 6 : 3); blockComposer.ShowText(" aligned to " + lineAlignment + " ", lineAlignment); blockComposer.ShowXObject(sampleImageXObject, new SizeF(imageSize, imageSize), imageAlignment); blockComposer.ShowBreak(); composer.SetFont(sampleFont, 3); blockComposer.ShowText("Next row boundary."); } blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[]{1,4}, 4)); composer.DrawRectangle(blockComposer.Frame); composer.Stroke(); } composer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[]{1,1}, 1)); composer.DrawRectangle(blockComposer.BoundBox); composer.Stroke(); } composer.End(); } } } } // 4. Flush the contents into the page! composer.Flush(); }
/// <summary> /// Flush a composer so it will write all the data to the page after we build up the composer /// </summary> /// <param name="ComposerToFlush">comoser to flush</param> public void FlushComposer(PrimitiveComposer ComposerToFlush) { ComposerToFlush.Flush(); }
private void Populate(Document document) { Page page = new Page(document); document.Pages.Add(page); SKSize pageSize = page.Size; /* * NOTE: Default fallback behavior on text encoding mismatch is substitution with default * character; in this case, we want to force an exception to be thrown so we can explicitly * handle the issue. */ document.Configuration.EncodingFallback = EncodingFallbackEnum.Exception; PrimitiveComposer composer = new PrimitiveComposer(page); int x = Margin, y = Margin; PdfType1Font titleFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Times, true, true); PdfType1Font font = null; // Iterating through the standard Type 1 fonts... foreach (PdfType1Font.FamilyEnum fontFamily in (PdfType1Font.FamilyEnum[])Enum.GetValues(typeof(PdfType1Font.FamilyEnum))) { // Iterating through the font styles... for (int styleIndex = 0; styleIndex < 4; styleIndex++) { /* * NOTE: Symbol and Zapf Dingbats are available just as regular fonts (no italic or bold variant). */ if (styleIndex > 0 && (fontFamily == PdfType1Font.FamilyEnum.Symbol || fontFamily == PdfType1Font.FamilyEnum.ZapfDingbats)) { break; } bool bold = (styleIndex & 1) > 0; bool italic = (styleIndex & 2) > 0; // Define the font used to show its character set! font = PdfType1Font.Load(document, fontFamily, bold, italic); if (y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; } if (styleIndex == 0) { composer.DrawLine( new SKPoint(x, y), new SKPoint(pageSize.Width - Margin, y) ); composer.Stroke(); y += 5; } composer.SetFont( titleFont, FontBaseSize * (styleIndex == 0 ? 1.5f : 1) ); composer.ShowText( fontFamily.ToString() + (bold ? " bold" : "") + (italic ? " italic" : ""), new SKPoint(x, y) ); y += 40; // Set the font used to show its character set! composer.SetFont(font, FontBaseSize); // Iterating through the font characters... foreach (int charCode in font.Encoding.CodeToNameMap.Keys.OrderBy(codePoint => codePoint)) { if (y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; composer.SetFont(titleFont, FontBaseSize); composer.ShowText( fontFamily.ToString() + " (continued)", new SKPoint(pageSize.Width - Margin, y), XAlignmentEnum.Right, YAlignmentEnum.Top, 0 ); composer.SetFont(font, FontBaseSize); y += FontBaseSize * 2; } try { var uniCode = font.ToUnicode(charCode); // Show the character! composer.ShowText( new String((char)uniCode, 1), new SKPoint(x, y) ); x += FontBaseSize; if (x > pageSize.Width - Margin) { x = Margin; y += 30; } } catch (EncodeException) { /* * NOOP -- NOTE: document.Configuration.EncodingFallback allows to customize the * behavior in case of missing character: we can alternatively catch an exception, have * the character substituted by a default one (typically '?' symbol) or have the * character silently excluded. */ } } x = Margin; y += Margin; } } composer.Flush(); }
public org.pdfclown.documents.contents.xObjects.XObject ToXObject(org.pdfclown.documents.Document context) { var xObject = new org.pdfclown.documents.contents.xObjects.FormXObject(context, Size); PrimitiveComposer composer = new PrimitiveComposer(xObject); this.ToInlineObject(composer); composer.Flush(); return xObject; }
/** <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2.1. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 2.2. Create a block composer! BlockComposer blockComposer = new BlockComposer(composer); // 3. Inserting contents... // Define the font to use! fonts::Font font = fonts::Font.Get( document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "GenR102.TTF") ); // Define the paragraph break size! Size breakSize = new Size(0,10); // Define the text to show! string[] titles = new string[] { "ΑΡΘΡΟ 1", "ASARIYA SINTE (1)", "Article 1", "Article premier", "Статья 1", "Artículo 1", "Artikel 1", "Madde 1", "Artikel 1", "Articolo 1", "Artykuł 1", "Bend 1", "Abala kìíní." }; string[] bodies = new string[] { "'Ολοι οι άνθρωποι γεννιούνται ελεύθεροι και ίσοι στην αξιοπρέπεια και τα δικαιώματα. Είναι προικισμένοι με λογική και συνείδηση, και οφείλουν να συμπεριφέρονται μεταξύ τους με πνεύμα αδελφοσύνης.", "Aduniya kuna n gu ibuna damayo hɛi nɔ dei-dei nn daama nna n burucinitɛrɛ fɔ, n lasabu nna laakari ya nam nn mɔ huro cɛrɛ kuna nyanze tɛrɛ bɔŋɔɔ.", "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.", "Tous les êtres humains naissent libres et égaux en dignité et en droits. Ils sont doués de raison et de conscience et doivent agir les uns envers les autres dans un esprit de fraternité.", "Все люди рождаются свободными и равными в своем достоинстве и правах. Они наделены разумом и совестью и должны поступать в отношении друг друга в духе братства.", "Todos los seres humanos nacen libres e iguales en dignidad y derechos y, dotados como están de razón y conciencia, deben comportarse fraternalmente los unos con los otros.", "Alle Menschen sind frei und gleich an Würde und Rechten geboren. Sie sind mit Vernunft und Gewissen begabt und sollen einander im Geist der Brüderlichkeit begegnen.", "Bütün insanlar hür, haysiyet ve haklar bakımından eşit doğarlar. Akıl ve vicdana sahiptirler ve birbirlerine karşı kardeşlik zihniyeti ile hareket etmelidirler.", "Alla människor är födda fria och lika i värde och rättigheter. De har utrustats med förnuft och samvete och bör handla gentemot varandra i en anda av gemenskap.", "Tutti gli esseri umani nascono liberi ed eguali in dignità e diritti. Essi sono dotati di ragione e di coscienza e devono agire gli uni verso gli altri in spirito di fratellanza.", "Wszyscy ludzie rodzą się wolni i równi pod względem swej godności i swych praw. Są oni obdarzeni rozumem i sumieniem i powinni postępować wobec innych w duchu braterstwa.", "Hemû mirov azad û di weqar û mafan de wekhev tên dinyayê. Ew xwedî hiş û şuûr in û divê li hember hev bi zihniyeteke bratiyê bilivin.", "Gbogbo ènìyàn ni a bí ní òmìnira; iyì àti è̟tó̟ kò̟ò̟kan sì dó̟gba. Wó̟n ní è̟bùn ti làákàyè àti ti è̟rí-o̟kàn, ó sì ye̟ kí wo̟n ó máa hùwà sí ara wo̟n gé̟gé̟ bí o̟mo̟ ìyá." }; string[] sources = new string[] { "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=grk", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=den", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=eng", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=frn", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=rus", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=spn", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=ger", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=trk", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=swd", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=itn", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=pql", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=kdb1", "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=yor" }; // Begin the content block! blockComposer.Begin( new RectangleF( Margin, Margin, page.Size.Width - Margin * 2, page.Size.Height - Margin * 2 ), XAlignmentEnum.Justify, YAlignmentEnum.Top ); for( int index = 0, length = titles.Length; index < length; index++ ) { composer.SetFont(font,12); blockComposer.ShowText(titles[index]); blockComposer.ShowBreak(); composer.SetFont(font,11); blockComposer.ShowText(bodies[index]); blockComposer.ShowBreak(XAlignmentEnum.Right); composer.SetFont(font,8); blockComposer.ShowText("[Source: " + sources[index] + "]"); blockComposer.ShowBreak(breakSize,XAlignmentEnum.Justify); } // End the content block! blockComposer.End(); // 4. Flush the contents into the page! composer.Flush(); }
private void RefreshAppearance( ) { Widget widget = Widgets[0]; FormXObject normalAppearance; { AppearanceStates normalAppearances = widget.Appearance.Normal; normalAppearance = normalAppearances[null]; if(normalAppearance == null) {normalAppearances[null] = normalAppearance = new FormXObject(Document, widget.Box.Size);} } PdfName fontName = null; double fontSize = 0; { PdfString defaultAppearanceState = DefaultAppearanceState; if(defaultAppearanceState == null) { // Retrieving the font to define the default appearance... fonts::Font defaultFont = null; PdfName defaultFontName = null; { // Field fonts. FontResources normalAppearanceFonts = normalAppearance.Resources.Fonts; foreach(KeyValuePair<PdfName,fonts::Font> entry in normalAppearanceFonts) { if(!entry.Value.Symbolic) { defaultFont = entry.Value; defaultFontName = entry.Key; break; } } if(defaultFontName == null) { // Common fonts. FontResources formFonts = Document.Form.Resources.Fonts; foreach(KeyValuePair<PdfName,fonts::Font> entry in formFonts) { if(!entry.Value.Symbolic) { defaultFont = entry.Value; defaultFontName = entry.Key; break; } } if(defaultFontName == null) { //TODO:manage name collision! formFonts[ defaultFontName = new PdfName("default") ] = defaultFont = new fonts::StandardType1Font( Document, fonts::StandardType1Font.FamilyEnum.Helvetica, false, false ); } normalAppearanceFonts[defaultFontName] = defaultFont; } } bytes::Buffer buffer = new bytes::Buffer(); new SetFont(defaultFontName, IsMultiline ? 10 : 0).WriteTo(buffer, Document); widget.BaseDataObject[PdfName.DA] = defaultAppearanceState = new PdfString(buffer.ToByteArray()); } // Retrieving the font to use... ContentParser parser = new ContentParser(defaultAppearanceState.ToByteArray()); foreach(ContentObject content in parser.ParseContentObjects()) { if(content is SetFont) { SetFont setFontOperation = (SetFont)content; fontName = setFontOperation.Name; fontSize = setFontOperation.Size; break; } } normalAppearance.Resources.Fonts[fontName] = Document.Form.Resources.Fonts[fontName]; } // Refreshing the field appearance... /* * TODO: resources MUST be resolved both through the apperance stream resource dictionary and * from the DR-entry acroform resource dictionary */ PrimitiveComposer baseComposer = new PrimitiveComposer(normalAppearance); BlockComposer composer = new BlockComposer(baseComposer); ContentScanner currentLevel = composer.Scanner; bool textShown = false; while(currentLevel != null) { if(!currentLevel.MoveNext()) { currentLevel = currentLevel.ParentLevel; continue; } ContentObject content = currentLevel.Current; if(content is MarkedContent) { MarkedContent markedContent = (MarkedContent)content; if(PdfName.Tx.Equals(((BeginMarkedContent)markedContent.Header).Tag)) { // Remove old text representation! markedContent.Objects.Clear(); // Add new text representation! baseComposer.Scanner = currentLevel.ChildLevel; // Ensures the composer places new contents within the marked content block. ShowText(composer, fontName, fontSize); textShown = true; } } else if(content is Text) {currentLevel.Remove();} else if(currentLevel.ChildLevel != null) {currentLevel = currentLevel.ChildLevel;} } if(!textShown) { baseComposer.BeginMarkedContent(PdfName.Tx); ShowText(composer, fontName, fontSize); baseComposer.End(); } baseComposer.Flush(); }
/** <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document, XObject form ) { // 1. Add a page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2. Create a content composer for the content stream! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Inserting contents... SizeF pageSize = page.Size; // 3.1. Showing the form on the page... { SizeF formSize = form.Size; // Form 1. composer.ShowXObject( form, new PointF(pageSize.Width/2,pageSize.Height/2), GeomUtils.Scale(formSize, new SizeF(300,0)), XAlignmentEnum.Center, YAlignmentEnum.Middle, 45 ); // Form 2. composer.ShowXObject( form, new PointF(0,pageSize.Height), GeomUtils.Scale(formSize, new SizeF(0,300)), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); // Form 3. composer.ShowXObject( form, new PointF(pageSize.Width,pageSize.Height), new SizeF(80,200), XAlignmentEnum.Right, YAlignmentEnum.Bottom, 0 ); } // 3.2. Showing the comments on the page... { BlockComposer blockComposer = new BlockComposer(composer); RectangleF frame = new RectangleF( 18, 18, pageSize.Width * .5f, pageSize.Height * .5f ); blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Top); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont,24); blockComposer.ShowText("Page-to-form sample"); SizeF breakSize = new SizeF(0,8); blockComposer.ShowBreak(breakSize); composer.SetFont(bodyFont,8); blockComposer.ShowText("This sample shows how to convert a page to a reusable form that can be placed multiple times on other pages scaling, rotating, anchoring and aligning it."); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("On this page you can see some of the above-mentioned transformations:"); breakSize.Width = 8; blockComposer.ShowBreak(breakSize); blockComposer.ShowText("1. anchored to the center of the page, rotated by 45 degrees counterclockwise, 300 point wide (preserved proportions);"); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("2. anchored to the bottom-left corner of the page, 300 point high (preserved proportions);"); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("3. anchored to the bottom-right of the page, 80 point wide and 200 point high (altered proportions)."); blockComposer.End(); } // 4. Flush the contents into the content stream! composer.Flush(); }
private void BuildTextBlockPage4( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int stepCount = 5; int step = (int)pageSize.Height / (stepCount + 1); BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width-60, step*.8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Unspaced block"); blockComposer.End(); } // Drawing the text block... { fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); composer.SetFont(sampleFont, 15); float topMargin = 100; float boxMargin = 30; float boxWidth = pageSize.Width - boxMargin * 2; float boxHeight = (pageSize.Height - topMargin - boxMargin - boxMargin) / 2; { RectangleF frame = new RectangleF( boxMargin, topMargin, boxWidth, boxHeight ); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top); // Add text until the frame area is completely filled! while(blockComposer.ShowText("DemonstratingHowUnspacedTextIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0); blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.2); composer.SetLineDash(new LineDash(new double[]{5,5}, 5)); composer.DrawRectangle(frame); composer.Stroke(); } composer.End(); } { RectangleF frame = new RectangleF( boxMargin, topMargin + boxHeight + boxMargin, boxWidth, boxHeight ); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top); // Add text until the frame area is completely filled! while(blockComposer.ShowText(" DemonstratingHowUnspacedTextWithLeadingSpaceIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0); blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.2); composer.SetLineDash(new LineDash(new double[]{5,5}, 5)); composer.DrawRectangle(frame); composer.Stroke(); } composer.End(); } } // 4. Flush the contents into the page! composer.Flush(); }
private void Populate( Document document ) { /* NOTE: In order to insert a field into a document, you have to follow these steps: 1. Define the form fields collection that will gather your fields (NOTE: the form field collection is global to the document); 2. Define the pages where to place the fields; 3. Define the appearance style to render your fields; 4. Create each field of yours: 4.1. instantiate your field into the page; 4.2. apply the appearance style to your field; 4.3. insert your field into the fields collection. */ // 1. Define the form fields collection! Form form = document.Form; Fields fields = form.Fields; // 2. Define the page where to place the fields! Page page = new Page(document); document.Pages.Add(page); // 3. Define the appearance style to apply to the fields! DefaultStyle fieldStyle = new DefaultStyle(); fieldStyle.FontSize = 12; fieldStyle.GraphicsVisibile = true; PrimitiveComposer composer = new PrimitiveComposer(page); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ), 14 ); // 4. Field creation. // 4.a. Push button. { composer.ShowText( "PushButton:", new PointF(140, 68), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0 ); Widget fieldWidget = new Widget( page, new RectangleF(150, 50, 136, 36) ); WidgetActions fieldWidgetActions = new WidgetActions(fieldWidget); fieldWidget.Actions = fieldWidgetActions; fieldWidgetActions.OnActivate = new JavaScript( document, "app.alert(\"Radio button currently selected: '\" + this.getField(\"myRadio\").value + \"'.\",3,0,\"Activation event\");" ); PushButton field = new PushButton( "okButton", fieldWidget, "Push" // Current value. ); // 4.1. Field instantiation. fields.Add(field); // 4.2. Field insertion into the fields collection. fieldStyle.Apply(field); // 4.3. Appearance style applied. { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(296,50,page.Size.Width-336,36),XAlignmentEnum.Left,YAlignmentEnum.Middle); composer.SetFont(composer.State.Font,7); blockComposer.ShowText("If you click this push button, a javascript action should prompt you an alert box responding to the activation event triggered by your PDF viewer."); blockComposer.End(); } } // 4.b. Check box. { composer.ShowText( "CheckBox:", new PointF(140, 118), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0 ); CheckBox field = new CheckBox( "myCheck", new Widget( page, new RectangleF(150, 100, 36, 36) ), true // Current value. ); // 4.1. Field instantiation. fieldStyle.Apply(field); fields.Add(field); field = new CheckBox( "myCheck2", new Widget( page, new RectangleF(200, 100, 36, 36) ), true // Current value. ); // 4.1. Field instantiation. fieldStyle.Apply(field); fields.Add(field); field = new CheckBox( "myCheck3", new Widget( page, new RectangleF(250, 100, 36, 36) ), false // Current value. ); // 4.1. Field instantiation. fields.Add(field); // 4.2. Field insertion into the fields collection. fieldStyle.Apply(field); // 4.3. Appearance style applied. } // 4.c. Radio button. { composer.ShowText( "RadioButton:", new PointF(140, 168), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0 ); RadioButton field = new RadioButton( "myRadio", /* NOTE: A radio button field typically combines multiple alternative widgets. */ new DualWidget[] { new DualWidget( page, new RectangleF(150, 150, 36, 36), "first" ), new DualWidget( page, new RectangleF(200, 150, 36, 36), "second" ), new DualWidget( page, new RectangleF(250, 150, 36, 36), "third" ) }, "second" // Selected item (it MUST correspond to one of the available widgets' names). ); // 4.1. Field instantiation. fields.Add(field); // 4.2. Field insertion into the fields collection. fieldStyle.Apply(field); // 4.3. Appearance style applied. } // 4.d. Text field. { composer.ShowText( "TextField:", new PointF(140, 218), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0 ); TextField field = new TextField( "myText", new Widget( page, new RectangleF(150, 200, 200, 36) ), "Carmen Consoli" // Current value. ); // 4.1. Field instantiation. field.SpellChecked = false; // Avoids text spell check. FieldActions fieldActions = new FieldActions(document); field.Actions = fieldActions; fieldActions.OnValidate = new JavaScript( document, "app.alert(\"Text '\" + this.getField(\"myText\").value + \"' has changed!\",3,0,\"Validation event\");" ); fields.Add(field); // 4.2. Field insertion into the fields collection. fieldStyle.Apply(field); // 4.3. Appearance style applied. { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(360,200,page.Size.Width-400,36),XAlignmentEnum.Left,YAlignmentEnum.Middle); composer.SetFont(composer.State.Font,7); blockComposer.ShowText("If you leave this text field after changing its content, a javascript action should prompt you an alert box responding to the validation event triggered by your PDF viewer."); blockComposer.End(); } } // 4.e. Choice fields. { // Preparing the item list that we'll use for choice fields (a list box and a combo box (see below))... ChoiceItems items = new ChoiceItems(document); items.Add("Tori Amos"); items.Add("Anouk"); items.Add("Joan Baez"); items.Add("Rachele Bastreghi"); items.Add("Anna Calvi"); items.Add("Tracy Chapman"); items.Add("Carmen Consoli"); items.Add("Ani DiFranco"); items.Add("Cristina Dona'"); items.Add("Nathalie Giannitrapani"); items.Add("PJ Harvey"); items.Add("Billie Holiday"); items.Add("Joan As Police Woman"); items.Add("Joan Jett"); items.Add("Janis Joplin"); items.Add("Angelique Kidjo"); items.Add("Patrizia Laquidara"); items.Add("Annie Lennox"); items.Add("Loreena McKennitt"); items.Add("Joni Mitchell"); items.Add("Alanis Morissette"); items.Add("Yael Naim"); items.Add("Noa"); items.Add("Sinead O'Connor"); items.Add("Dolores O'Riordan"); items.Add("Nina Persson"); items.Add("Brisa Roche'"); items.Add("Roberta Sammarelli"); items.Add("Cristina Scabbia"); items.Add("Nina Simone"); items.Add("Skin"); items.Add("Patti Smith"); items.Add("Fatima Spar"); items.Add("Thony (F.V.Caiozzo)"); items.Add("Paola Turci"); items.Add("Sarah Vaughan"); items.Add("Nina Zilli"); // 4.e1. List box. { composer.ShowText( "ListBox:", new PointF(140, 268), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0 ); ListBox field = new ListBox( "myList", new Widget( page, new RectangleF(150, 250, 200, 70) ) ); // 4.1. Field instantiation. field.Items = items; // List items assignment. field.MultiSelect = false; // Multiple items may not be selected simultaneously. field.Value = "Carmen Consoli"; // Selected item. fields.Add(field); // 4.2. Field insertion into the fields collection. fieldStyle.Apply(field); // 4.3. Appearance style applied. } // 4.e2. Combo box. { composer.ShowText( "ComboBox:", new PointF(140, 350), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0 ); ComboBox field = new ComboBox( "myCombo", new Widget( page, new RectangleF(150, 334, 200, 36) ) ); // 4.1. Field instantiation. field.Items = items; // Combo items assignment. field.Editable = true; // Text may be edited. field.SpellChecked = false; // Avoids text spell check. field.Value = "Carmen Consoli"; // Selected item. fields.Add(field); // 4.2. Field insertion into the fields collection. fieldStyle.Apply(field); // 4.3. Appearance style applied. } } composer.Flush(); }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); PrimitiveComposer composer = new PrimitiveComposer(page); StandardType1Font font = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(font,12); // Note. composer.ShowText("Note annotation:", new Point(35,35)); annotations::Note note = new annotations::Note( page, new Point(50, 50), "Note annotation" ); note.IconType = annotations::Note.IconTypeEnum.Help; note.ModificationDate = new DateTime(); note.IsOpen = true; // Callout. composer.ShowText("Callout note annotation:", new Point(35,85)); annotations::CalloutNote calloutNote = new annotations::CalloutNote( page, new Rectangle(50, 100, 200, 24), "Callout note annotation" ); calloutNote.Justification = JustificationEnum.Right; calloutNote.Line = new annotations::CalloutNote.LineObject( page, new Point(150,650), new Point(100,600), new Point(50,100) ); // File attachment. composer.ShowText("File attachment annotation:", new Point(35,135)); annotations::FileAttachment attachment = new annotations::FileAttachment( page, new Rectangle(50, 150, 12, 12), "File attachment annotation", FileSpecification.Get( EmbeddedFile.Get( document, GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg") ), "happyGNU.jpg" ) ); attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip; composer.BeginLocalState(); // Arrow line. composer.ShowText("Line annotation:", new Point(35,185)); composer.SetFont(font,10); composer.ShowText("Arrow:", new Point(50,200)); annotations::Line line = new annotations::Line( page, new Point(50, 260), new Point(200,210), "Arrow line annotation" ); line.FillColor = new DeviceRGBColor(1,0,0); line.StartStyle = annotations::Line.LineEndStyleEnum.Circle; line.EndStyle = annotations::Line.LineEndStyleEnum.ClosedArrow; line.CaptionVisible = true; // Dimension line. composer.ShowText("Dimension:", new Point(300,200)); line = new annotations::Line( page, new Point(300,220), new Point(500,220), "Dimension line annotation" ); line.LeaderLineLength = 20; line.LeaderLineExtensionLength = 10; line.CaptionVisible = true; composer.End(); // Scribble. composer.ShowText("Scribble annotation:", new Point(35,285)); new annotations::Scribble( page, new RectangleF(50, 300, 100, 30), "Scribble annotation", new List<IList<PointF>>( new List<PointF>[] { new List<PointF>( new PointF[] { new PointF(50,300), new PointF(70,310), new PointF(100,320) } ) } ) ); // Rectangle. composer.ShowText("Rectangle annotation:", new Point(35,335)); annotations::Rectangle rectangle = new annotations::Rectangle( page, new Rectangle(50, 350, 100, 30), "Rectangle annotation" ); rectangle.FillColor = new DeviceRGBColor(1,0,0); rectangle.Alpha = .25; // Ellipse. composer.ShowText("Ellipse annotation:", new Point(35,385)); annotations::Ellipse ellipse = new annotations::Ellipse( page, new Rectangle(50, 400, 100, 30), "Ellipse annotation" ); ellipse.FillColor = new DeviceRGBColor(0,0,1); // Rubber stamp. composer.ShowText("Rubber stamp annotation:", new Point(35,435)); new annotations::RubberStamp( page, new Rectangle(50, 450, 100, 30), "Rubber stamp annotation", annotations::RubberStamp.IconTypeEnum.Approved ); // Caret. composer.ShowText("Caret annotation:", new Point(35,485)); annotations::Caret caret = new annotations::Caret( page, new Rectangle(50, 500, 100, 30), "Caret annotation" ); caret.SymbolType = annotations::Caret.SymbolTypeEnum.NewParagraph; composer.Flush(); }
private void BuildTextBlockPage4( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int stepCount = 5; int step = (int)pageSize.Height / (stepCount + 1); BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width - 60, step * .8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Unspaced block"); blockComposer.End(); } // Drawing the text block... { fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); composer.SetFont(sampleFont, 15); float topMargin = 100; float boxMargin = 30; float boxWidth = pageSize.Width - boxMargin * 2; float boxHeight = (pageSize.Height - topMargin - boxMargin - boxMargin) / 2; { RectangleF frame = new RectangleF( boxMargin, topMargin, boxWidth, boxHeight ); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top); // Add text until the frame area is completely filled! while (blockComposer.ShowText("DemonstratingHowUnspacedTextIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0) { ; } blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.2); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5)); composer.DrawRectangle(frame); composer.Stroke(); } composer.End(); } { RectangleF frame = new RectangleF( boxMargin, topMargin + boxHeight + boxMargin, boxWidth, boxHeight ); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top); // Add text until the frame area is completely filled! while (blockComposer.ShowText(" DemonstratingHowUnspacedTextWithLeadingSpaceIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0) { ; } blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.2); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5)); composer.DrawRectangle(frame); composer.Stroke(); } composer.End(); } } // 4. Flush the contents into the page! composer.Flush(); }
private void Apply( ComboBox field ) { Document document = field.Document; Widget widget = field.Widgets[0]; Appearance appearance = widget.Appearance; if(appearance == null) {widget.Appearance = appearance = new Appearance(document);} widget.BaseDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg"); FormXObject normalAppearanceState; { SizeF size = widget.Box.Size; normalAppearanceState = new FormXObject(document, size); PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState); float lineWidth = 1; RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); if(GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } composer.BeginMarkedContent(PdfName.Tx); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Helvetica, false, false ), FontSize ); composer.ShowText( (string)field.Value, new PointF(0,size.Height/2), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.End(); composer.Flush(); } appearance.Normal[null] = normalAppearanceState; }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Hyphenation = true; blockComposer.Begin( new RectangleF( Margin, Margin, (float)pageSize.Width - Margin * 2, (float)pageSize.Height - Margin * 2 ), XAlignmentEnum.Justify, YAlignmentEnum.Top ); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont,32); blockComposer.ShowText("Inline image sample"); blockComposer.ShowBreak(); composer.SetFont(bodyFont,16); blockComposer.ShowText("Showing the GNU logo as an inline image within the page content stream."); blockComposer.End(); } // Showing the 'GNU' image... { // Instantiate a jpeg image object! entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")); // Abstract image (entity). // Set the position of the image in the page! composer.ApplyMatrix(200,0,0,200,(pageSize.Width-200)/2,(pageSize.Height-200)/2); // Show the image! image.ToInlineObject(composer); // Transforms the image entity into an inline image within the page. } composer.Flush(); }
private void Apply( ListBox field ) { Document document = field.Document; Widget widget = field.Widgets[0]; Appearance appearance = widget.Appearance; if(appearance == null) {widget.Appearance = appearance = new Appearance(document);} { PdfDictionary widgetDataObject = widget.BaseDataObject; widgetDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg"); widgetDataObject[PdfName.MK] = new PdfDictionary( new PdfName[] { PdfName.BG, PdfName.BC }, new PdfDirectObject[] { new PdfArray(new PdfDirectObject[]{PdfReal.Get(.9), PdfReal.Get(.9), PdfReal.Get(.9)}), new PdfArray(new PdfDirectObject[]{PdfInteger.Default, PdfInteger.Default, PdfInteger.Default}) } ); } FormXObject normalAppearanceState; { SizeF size = widget.Box.Size; normalAppearanceState = new FormXObject(document, size); PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState); float lineWidth = 1; RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); if(GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } composer.BeginLocalState(); if(GraphicsVisibile) { composer.DrawRectangle(frame, 5); composer.Clip(); // Ensures that the visible content is clipped within the rounded frame. } composer.BeginMarkedContent(PdfName.Tx); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Helvetica, false, false ), FontSize ); double y = 3; foreach(ChoiceItem item in field.Items) { composer.ShowText( item.Text, new PointF(0, (float)y) ); y += FontSize * 1.175; if(y > size.Height) break; } composer.End(); composer.End(); composer.Flush(); } appearance.Normal[null] = normalAppearanceState; }
private void Apply( CheckBox field ) { Document document = field.Document; foreach(Widget widget in field.Widgets) { { PdfDictionary widgetDataObject = widget.BaseDataObject; widgetDataObject[PdfName.DA] = new PdfString("/ZaDb 0 Tf 0 0 0 rg"); widgetDataObject[PdfName.MK] = new PdfDictionary( new PdfName[] { PdfName.BG, PdfName.BC, PdfName.CA }, new PdfDirectObject[] { new PdfArray(new PdfDirectObject[]{PdfReal.Get(0.9412), PdfReal.Get(0.9412), PdfReal.Get(0.9412)}), new PdfArray(new PdfDirectObject[]{PdfInteger.Default, PdfInteger.Default, PdfInteger.Default}), new PdfString("4") } ); widgetDataObject[PdfName.BS] = new PdfDictionary( new PdfName[] { PdfName.W, PdfName.S }, new PdfDirectObject[] { PdfReal.Get(0.8), PdfName.S } ); widgetDataObject[PdfName.H] = PdfName.P; } Appearance appearance = widget.Appearance; if(appearance == null) {widget.Appearance = appearance = new Appearance(document);} SizeF size = widget.Box.Size; AppearanceStates normalAppearance = appearance.Normal; FormXObject onState = new FormXObject(document, size); normalAppearance[PdfName.Yes] = onState; //TODO:verify!!! // appearance.getRollover().put(PdfName.Yes,onState); // appearance.getDown().put(PdfName.Yes,onState); // appearance.getRollover().put(PdfName.Off,offState); // appearance.getDown().put(PdfName.Off,offState); float lineWidth = 1; RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); { PrimitiveComposer composer = new PrimitiveComposer(onState); if(GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Middle); composer.SetFillColor(ForeColor); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.ZapfDingbats, true, false ), size.Height * 0.8 ); blockComposer.ShowText(new String(new char[]{CheckSymbol})); blockComposer.End(); composer.Flush(); } FormXObject offState = new FormXObject(document, size); normalAppearance[PdfName.Off] = offState; { if(GraphicsVisibile) { PrimitiveComposer composer = new PrimitiveComposer(offState); composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); composer.Flush(); } } } }
private void Populate(Document document) { Page page = new Page(document); document.Pages.Add(page); PrimitiveComposer composer = new PrimitiveComposer(page); fonts::StandardType1Font font = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); composer.SetFont(font, 12); // Sticky note. composer.ShowText("Sticky note annotation:", new SKPoint(35, 35)); new StickyNote(page, new SKPoint(50, 50), "Text of the Sticky note annotation") { IconType = StickyNote.IconTypeEnum.Note, Color = DeviceRGBColor.Get(SKColors.Yellow), Popup = new Popup( page, SKRect.Create(200, 25, 200, 75), "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)" ), Author = "Stefano", Subject = "Sticky note", IsOpen = true }; new StickyNote(page, new SKPoint(80, 50), "Text of the Help sticky note annotation") { IconType = StickyNote.IconTypeEnum.Help, Color = DeviceRGBColor.Get(SKColors.Pink), Author = "Stefano", Subject = "Sticky note", Popup = new Popup( page, SKRect.Create(400, 25, 200, 75), "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)" ) }; new StickyNote(page, new SKPoint(110, 50), "Text of the Comment sticky note annotation") { IconType = StickyNote.IconTypeEnum.Comment, Color = DeviceRGBColor.Get(SKColors.Green), Author = "Stefano", Subject = "Sticky note" }; new StickyNote(page, new SKPoint(140, 50), "Text of the Key sticky note annotation") { IconType = StickyNote.IconTypeEnum.Key, Color = DeviceRGBColor.Get(SKColors.Blue), Author = "Stefano", Subject = "Sticky note" }; // Callout. composer.ShowText("Callout note annotation:", new SKPoint(35, 85)); new FreeText(page, SKRect.Create(250, 90, 150, 70), "Text of the Callout note annotation") { Line = new FreeText.CalloutLine( page, new SKPoint(100, 100), new SKPoint(150, 125), new SKPoint(250, 125) ), Type = FreeText.TypeEnum.Callout, LineEndStyle = LineEndStyleEnum.OpenArrow, Border = new Border(1), Color = DeviceRGBColor.Get(SKColors.Yellow) }; // File attachment. composer.ShowText("File attachment annotation:", new SKPoint(35, 135)); new FileAttachment( page, SKRect.Create(50, 150, 15, 20), "Text of the File attachment annotation", FileSpecification.Get( EmbeddedFile.Get(document, GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")), "happyGNU.jpg") ) { IconType = FileAttachment.IconTypeEnum.PaperClip, Author = "Stefano", Subject = "File attachment" }; composer.ShowText("Line annotation:", new SKPoint(35, 185)); { composer.BeginLocalState(); composer.SetFont(font, 10); // Arrow line. composer.ShowText("Arrow:", new SKPoint(50, 200)); new Line( page, new SKPoint(50, 260), new SKPoint(200, 210), "Text of the Arrow line annotation", DeviceRGBColor.Get(SKColors.Black)) { StartStyle = LineEndStyleEnum.Circle, EndStyle = LineEndStyleEnum.ClosedArrow, CaptionVisible = true, FillColor = DeviceRGBColor.Get(SKColors.Green), Author = "Stefano", Subject = "Arrow line" }; // Dimension line. composer.ShowText("Dimension:", new SKPoint(300, 200)); new Line( page, new SKPoint(300, 220), new SKPoint(500, 220), "Text of the Dimension line annotation", DeviceRGBColor.Get(SKColors.Blue) ) { LeaderLineLength = 20, LeaderLineExtensionLength = 10, StartStyle = LineEndStyleEnum.OpenArrow, EndStyle = LineEndStyleEnum.OpenArrow, Border = new Border(1), CaptionVisible = true, Author = "Stefano", Subject = "Dimension line" }; composer.End(); } var path = new SKPath(); path.MoveTo(new SKPoint(50, 320)); path.LineTo(new SKPoint(70, 305)); path.LineTo(new SKPoint(110, 335)); path.LineTo(new SKPoint(130, 320)); path.LineTo(new SKPoint(110, 305)); path.LineTo(new SKPoint(70, 335)); path.LineTo(new SKPoint(50, 320)); // Scribble. composer.ShowText("Scribble annotation:", new SKPoint(35, 285)); new Scribble( page, new List <SKPath> { path }, "Text of the Scribble annotation", DeviceRGBColor.Get(SKColors.Orange)) { Border = new Border(1, new LineDash(new double[] { 5, 2, 2, 2 })), Author = "Stefano", Subject = "Scribble" }; // Rectangle. composer.ShowText("Rectangle annotation:", new SKPoint(35, 350)); new PdfClown.Documents.Interaction.Annotations.Rectangle( page, SKRect.Create(50, 370, 100, 30), "Text of the Rectangle annotation") { Color = DeviceRGBColor.Get(SKColors.Red), Border = new Border(1, new LineDash(new double[] { 5 })), Author = "Stefano", Subject = "Rectangle", Popup = new Popup( page, SKRect.Create(200, 325, 200, 75), "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)" ) }; // Ellipse. composer.ShowText("Ellipse annotation:", new SKPoint(35, 415)); new Ellipse( page, SKRect.Create(50, 440, 100, 30), "Text of the Ellipse annotation") { BorderEffect = new BorderEffect(BorderEffect.TypeEnum.Cloudy, 1), FillColor = DeviceRGBColor.Get(SKColors.Cyan), Color = DeviceRGBColor.Get(SKColors.Black), Author = "Stefano", Subject = "Ellipse" }; // Rubber stamp. composer.ShowText("Rubber stamp annotations:", new SKPoint(35, 505)); { fonts::Font stampFont = fonts::Font.Get(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf")); new Stamp( page, new SKPoint(75, 570), "This is a round custom stamp", new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Round, "Done", 50, stampFont) .Build() ) { Rotation = -10, Author = "Stefano", Subject = "Custom stamp" }; new Stamp( page, new SKPoint(210, 570), "This is a squared (and round-cornered) custom stamp", new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Squared, "Classified", 150, stampFont) { Color = DeviceRGBColor.Get(SKColors.Orange) }.Build() ) { Rotation = 15, Author = "Stefano", Subject = "Custom stamp" }; fonts::Font stampFont2 = fonts::Font.Get(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "MgOpenCanonicaRegular.ttf")); new Stamp( page, new SKPoint(350, 570), "This is a striped custom stamp", new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Striped, "Out of stock", 100, stampFont2) { Color = DeviceRGBColor.Get(SKColors.Gray) }.Build() ) { Rotation = 90, Author = "Stefano", Subject = "Custom stamp" }; // Define the standard stamps template path! /* * NOTE: The PDF specification defines several stamps (aka "standard stamps") whose rendering * depends on the support of viewer applications. As such support isn't guaranteed, PDF Clown * offers smooth, ready-to-use embedding of these stamps through the StampPath property of the * document configuration: you can decide to point to the stamps directory of your Acrobat * installation (e.g., in my GNU/Linux system it's located in * "/opt/Adobe/Reader9/Reader/intellinux/plug_ins/Annotations/Stamps/ENU") or to the * collection included in this distribution (std-stamps.pdf). */ document.Configuration.StampPath = GetResourcePath("../../pkg/templates/std-stamps.pdf"); // Add a standard stamp, rotating it 15 degrees counterclockwise! new Stamp( page, new SKPoint(485, 515), null, // Default size is natural size. "This is 'Confidential', a standard stamp", StandardStampEnum.Confidential) { Rotation = 15, Author = "Stefano", Subject = "Standard stamp" }; // Add a standard stamp, without rotation! new Stamp( page, new SKPoint(485, 580), null, // Default size is natural size. "This is 'SBApproved', a standard stamp", StandardStampEnum.BusinessApproved) { Author = "Stefano", Subject = "Standard stamp" }; // Add a standard stamp, rotating it 10 degrees clockwise! new Stamp( page, new SKPoint(485, 635), new SKSize(0, 40), // This scales the width proportionally to the 40-unit height (you can obviously do also the opposite, defining only the width). "This is 'SHSignHere', a standard stamp", StandardStampEnum.SignHere) { Rotation = -10, Author = "Stefano", Subject = "Standard stamp" }; } composer.ShowText("Text markup annotations:", new SKPoint(35, 650)); { composer.BeginLocalState(); composer.SetFont(font, 8); new TextMarkup( page, composer.ShowText("Highlight annotation", new SKPoint(35, 680)), "Text of the Highlight annotation", TextMarkup.MarkupTypeEnum.Highlight) { Author = "Stefano", Subject = "An highlight text markup!" }; new TextMarkup( page, composer.ShowText("Highlight annotation 2", new SKPoint(35, 695)).Inflate(0, 1), "Text of the Highlight annotation 2", TextMarkup.MarkupTypeEnum.Highlight) { Color = DeviceRGBColor.Get(SKColors.Magenta) }; new TextMarkup( page, composer.ShowText("Highlight annotation 3", new SKPoint(35, 710)).Inflate(0, 2), "Text of the Highlight annotation 3", TextMarkup.MarkupTypeEnum.Highlight) { Color = DeviceRGBColor.Get(SKColors.Red) }; new TextMarkup( page, composer.ShowText("Squiggly annotation", new SKPoint(180, 680)), "Text of the Squiggly annotation", TextMarkup.MarkupTypeEnum.Squiggly); new TextMarkup( page, composer.ShowText("Squiggly annotation 2", new SKPoint(180, 695)).Inflate(0, 2.5f), "Text of the Squiggly annotation 2", TextMarkup.MarkupTypeEnum.Squiggly) { Color = DeviceRGBColor.Get(SKColors.Orange) }; new TextMarkup( page, composer.ShowText("Squiggly annotation 3", new SKPoint(180, 710)).Inflate(0, 3), "Text of the Squiggly annotation 3", TextMarkup.MarkupTypeEnum.Squiggly) { Color = DeviceRGBColor.Get(SKColors.Pink) }; new TextMarkup( page, composer.ShowText("Underline annotation", new SKPoint(320, 680)), "Text of the Underline annotation", TextMarkup.MarkupTypeEnum.Underline ); new TextMarkup( page, composer.ShowText("Underline annotation 2", new SKPoint(320, 695)).Inflate(0, 2.5f), "Text of the Underline annotation 2", TextMarkup.MarkupTypeEnum.Underline ) { Color = DeviceRGBColor.Get(SKColors.Orange) }; new TextMarkup( page, composer.ShowText("Underline annotation 3", new SKPoint(320, 710)).Inflate(0, 3), "Text of the Underline annotation 3", TextMarkup.MarkupTypeEnum.Underline ) { Color = DeviceRGBColor.Get(SKColors.Green) }; new TextMarkup( page, composer.ShowText("StrikeOut annotation", new SKPoint(455, 680)), "Text of the StrikeOut annotation", TextMarkup.MarkupTypeEnum.StrikeOut ); new TextMarkup( page, composer.ShowText("StrikeOut annotation 2", new SKPoint(455, 695)).Inflate(0, 2.5f), "Text of the StrikeOut annotation 2", TextMarkup.MarkupTypeEnum.StrikeOut ) { Color = DeviceRGBColor.Get(SKColors.Orange) }; new TextMarkup( page, composer.ShowText("StrikeOut annotation 3", new SKPoint(455, 710)).Inflate(0, 3), "Text of the StrikeOut annotation 3", TextMarkup.MarkupTypeEnum.StrikeOut ) { Color = DeviceRGBColor.Get(SKColors.Green) }; composer.End(); } composer.Flush(); }
/** <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // Get the abstract barcode entity! EAN13Barcode barcode = new EAN13Barcode("8012345678901"); // Create the reusable barcode within the document! XObject barcodeXObject = barcode.ToXObject(document); Pages pages = document.Pages; // Page 1. { Page page = new Page(document); pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Hyphenation = true; blockComposer.Begin( new RectangleF( Margin, Margin, pageSize.Width - Margin * 2, pageSize.Height - Margin * 2 ), XAlignmentEnum.Left, YAlignmentEnum.Top ); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont,32); blockComposer.ShowText("Barcode sample"); blockComposer.ShowBreak(); composer.SetFont(bodyFont,16); blockComposer.ShowText("Showing the EAN-13 Bar Code on different compositions:"); blockComposer.ShowBreak(); blockComposer.ShowText("- page 1: on the lower right corner of the page, 100pt wide;"); blockComposer.ShowBreak(); blockComposer.ShowText("- page 2: on the middle of the page, 1/3-page wide, 25 degree counterclockwise rotated;"); blockComposer.ShowBreak(); blockComposer.ShowText("- page 3: filled page, 90 degree clockwise rotated."); blockComposer.ShowBreak(); blockComposer.End(); } // Show the barcode! composer.ShowXObject( barcodeXObject, new PointF(pageSize.Width - Margin, pageSize.Height - Margin), GeomUtils.Scale(barcodeXObject.Size, new SizeF(100,0)), XAlignmentEnum.Right, YAlignmentEnum.Bottom, 0 ); composer.Flush(); } // Page 2. { Page page = new Page(document); pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); // Show the barcode! composer.ShowXObject( barcodeXObject, new PointF(pageSize.Width / 2, pageSize.Height / 2), GeomUtils.Scale(barcodeXObject.Size, new SizeF(pageSize.Width / 3, 0)), XAlignmentEnum.Center, YAlignmentEnum.Middle, 25 ); composer.Flush(); } // Page 3. { Page page = new Page(document); pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); // Show the barcode! composer.ShowXObject( barcodeXObject, new PointF(pageSize.Width / 2, pageSize.Height / 2), new SizeF(pageSize.Height, pageSize.Width), XAlignmentEnum.Center, YAlignmentEnum.Middle, -90 ); composer.Flush(); } }
private void Apply( CheckBox field ) { Document document = field.Document; foreach (Widget widget in field.Widgets) { { PdfDictionary widgetDataObject = widget.BaseDataObject; widgetDataObject[PdfName.DA] = new PdfString("/ZaDb 0 Tf 0 0 0 rg"); widgetDataObject[PdfName.MK] = new PdfDictionary( new PdfName[] { PdfName.BG, PdfName.BC, PdfName.CA }, new PdfDirectObject[] { new PdfArray(new PdfDirectObject[] { PdfReal.Get(0.9412), PdfReal.Get(0.9412), PdfReal.Get(0.9412) }), new PdfArray(new PdfDirectObject[] { PdfInteger.Default, PdfInteger.Default, PdfInteger.Default }), new PdfString("4") } ); widgetDataObject[PdfName.BS] = new PdfDictionary( new PdfName[] { PdfName.W, PdfName.S }, new PdfDirectObject[] { PdfReal.Get(0.8), PdfName.S } ); widgetDataObject[PdfName.H] = PdfName.P; } Appearance appearance = widget.Appearance; AppearanceStates normalAppearance = appearance.Normal; SKSize size = widget.Box.Size; FormXObject onState = new FormXObject(document, size); normalAppearance[PdfName.Yes] = onState; //TODO:verify!!! // appearance.getRollover().put(PdfName.Yes,onState); // appearance.getDown().put(PdfName.Yes,onState); // appearance.getRollover().put(PdfName.Off,offState); // appearance.getDown().put(PdfName.Off,offState); float lineWidth = 1; SKRect frame = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); { PrimitiveComposer composer = new PrimitiveComposer(onState); if (GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle); composer.SetFillColor(ForeColor); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.ZapfDingbats, true, false ), size.Height * 0.8 ); blockComposer.ShowText(new String(new char[] { CheckSymbol })); blockComposer.End(); composer.Flush(); } FormXObject offState = new FormXObject(document, size); normalAppearance[PdfName.Off] = offState; { if (GraphicsVisibile) { PrimitiveComposer composer = new PrimitiveComposer(offState); composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); composer.Flush(); } } } }
private FormXObject CreateWatermark( Document document ) { SizeF size = document.GetSize(); // 1. Create an external form object to represent the watermark! FormXObject watermark = new FormXObject(document, size); // 2. Inserting the contents of the watermark... // 2.1. Create a content composer! PrimitiveComposer composer = new PrimitiveComposer(watermark); // 2.2. Inserting the contents... // Set the font to use! composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, true, false), 120); // Set the color to fill the text characters! composer.SetFillColor(new DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d)); // Apply transparency! { ExtGState state = new ExtGState(document); state.FillAlpha = .3; composer.ApplyState(state); } // Show the text! composer.ShowText( "PDFClown", // Text to show. new PointF(size.Width / 2f, size.Height / 2f), // Anchor location: page center. XAlignmentEnum.Center, // Horizontal placement (relative to the anchor): center. YAlignmentEnum.Middle, // Vertical placement (relative to the anchor): middle. 50 // Rotation: 50-degree-counterclockwise. ); // 2.3. Flush the contents into the watermark! composer.Flush(); return watermark; }
private void BuildTextBlockPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int step; { XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)); YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)); step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length+1); } BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width-60, step*.8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block alignment"); blockComposer.End(); } // Drawing the text blocks... fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); int x = 30; int y = (int)(step*1.2); foreach(XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum))) { foreach(YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum))) { composer.SetFont(mainFont, 12); composer.ShowText( xAlignment + " " + yAlignment + ":", new PointF(x,y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetFont(sampleFont, 10); for(int index = 0; index < 2; index++) { int frameX; switch(index) { case 0: frameX = 150; blockComposer.Hyphenation = false; break; case 1: frameX = 360; blockComposer.Hyphenation = true; break; default: throw new Exception(); } RectangleF frame = new RectangleF( frameX, y-step*.4f, 200, step*.8f ); blockComposer.Begin(frame,xAlignment,yAlignment); blockComposer.ShowText( "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details." ); blockComposer.End(); composer.BeginLocalState(); composer.SetLineWidth(0.2f); composer.SetLineDash(new LineDash(new double[]{5,5}, 5)); composer.DrawRectangle(frame); composer.Stroke(); composer.End(); } y+=step; } } // 4. Flush the contents into the page! composer.Flush(); }
private void BuildTextBlockPage3( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int stepCount = 5; int step = (int)(pageSize.Height) / (stepCount + 1); // 3.1. Drawing the page title... BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width-60, step*.8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block line space"); blockComposer.End(); } // 3.2. Drawing the text blocks... fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); int x = 30; int y = (int)(step * 1.1); blockComposer.LineSpace.UnitMode = Length.UnitModeEnum.Relative; for(int index = 0; index < stepCount; index++) { float relativeLineSpace = 0.5f * index; blockComposer.LineSpace.Value = relativeLineSpace; composer.SetFont(mainFont, 12); composer.ShowText( relativeLineSpace + ":", new PointF(x,y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetFont(sampleFont, 10); RectangleF frame = new RectangleF(150, y - step * .4f, 350, step * .9f); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top); blockComposer.ShowText("Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's twice as the line height\")."); blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.2); composer.SetLineDash(new LineDash(new double[]{5,5}, 5)); composer.DrawRectangle(frame); composer.Stroke(); } composer.End(); y+=step; } // 4. Flush the contents into the page! composer.Flush(); }
private void BuildCurvesPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(30, 0, pageSize.Width - 60, 50), XAlignmentEnum.Center, YAlignmentEnum.Middle); blockComposer.ShowText("Curves"); blockComposer.End(); } // 3.1. Arcs. { float y = 100; for ( int rowIndex = 0; rowIndex < 4; rowIndex++ ) { int angleStep = 45; int startAngle = 0; int endAngle = angleStep; float x = 100; float diameterX; float diameterY; switch (rowIndex) { case 0: default: diameterX = 40; diameterY = 40; break; case 1: diameterX = 40; diameterY = 20; break; case 2: diameterX = 20; diameterY = 40; break; case 3: diameterX = 40; diameterY = 40; break; } for ( int index = 0, length = 360 / angleStep; index < length; index++ ) { RectangleF arcFrame = new RectangleF((float)x, (float)y, (float)diameterX, (float)diameterY); // Drawing the arc frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Draw the arc! composer.DrawArc(arcFrame, startAngle, endAngle); composer.Stroke(); endAngle += angleStep; switch (rowIndex) { case 3: startAngle += angleStep; break; } x += 50; } y += diameterY + 10; } } // 3.2. Circle. { RectangleF arcFrame = new RectangleF(100, 300, 100, 100); // Drawing the circle frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the circle... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Red)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.3. Horizontal ellipse. { RectangleF arcFrame = new RectangleF(210, 300, 100, 50); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Green)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.4. Vertical ellipse. { RectangleF arcFrame = new RectangleF(320, 300, 50, 100); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.5. Spirals. { float y = 500; float spiralWidth = 100; composer.SetLineWidth(.5f); for ( int rowIndex = 0; rowIndex < 3; rowIndex++ ) { float x = 150; float branchWidth = .5f; float branchRatio = 1; for ( int spiralIndex = 0; spiralIndex < 4; spiralIndex++ ) { float spiralTurnsCount; switch (rowIndex) { case 0: default: spiralTurnsCount = spiralWidth / (branchWidth * 8); break; case 1: spiralTurnsCount = (float)(spiralWidth / (branchWidth * 8 * (spiralIndex * 1.15 + 1))); break; } switch (rowIndex) { case 2: composer.SetLineDash(new LineDash(new double[] { 10, 5 })); composer.SetLineCap(LineCapEnum.Round); break; default: break; } composer.DrawSpiral( new PointF((float)x, (float)y), 0, 360 * spiralTurnsCount, branchWidth, branchRatio ); composer.Stroke(); x += spiralWidth + 10; switch (rowIndex) { case 0: default: branchWidth += 1; break; case 1: branchRatio += .035f; break; } switch (rowIndex) { case 2: composer.SetLineWidth(composer.State.LineWidth + .5f); break; } } y += spiralWidth + 10; } } // 4. Flush the contents into the page! composer.Flush(); }
private void BuildLinks( Document document ) { Pages pages = document.Pages; Page page = new Page(document); pages.Add(page); StandardType1Font font = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); PrimitiveComposer composer = new PrimitiveComposer(page); BlockComposer blockComposer = new BlockComposer(composer); /* 2.1. Goto-URI link. */ { blockComposer.Begin(new RectangleF(30,100,200,50),XAlignmentEnum.Left,YAlignmentEnum.Middle); composer.SetFont(font,12); blockComposer.ShowText("Go-to-URI link"); composer.SetFont(font,8); blockComposer.ShowText("\nIt allows you to navigate to a network resource."); composer.SetFont(font,5); blockComposer.ShowText("\n\nClick on the box to go to the project's SourceForge.net repository."); blockComposer.End(); try { /* NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked. */ annotations::Link link = new annotations::Link( page, new Rectangle(240,100,100,50), "Link annotation", new GoToURI( document, new Uri("http://www.sourceforge.net/projects/clown") ) ); link.Border = new annotations::Border( document, 3, annotations::Border.StyleEnum.Beveled, null ); } catch(Exception exception) {throw new Exception("",exception);} } /* 2.2. Embedded-goto link. */ { string filePath = PromptFileChoice("Please select a PDF file to attach"); /* NOTE: These statements instruct PDF Clown to attach a PDF file to the current document. This is necessary in order to test the embedded-goto functionality, as you can see in the following link creation (see below). */ int fileAttachmentPageIndex = page.Index; string fileAttachmentName = "attachedSamplePDF"; string fileName = System.IO.Path.GetFileName(filePath); annotations::FileAttachment attachment = new annotations::FileAttachment( page, new Rectangle(0, -20, 10, 10), "File attachment annotation", FileSpecification.Get( EmbeddedFile.Get( document, filePath ), fileName ) ); attachment.Name = fileAttachmentName; attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip; blockComposer.Begin(new RectangleF(30,170,200,50),XAlignmentEnum.Left,YAlignmentEnum.Middle); composer.SetFont(font,12); blockComposer.ShowText("Go-to-embedded link"); composer.SetFont(font,8); blockComposer.ShowText("\nIt allows you to navigate to a destination within an embedded PDF file."); composer.SetFont(font,5); blockComposer.ShowText("\n\nClick on the button to go to the 2nd page of the attached PDF file (" + fileName + ")."); blockComposer.End(); /* NOTE: This statement instructs the PDF viewer to navigate to the page 2 of a PDF file attached inside the current document as described by the FileAttachment annotation on page 1 of the current document. */ annotations::Link link = new annotations::Link( page, new Rectangle(240,170,100,50), "Link annotation", new GoToEmbedded( document, new GoToEmbedded.PathElement( document, fileAttachmentPageIndex, // Page of the current document containing the file attachment annotation of the target document. fileAttachmentName, // Name of the file attachment annotation corresponding to the target document. null // No sub-target. ), // Target represents the document to go to. new RemoteDestination( document, 1, // Show the page 2 of the target document. Destination.ModeEnum.Fit, // Show the target document page entirely on the screen. null, null ) // The destination must be within the target document. ) ); link.Border = new annotations::Border( document, 1, annotations::Border.StyleEnum.Dashed, new LineDash(new double[]{8,5,2,5}) ); } /* 2.3. Textual link. */ { blockComposer.Begin(new RectangleF(30,240,200,50),XAlignmentEnum.Left,YAlignmentEnum.Middle); composer.SetFont(font,12); blockComposer.ShowText("Textual link"); composer.SetFont(font,8); blockComposer.ShowText("\nIt allows you to expose any kind of link (including the above-mentioned types) as text."); composer.SetFont(font,5); blockComposer.ShowText("\n\nClick on the text links to go either to the project's SourceForge.net repository or to the project's home page."); blockComposer.End(); try { composer.BeginLocalState(); composer.SetFont(font,10); composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue)); composer.ShowText( "PDF Clown Project's repository at SourceForge.net", new PointF(240,265), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0, new GoToURI( document, new Uri("http://www.sourceforge.net/projects/clown") ) ); composer.ShowText( "PDF Clown Project's home page", new PointF(240,285), XAlignmentEnum.Left, YAlignmentEnum.Bottom, -90, new GoToURI( document, new Uri("http://www.pdfclown.org") ) ); composer.End(); } catch {} } composer.Flush(); }
private void BuildTextBlockPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int step; { XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)); YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)); step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length + 1); } BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width - 60, step * .8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block alignment"); blockComposer.End(); } // Drawing the text blocks... fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); int x = 30; int y = (int)(step * 1.2); foreach (XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum))) { foreach (YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum))) { composer.SetFont(mainFont, 12); composer.ShowText( xAlignment + " " + yAlignment + ":", new PointF(x, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetFont(sampleFont, 10); for (int index = 0; index < 2; index++) { int frameX; switch (index) { case 0: frameX = 150; blockComposer.Hyphenation = false; break; case 1: frameX = 360; blockComposer.Hyphenation = true; break; default: throw new Exception(); } RectangleF frame = new RectangleF( frameX, y - step * .4f, 200, step * .8f ); blockComposer.Begin(frame, xAlignment, yAlignment); blockComposer.ShowText( "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details." ); blockComposer.End(); composer.BeginLocalState(); composer.SetLineWidth(0.2f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5)); composer.DrawRectangle(frame); composer.Stroke(); composer.End(); } y += step; } } // 4. Flush the contents into the page! composer.Flush(); }
private void BuildCurvesPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(30,0,pageSize.Width-60,50),XAlignmentEnum.Center,YAlignmentEnum.Middle); blockComposer.ShowText("Curves"); blockComposer.End(); } // 3.1. Arcs. { float y = 100; for( int rowIndex = 0; rowIndex < 4; rowIndex++ ) { int angleStep = 45; int startAngle = 0; int endAngle = angleStep; float x = 100; float diameterX; float diameterY; switch(rowIndex) { case 0: default: diameterX = 40; diameterY = 40; break; case 1: diameterX = 40; diameterY = 20; break; case 2: diameterX = 20; diameterY = 40; break; case 3: diameterX = 40; diameterY = 40; break; } for( int index = 0, length = 360/angleStep; index < length; index++ ) { RectangleF arcFrame = new RectangleF((float)x,(float)y,(float)diameterX,(float)diameterY); // Drawing the arc frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Draw the arc! composer.DrawArc(arcFrame,startAngle,endAngle); composer.Stroke(); endAngle += angleStep; switch(rowIndex) { case 3: startAngle += angleStep; break; } x += 50; } y += diameterY + 10; } } // 3.2. Circle. { RectangleF arcFrame = new RectangleF(100, 300, 100, 100); // Drawing the circle frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the circle... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Red)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.3. Horizontal ellipse. { RectangleF arcFrame = new RectangleF(210, 300, 100, 50); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Green)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.4. Vertical ellipse. { RectangleF arcFrame = new RectangleF(320, 300, 50, 100); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.5. Spirals. { float y = 500; float spiralWidth = 100; composer.SetLineWidth(.5f); for( int rowIndex = 0; rowIndex < 3; rowIndex++ ) { float x = 150; float branchWidth = .5f; float branchRatio = 1; for( int spiralIndex = 0; spiralIndex < 4; spiralIndex++ ) { float spiralTurnsCount; switch(rowIndex) { case 0: default: spiralTurnsCount = spiralWidth/(branchWidth*8); break; case 1: spiralTurnsCount = (float)(spiralWidth/(branchWidth*8*(spiralIndex*1.15+1))); break; } switch(rowIndex) { case 2: composer.SetLineDash(new LineDash(new double[]{10,5})); composer.SetLineCap(LineCapEnum.Round); break; default: break; } composer.DrawSpiral( new PointF((float)x,(float)y), 0, 360*spiralTurnsCount, branchWidth, branchRatio ); composer.Stroke(); x += spiralWidth + 10; switch(rowIndex) { case 0: default: branchWidth += 1; break; case 1: branchRatio += .035f; break; } switch(rowIndex) { case 2: composer.SetLineWidth(composer.State.LineWidth+.5f); break; } } y += spiralWidth + 10; } } // 4. Flush the contents into the page! composer.Flush(); }
private void BuildTextBlockPage3( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int stepCount = 5; int step = (int)(pageSize.Height) / (stepCount + 1); // 3.1. Drawing the page title... BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width - 60, step * .8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block line space"); blockComposer.End(); } // 3.2. Drawing the text blocks... fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); int x = 30; int y = (int)(step * 1.1); blockComposer.LineSpace.UnitMode = Length.UnitModeEnum.Relative; for (int index = 0; index < stepCount; index++) { float relativeLineSpace = 0.5f * index; blockComposer.LineSpace.Value = relativeLineSpace; composer.SetFont(mainFont, 12); composer.ShowText( relativeLineSpace + ":", new PointF(x, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetFont(sampleFont, 10); RectangleF frame = new RectangleF(150, y - step * .4f, 350, step * .9f); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top); blockComposer.ShowText("Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's twice as the line height\")."); blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.2); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5)); composer.DrawRectangle(frame); composer.Stroke(); } composer.End(); y += step; } // 4. Flush the contents into the page! composer.Flush(); }
public override xObjects::XObject ToXObject( Document context ) { xObjects::FormXObject xObject = new xObjects::FormXObject(context); { xObject.Size = Size; PrimitiveComposer composer = new PrimitiveComposer(xObject); this.ToInlineObject(composer); composer.Flush(); } return xObject; }
private void Build( Document document ) { // Add a page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // Create a content composer for the content stream! /* NOTE: There are several ways to add contents to a content stream: - adding content objects directly to the Contents collection; - adding content objects through a ContentScanner instance; - invoking basic drawing functions through a PrimitiveComposer instance; - invoking advanced static-positioning functions through a BlockComposer instance; - invoking advanced dynamic-positioning functions through a FlowComposer instance (currently not implemented yet). */ PrimitiveComposer composer = new PrimitiveComposer(page); // Wrap the content composer within a block filter! /* NOTE: The block filter is a basic typesetter. It exposes higher-level graphical functionalities (horizontal/vertical alignment, indentation, paragraph composition etc.) leveraging the content composer primitives. It's important to note that this is just an intermediate abstraction layer of the typesetting stack: further abstract levels could sit upon it, allowing the convenient treatment of typographic entities like titles, paragraphs, columns, tables, headers, footers etc. When such further abstract levels are available, the final user (developer of consuming applications) won't care any more of the details you can see here in the following code lines (such as bothering to select the first-letter font...). */ BlockComposer blockComposer = new BlockComposer(composer); composer.BeginLocalState(); // Define the block frame that will constrain our contents on the page canvas! RectangleF frame = new RectangleF( Margin_X, Margin_Y, (float)pageSize.Width - Margin_X * 2, (float)pageSize.Height - Margin_Y * 2 ); // Begin the title block! blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top); fonts::Font decorativeFont = fonts::Font.Get( document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "Ruritania-Outline.ttf") ); composer.SetFont(decorativeFont,56); blockComposer.ShowText("Chapter 1"); blockComposer.ShowBreak(); composer.SetFont(decorativeFont,32); blockComposer.ShowText("Down the Rabbit-Hole"); // End the title block! blockComposer.End(); // Update the block frame in order to begin after the title! frame = new RectangleF( (float)blockComposer.BoundBox.X, (float)blockComposer.BoundBox.Y + blockComposer.BoundBox.Height, (float)blockComposer.BoundBox.Width, (float)pageSize.Height - Margin_Y - (blockComposer.BoundBox.Y + blockComposer.BoundBox.Height) ); // Begin the body block! blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Bottom); fonts::Font bodyFont = fonts::Font.Get( document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf") ); composer.SetFont(bodyFont,14); composer.BeginLocalState(); composer.SetFont(decorativeFont,28); blockComposer.ShowText("A"); composer.End(); blockComposer.ShowText("lice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'"); // Define new-paragraph first-line offset! SizeF breakSize = new SizeF(24,8); // Indentation (24pt) and top margin (8pt). // Begin a new paragraph! blockComposer.ShowBreak(breakSize); blockComposer.ShowText("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her."); // Begin a new paragraph! blockComposer.ShowBreak(breakSize); blockComposer.ShowText("There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge."); // End the body block! blockComposer.End(); composer.End(); composer.BeginLocalState(); composer.Rotate( 90, new PointF( pageSize.Width - 50, pageSize.Height - 25 ) ); blockComposer = new BlockComposer(composer); blockComposer.Begin( new RectangleF(0,0,300,50), XAlignmentEnum.Left, YAlignmentEnum.Middle ); composer.SetFont(bodyFont,8); blockComposer.ShowText("Generated by PDF Clown on " + System.DateTime.Now); blockComposer.ShowBreak(); blockComposer.ShowText("For more info, visit http://www.pdfclown.org"); blockComposer.End(); composer.End(); // Flush the contents into the page! composer.Flush(); }
/// <summary> /// Renderiza o bloco para um XObject. /// </summary> public virtual org.pdfclown.documents.contents.xObjects.XObject ToXObject() { if(_RenderedObject == null) { _RenderedObject = new org.pdfclown.documents.contents.xObjects.FormXObject(Danfe.Document, Size); PrimitiveComposer composer = new PrimitiveComposer(_RenderedObject); var obj = composer.BeginLocalState(); composer.SetLineWidth(DanfeDocumento.LineWidth); if (PossuiCabecalho) { RectangleF rect = GetHeaderInnerRectangle(); //Danfe.PrintCabecalhoBloco2(composer, rect.Top, rect.Left, rect.Width, Cabecalho); PrintCabecalho(composer); } ToXObjectInternal(composer); foreach (var campo in Campos) { campo.Print(composer, Danfe.Font, Danfe.FontBold); } composer.Stroke(); composer.End(); composer.Flush(); } return _RenderedObject; }
/** <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // Initialize a new page! Page page = new Page(document); document.Pages.Add(page); // Initialize the primitive composer (within the new page context)! PrimitiveComposer composer = new PrimitiveComposer(page); composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 12); // Initialize the block composer (wrapping the primitive one)! BlockComposer blockComposer = new BlockComposer(composer); // Initialize the document layer configuration! LayerDefinition layerDefinition = document.Layer; document.PageMode = Document.PageModeEnum.Layers; // Shows the layers tab on document opening. // Get the root layers collection! Layers rootLayers = layerDefinition.Layers; // 1. Nested layers. { Layer nestedLayer = new Layer(document, "Nested layers"); rootLayers.Add(nestedLayer); Layers nestedSubLayers = nestedLayer.Layers; Layer nestedLayer1 = new Layer(document, "Nested layer 1"); nestedSubLayers.Add(nestedLayer1); Layer nestedLayer2 = new Layer(document, "Nested layer 2"); nestedSubLayers.Add(nestedLayer2); nestedLayer2.Locked = true; /* NOTE: Text in this section is shown using PrimitiveComposer. */ composer.BeginLayer(nestedLayer); composer.ShowText(nestedLayer.Title, new PointF(50, 50)); composer.End(); composer.BeginLayer(nestedLayer1); composer.ShowText(nestedLayer1.Title, new PointF(50, 75)); composer.End(); composer.BeginLayer(nestedLayer2); composer.ShowText(nestedLayer2.Title, new PointF(50, 100)); composer.End(); } // 2. Simple group (labeled group of non-nested, inclusive-state layers). { Layers simpleGroup = new Layers(document, "Simple group"); rootLayers.Add(simpleGroup); Layer layer1 = new Layer(document, "Grouped layer 1"); simpleGroup.Add(layer1); Layer layer2 = new Layer(document, "Grouped layer 2"); simpleGroup.Add(layer2); /* NOTE: Text in this section is shown using BlockComposer along with PrimitiveComposer to demonstrate their flexible cooperation. */ blockComposer.Begin(new RectangleF(50, 125, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle); composer.BeginLayer(layer1); blockComposer.ShowText(layer1.Title); composer.End(); blockComposer.ShowBreak(new SizeF(0, 15)); composer.BeginLayer(layer2); blockComposer.ShowText(layer2.Title); composer.End(); blockComposer.End(); } // 3. Radio group (labeled group of non-nested, exclusive-state layers). { Layers radioGroup = new Layers(document, "Radio group"); rootLayers.Add(radioGroup); Layer radio1 = new Layer(document, "Radiogrouped layer 1"); radioGroup.Add(radio1); radio1.Visible = true; Layer radio2 = new Layer(document, "Radiogrouped layer 2"); radioGroup.Add(radio2); radio2.Visible = false; Layer radio3 = new Layer(document, "Radiogrouped layer 3"); radioGroup.Add(radio3); radio3.Visible = false; // Register this option group in the layer configuration! LayerGroup options = new LayerGroup(document); options.Add(radio1); options.Add(radio2); options.Add(radio3); layerDefinition.OptionGroups.Add(options); /* NOTE: Text in this section is shown using BlockComposer along with PrimitiveComposer to demonstrate their flexible cooperation. */ blockComposer.Begin(new RectangleF(50, 185, 200, 75), XAlignmentEnum.Left, YAlignmentEnum.Middle); composer.BeginLayer(radio1); blockComposer.ShowText(radio1.Title); composer.End(); blockComposer.ShowBreak(new SizeF(0, 15)); composer.BeginLayer(radio2); blockComposer.ShowText(radio2.Title); composer.End(); blockComposer.ShowBreak(new SizeF(0, 15)); composer.BeginLayer(radio3); blockComposer.ShowText(radio3.Title); composer.End(); blockComposer.End(); } // 4. Print-only layer. { Layer printOnlyLayer = new Layer(document, "Print-only layer"); printOnlyLayer.Visible = false; printOnlyLayer.Printable = true; printOnlyLayer.Locked = true; rootLayers.Add(printOnlyLayer); composer.BeginLayer(printOnlyLayer); composer.ShowText(printOnlyLayer.Title, new PointF(50, 270)); composer.End(); } composer.Flush(); }
/* TODO: refresh should happen just before serialization, on document event (e.g. OnWrite()) */ private void RefreshAppearance( ) { FormXObject normalAppearance; RectangleF box = org.pdfclown.objects.Rectangle.Wrap(BaseDataObject[PdfName.Rect]).ToRectangleF(); { AppearanceStates normalAppearances = Appearance.Normal; normalAppearance = normalAppearances[null]; if(normalAppearance != null) { normalAppearance.Box = box; normalAppearance.BaseDataObject.Body.SetLength(0); } else {normalAppearances[null] = normalAppearance = new FormXObject(Document, box);} } PrimitiveComposer composer = new PrimitiveComposer(normalAppearance); { float yOffset = box.Height - Page.Box.Height; MarkupTypeEnum markupType = MarkupType; switch(markupType) { case MarkupTypeEnum.Highlight: { ExtGState defaultExtGState; { ExtGStateResources extGStates = normalAppearance.Resources.ExtGStates; defaultExtGState = extGStates[HighlightExtGStateName]; if(defaultExtGState == null) { if(extGStates.Count > 0) {extGStates.Clear();} extGStates[HighlightExtGStateName] = defaultExtGState = new ExtGState(Document); defaultExtGState.AlphaShape = false; defaultExtGState.BlendMode = new List<BlendModeEnum>(new BlendModeEnum[]{BlendModeEnum.Multiply}); } } composer.ApplyState(defaultExtGState); composer.SetFillColor(Color); { foreach(Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float markupBoxMargin = GetMarkupBoxMargin(markupBoxHeight); composer.DrawCurve( new PointF(points[3].X, points[3].Y + yOffset), new PointF(points[0].X, points[0].Y + yOffset), new PointF(points[3].X - markupBoxMargin, points[3].Y - markupBoxMargin + yOffset), new PointF(points[0].X - markupBoxMargin, points[0].Y + markupBoxMargin + yOffset) ); composer.DrawLine( new PointF(points[1].X, points[1].Y + yOffset) ); composer.DrawCurve( new PointF(points[2].X, points[2].Y + yOffset), new PointF(points[1].X + markupBoxMargin, points[1].Y + markupBoxMargin + yOffset), new PointF(points[2].X + markupBoxMargin, points[2].Y - markupBoxMargin + yOffset) ); composer.Fill(); } } } break; case MarkupTypeEnum.Squiggly: { composer.SetStrokeColor(Color); composer.SetLineCap(LineCapEnum.Round); composer.SetLineJoin(LineJoinEnum.Round); { foreach(Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float lineWidth = markupBoxHeight * .02f; float step = markupBoxHeight * .125f; float boxXOffset = points[3].X; float boxYOffset = points[3].Y + yOffset - lineWidth; bool phase = false; composer.SetLineWidth(lineWidth); for(float x = 0, xEnd = points[2].X - boxXOffset; x < xEnd || !phase; x += step) { PointF point = new PointF(x + boxXOffset, (phase ? -step : 0) + boxYOffset); if(x == 0) {composer.StartPath(point);} else {composer.DrawLine(point);} phase = !phase; } } composer.Stroke(); } } break; case MarkupTypeEnum.StrikeOut: case MarkupTypeEnum.Underline: { composer.SetStrokeColor(Color); { float lineYRatio = 0; switch(markupType) { case MarkupTypeEnum.StrikeOut: lineYRatio = .575f; break; case MarkupTypeEnum.Underline: lineYRatio = .85f; break; default: throw new NotImplementedException(); } foreach(Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float boxYOffset = markupBoxHeight * lineYRatio + yOffset; composer.SetLineWidth(markupBoxHeight * .065); composer.DrawLine( new PointF(points[3].X, points[0].Y + boxYOffset), new PointF(points[2].X, points[1].Y + boxYOffset) ); } composer.Stroke(); } } break; default: throw new NotImplementedException(); } } composer.Flush(); }
private void Apply( PushButton field ) { Document document = field.Document; Widget widget = field.Widgets[0]; Appearance appearance = widget.Appearance; if(appearance == null) {widget.Appearance = appearance = new Appearance(document);} FormXObject normalAppearanceState; { SizeF size = widget.Box.Size; normalAppearanceState = new FormXObject(document, size); PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState); float lineWidth = 1; RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth); if(GraphicsVisibile) { composer.BeginLocalState(); composer.SetLineWidth(lineWidth); composer.SetFillColor(BackColor); composer.SetStrokeColor(ForeColor); composer.DrawRectangle(frame, 5); composer.FillStroke(); composer.End(); } string title = (string)field.Value; if(title != null) { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Middle); composer.SetFillColor(ForeColor); composer.SetFont( new StandardType1Font( document, StandardType1Font.FamilyEnum.Helvetica, true, false ), size.Height * 0.5 ); blockComposer.ShowText(title); blockComposer.End(); } composer.Flush(); } appearance.Normal[null] = normalAppearanceState; }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); int x = Margin, y = Margin; StandardType1Font titleFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Times, true, true ); StandardType1Font font = null; // Iterating through the standard Type 1 fonts... foreach(StandardType1Font.FamilyEnum fontFamily in (StandardType1Font.FamilyEnum[])Enum.GetValues(typeof(StandardType1Font.FamilyEnum))) { // Iterating through the font styles... for(int styleIndex = 0; styleIndex < 4; styleIndex++) { /* NOTE: Symbol and Zapf Dingbats are available just as regular fonts (no italic or bold variant). */ if(styleIndex > 0 && (fontFamily == StandardType1Font.FamilyEnum.Symbol || fontFamily == StandardType1Font.FamilyEnum.ZapfDingbats)) break; bool bold, italic; switch(styleIndex) { case 0: // Regular. bold = false; italic = false; break; case 1: // Bold. bold = true; italic = false; break; case 2: // Italic. bold = false; italic = true; break; case 3: // Bold italic. bold = true; italic = true; break; default: throw new Exception("styleIndex " + styleIndex + " not supported."); } // Define the font used to show its character set! font = new StandardType1Font( document, fontFamily, bold, italic ); if(y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; } if(styleIndex == 0) { composer.DrawLine( new PointF(x,y), new PointF(pageSize.Width - Margin,y) ); composer.Stroke(); y += 5; } composer.SetFont( titleFont, FontBaseSize * (styleIndex == 0 ? 1.5f : 1) ); composer.ShowText( fontFamily.ToString() + (bold ? " bold" : "") + (italic ? " italic" : ""), new PointF(x,y) ); y += 40; // Set the font used to show its character set! composer.SetFont(font,FontBaseSize); // Iterating through the font characters... for(int charCode = 32; charCode < 256; charCode++) { if(y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; composer.SetFont(titleFont,FontBaseSize); composer.ShowText( fontFamily.ToString() + " (continued)", new PointF(pageSize.Width - Margin, y), XAlignmentEnum.Right, YAlignmentEnum.Top, 0 ); composer.SetFont(font,FontBaseSize); y += FontBaseSize * 2; } try { // Show the current character (using the current standard Type 1 font)! composer.ShowText( new String(new char[]{(char)charCode}), new PointF(x,y) ); x += FontBaseSize; if(x > pageSize.Width - Margin) {x = Margin; y += 30;} } catch { /* Ignore */ } } x = Margin; y += Margin; } } composer.Flush(); }