Exemplo n.º 1
0
        public BlocoQrCodeNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y, Document context) : base(estilo)
        {
            var result = new MemoryStream();

            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("CONSULTA VIA LEITOR DE QR CODE", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

            var bitmap = GerarQrCode.GerarQRCode(viewModel.QrCode);

            bitmap.Save(result, ImageFormat.Jpeg);
            result.Position = 0;
            org.pdfclown.documents.contents.entities.Image   image        = org.pdfclown.documents.contents.entities.Image.Get(result);
            org.pdfclown.documents.contents.xObjects.XObject imageXObject = image.ToXObject(context);

            primitiveComposer.ShowXObject(imageXObject, new PointF(140, y + 20), new SizeF(150, 150), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

            if (viewModel.CalculoImposto.ValorAproximadoTributos > 0)
            // valor aproximado dos tributos
            {
                primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, 7);

                primitiveComposer.ShowText($"CONFORME LEI 12.741/2012 o valor aproximado dos tributos é {viewModel.CalculoImposto.ValorAproximadoTributos.Formatar()}", new PointF(140, y + 180), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                primitiveComposer.ShowText($"O valor aproximado dos tributos Federais é {viewModel.CalculoImposto.ValorAproximadoTributosFederais.Formatar()}", new PointF(140, y + 190), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                primitiveComposer.ShowText($"O valor aproximado dos tributos Estaduais é {viewModel.CalculoImposto.ValorAproximadoTributosEstaduais.Formatar()}", new PointF(140, y + 200), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            }
        }
Exemplo n.º 2
0
        /**
         * <summary>Shows the specified external object.</summary>
         * <param name="xObject">External object.</param>
         * <param name="size">Size of the external object.</param>
         * <param name="lineAlignment">Line alignment. It can be:
         *  <list type="bullet">
         *    <item><see cref="LineAlignmentEnum"/></item>
         *    <item><see cref="Length">: arbitrary super-/sub-script, depending on whether the value is
         *    positive or not.</item>
         *  </list>
         * </param>
         * <returns>Whether the external object was successfully shown.</returns>
         */
        public bool ShowXObject(
            xObjects::XObject xObject,
            SizeF?size,
            object lineAlignment
            )
        {
            if (xObject == null ||
                !EnsureRow(true))
            {
                return(false);
            }

            if (!size.HasValue)
            {
                size = xObject.Size;
            }
            lineAlignment = ResolveLineAlignment(lineAlignment);

            while (true)
            {
                if (OperationUtils.Compare(currentRow.Y + size.Value.Height, frame.Height) == 1) // Object's height exceeds block's remaining vertical space.
                {
                    // Terminate current row and exit!
                    EndRow(false);
                    return(false);
                }
                else if (OperationUtils.Compare(currentRow.Width + size.Value.Width, frame.Width) < 1) // There's room for the object in the current row.
                {
                    PointF location = new PointF(
                        (float)currentRow.Width,
                        (float)currentRow.Y
                        );
                    RowObject obj;
                    {
                        obj = new RowObject(
                            RowObject.TypeEnum.XObject,
                            baseComposer.BeginLocalState(), // Opens the row object's local state.
                            size.Value.Height,
                            size.Value.Width,
                            0,
                            lineAlignment,
                            size.Value.Height,
                            0,
                            0
                            );
                        baseComposer.ShowXObject(xObject, location, size);
                        baseComposer.End(); // Closes the row object's local state.
                    }
                    AddRowObject(obj, lineAlignment);

                    return(true);
                }
                else // There's NOT enough room for the object in the current row.
                {
                    // Go to next row!
                    EndRow(false);
                    BeginRow();
                }
            }
        }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        private void PrintLogo(PrimitiveComposer comp, RectangleF area)
        {
            area = area.GetPaddedRectangleMm(1.5F, 1.5F, 1.5F, 1F);

            SizeF  bestsize = BestFitSize(Danfe._Logo.Size, area.Size);
            PointF point    = PointF.Empty;

            point.X = area.X + Math.Abs(area.Width - bestsize.Width) / 2F;
            point.Y = area.Y + Math.Abs(area.Height - bestsize.Height) / 2F;

            comp.ShowXObject(Danfe._Logo, point, bestsize);
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        private void ApplyWatermark(FormXObject watermark)
        {
            // 1. Instantiate the stamper!
            /* NOTE: The PageStamper is optimized for dealing with pages. */
            PageStamper stamper = new PageStamper();

            // 2. Inserting the watermark into each page of the document...
            foreach (Page page in watermark.Document.Pages)
            {
                // 2.1. Associate the page to the stamper!
                stamper.Page = page;

                // 2.2. Stamping the watermark on the foreground...
                // Get the content composer!
                PrimitiveComposer composer = stamper.Foreground;
                // Show the watermark into the page background!
                composer.ShowXObject(watermark);

                // 2.3. End the stamping!
                stamper.Flush();
            }
        }
Exemplo n.º 8
0
        protected override void ToXObjectInternal(PrimitiveComposer comp)
        {
            BlockComposer bComp = new BlockComposer(comp);

            PrintIdentificacaoEmitente(RetEmitente, bComp, comp);
            PrintDescricaoDanfe(RetDescDanfe, bComp, comp);

            var emitente = Danfe.Model.Emitente;

            comp.SafeDrawRectangle(RetCodigoBarras);
            comp.SafeDrawRectangle(RetCampoVariavel);

            comp.SetFont(Danfe.Font, 8);
            bComp.SafeBegin(RetCampoVariavel, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(MensagemConsulta);
            bComp.End();

            comp.Stroke();

            var barcode = new Barcode128C(Danfe.Model.ChaveAcesso, RetCodigoBarras.Size).ToXObject(Danfe.Document);

            comp.ShowXObject(barcode, new PointF(RetCodigoBarras.X, RetCodigoBarras.Y));
        }
Exemplo n.º 9
0
        private FormXObject BuildTemplate(
            Document document,
            DateTime creationDate
            )
        {
            // Create a template (form)!
              FormXObject template = new FormXObject(document, document.PageSize.Value);
              SizeF templateSize = template.Size;

              // Get form content stream!
              PrimitiveComposer composer = new PrimitiveComposer(template);

              // Showing the header image inside the common content stream...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "mountains.jpg")); // Abstract image (entity).
              // Show the image inside the common content stream!
              composer.ShowXObject(
            image.ToXObject(document),
            new PointF(0,0),
            new SizeF(templateSize.Width - 50, 125)
            );

              // Showing the 'PDFClown' label inside the common content stream...
              composer.BeginLocalState();
              composer.SetFillColor(new colorSpaces::DeviceRGBColor(115f / 255, 164f / 255, 232f / 255));
              // Set the font to use!
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Times,
              true,
              false
              ),
            120
            );
              // Show the text!
              composer.ShowText(
            "PDFClown",
            new PointF(
              0,
              templateSize.Height - (float)composer.State.Font.GetAscent(composer.State.FontSize)
              )
            );

              // Drawing the side rectangle...
              composer.DrawRectangle(
            new RectangleF(
              (float)templateSize.Width - 50,
              0,
              50,
              (float)templateSize.Height
              )
            );
              composer.Fill();
              composer.End();

              // Showing the side text inside the common content stream...
              composer.BeginLocalState();
              {
            composer.SetFont(
              new fonts::StandardType1Font(
            document,
            fonts::StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              8
              );
            composer.SetFillColor(colorSpaces::DeviceRGBColor.White);
            composer.BeginLocalState();
            {
              composer.Rotate(
            90,
            new PointF(
              templateSize.Width - 50,
              templateSize.Height - 25
              )
            );
              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.Begin(
            new RectangleF(0,0,300,50),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle
            );
              {
            blockComposer.ShowText("Generated by PDF Clown on " + creationDate);
            blockComposer.ShowBreak();
            blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
              }
              blockComposer.End();
            }
            composer.End();
              }
              composer.End();

              composer.Flush();

              return template;
        }
Exemplo n.º 10
0
        private void createPDF()
        {
            SaveFileDialog saveFileDialog2 = new SaveFileDialog();

            saveFileDialog2.Filter   = "PDF File|*.pdf";
            saveFileDialog2.Title    = "Save as PDF";
            saveFileDialog2.FileName = "" + profile.fname + " " + profile.sname + " 6CIT Results";

            File     file     = new File();
            Document document = file.Document;
            Page     page     = new Page(document);

            document.Pages.Add(page);

            PrimitiveComposer Composer = new PrimitiveComposer(page);

            Composer.SetLineWidth(200);

            //Image
            Image image = Image.Get("brain100.jpg");

            org.pdfclown.documents.contents.xObjects.XObject imageXObject = image.ToXObject(document);
            Composer.ShowXObject(imageXObject, new PointF(450, 40));
            Composer.Flush();

            //Title
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 32);
            Composer.ShowText("6CIT Results", new PointF(32, 40));

            //Heading 1
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 24);
            Composer.ShowText("Patient Details", new PointF(32, 100));

            //Heading 1 - Body
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 12);
            Composer.ShowText("NHS ID: " + profile.ID, new PointF(32, 140));
            Composer.ShowText("Name: " + profile.fname + " " + profile.sname, new PointF(32, 160));
            Composer.ShowText("Sex: " + profile.sex, new PointF(32, 180));
            Composer.ShowText("DOB: " + profile.DOB, new PointF(32, 200));
            Composer.ShowText("Address: " + profile.al1 + " " + profile.al2, new PointF(32, 220));
            Composer.ShowText("Postcode: " + profile.postcode, new PointF(32, 240));
            Composer.ShowText("Occupation: " + profile.occupation, new PointF(32, 260));
            Composer.ShowText("Test Score: " + score + " , Advice: " + calcAdvice(score), new PointF(32, 300));


            //Patient Notes
            BlockComposer bc = new BlockComposer(Composer);

            bc.Hyphenation = false;
            bc.LineSpace   = new Length(1.0, Length.UnitModeEnum.Relative);

            int notesLength = profile.notes.Length;
            int notesHeight = 40;
            int notesY      = 320;

            if (notesLength < 300)
            {
                notesHeight = 150;
            }
            else if (notesLength > 300 && notesLength < 600)
            {
                notesHeight = 200;
            }
            else if (notesLength > 600 && notesLength <= 1000)
            {
                notesHeight = 350;
            }

            RectangleF area = new RectangleF(new PointF(32, notesY), new SizeF(400, notesHeight));

            bc.Begin(area, XAlignmentEnum.Left, YAlignmentEnum.Top);
            bc.ShowText("Notes: " + "\n" + profile.notes);
            bc.End();

            Composer.Flush();

            var date = DateTime.Now;

            //Add Page 2
            Page page2 = new Page(document);

            document.Pages.Add(page2);
            Composer = new PrimitiveComposer(page2);

            //Heading 2
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 24);
            Composer.ShowText("6CIT Results ", new PointF(32, 40));

            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 12);
            Composer.ShowText("Test Carried out on: " /*+ Clinician Details Input Get*/ + " on: " + date, new PointF(32, 80));

            //Convert Question Answers to Temporary Text
            string six_q1_txt = "Incorrect";
            string six_q2_txt = "Incorrect";
            string six_q3_txt = "Incorrect";
            string six_q4_txt = "Incorrect";
            string six_q5_txt = "Incorrect";
            string six_q6_txt;

            if (q1 == 0)
            {
                six_q1_txt = "Correct";
            }
            if (q2 == 0)
            {
                six_q2_txt = "Correct";
            }
            if (q3 == 0)
            {
                six_q3_txt = "Correct";
            }

            //Q4
            if (q4 == 0)
            {
                six_q4_txt = "Correct";
            }
            else if (q4 == 4)
            {
                six_q4_txt = "More Than One Incorrect";
            }

            //Q5
            if (q5 == 0)
            {
                six_q5_txt = "Correct";
            }
            else if (q5 == 2)
            {
                six_q5_txt = "One Incorrect";
            }
            else if (q5 == 4)
            {
                six_q5_txt = "More Than One Incorrect";
            }

            //Q6
            if (q6 == 0)
            {
                six_q6_txt = "Correct";
            }
            else if (q6 == 2)
            {
                six_q6_txt = "One Incorrect";
            }
            else if (q6 == 4)
            {
                six_q6_txt = "More Than One Incorrect";
            }
            else if (q6 == 6)
            {
                six_q6_txt = "More Than Two Incorrect";
            }
            else if (q6 == 8)
            {
                six_q6_txt = "More Than Three Incorrect";
            }
            else if (q6 == 10)
            {
                six_q6_txt = "More Than Four Incorrect";
            }
            else
            {
                six_q6_txt = "All Incorrect";
            }

            Composer.ShowText("Question 1: What Year Is It? : ", new PointF(32, 120));
            Composer.ShowText(six_q1_txt, new PointF(32, 140));

            Composer.ShowText("Question 2: What Month Is It? : ", new PointF(32, 180));
            Composer.ShowText(six_q2_txt, new PointF(32, 200));

            Composer.ShowText("Question 3: What Time Is It? : ", new PointF(32, 240));
            Composer.ShowText(six_q3_txt, new PointF(32, 260));

            Composer.ShowText("Question 4: Count Backwards From 20 to 1: ", new PointF(32, 300));
            Composer.ShowText(six_q4_txt, new PointF(32, 320));

            Composer.ShowText("Question 5: Say The Months of the Year Backwards: ", new PointF(32, 360));
            Composer.ShowText(six_q5_txt, new PointF(32, 380));

            Composer.ShowText("Question 6: Repeat the Memory Phrase: ", new PointF(32, 420));
            Composer.ShowText(six_q6_txt, new PointF(32, 440));

            Composer.ShowText("Test Result was:  " + score, new PointF(32, 480));
            Composer.ShowText("Advice: " + calcAdvice(score), new PointF(32, 500));

            Composer.Flush();

            if (saveFileDialog2.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    file.Save(saveFileDialog2.FileName, SerializationModeEnum.Incremental);
                }
                catch (IOException)
                {
                    MessageBox.Show("File is open somewhere else; Cannot Save to PDF.");
                }
            }
        }
Exemplo n.º 11
0
        private void BuildWelcomePage(
            Document document,
            FormXObject template
            )
        {
            // Add welcome 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;

              PrimitiveComposer composer = new PrimitiveComposer(page);
              // Add the background template!
              composer.ShowXObject(template);
              // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!
              /*
            NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
            Flow-level typographic features are currently not supported: block-level typographic features
            are the foundations upon which flow-level typographic features will sit.
              */
              BlockComposer blockComposer = new BlockComposer(composer);

              SizeF breakSize = new SizeF(0,20); // Size of a paragraph break.
              // Instantiate the page body's font!
              fonts::Font font = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "lazyDog.ttf")
            );

              // Showing the page title...
              // Define the box frame to force the page title within!
              RectangleF frame = new RectangleF(
            20,
            150,
            (float)pageSize.Width - 90,
            (float)pageSize.Height - 250
            );
              // Begin the block!
              blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Top);
              // Set the font to use!
              composer.SetFont(font,56);
              // Set the text rendering mode (outline only)!
              composer.SetTextRenderMode(TextRenderModeEnum.Stroke);
              // Show the page title!
              blockComposer.ShowText("Welcome");
              // End the block!
              blockComposer.End();

              // Showing the clown photo...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
              PointF imageLocation = new PointF(
            blockComposer.BoundBox.X + blockComposer.BoundBox.Width - image.Width,
            blockComposer.BoundBox.Y + blockComposer.BoundBox.Height + 25
            );
              // Show the image!
              composer.ShowXObject(
            image.ToXObject(document),
            imageLocation
            );

              RectangleF descriptionFrame = new RectangleF(
            imageLocation.X,
            imageLocation.Y + image.Height + 5,
            image.Width,
            20
            );

              frame = new RectangleF(
            blockComposer.BoundBox.X,
            imageLocation.Y,
            blockComposer.BoundBox.Width - image.Width - 20,
            image.Height
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Middle);
              {
            composer.SetFont(font,30);
            blockComposer.ShowText("This is a sample document that merely demonstrates some basic graphics features supported by PDF Clown.");
            blockComposer.ShowBreak(XAlignmentEnum.Center);
            blockComposer.ShowText("Enjoy!");
              }
              blockComposer.End();

              frame = new RectangleF(
            blockComposer.BoundBox.X,
            blockComposer.BoundBox.Y+blockComposer.BoundBox.Height,
            pageSize.Width - 90,
            pageSize.Height - 100 - (blockComposer.BoundBox.Y+blockComposer.BoundBox.Height)
            );
              blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Bottom);
              {
            composer.SetFont(font,14);
            blockComposer.ShowText("PS: As promised, since version 0.0.3 PDF Clown has supported");
            // Begin local state!
            /*
              NOTE: Local state is a powerful feature of PDF format as it lets you nest
              multiple graphics contexts on the graphics state stack.
            */
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText(" embedded latin OpenFont/TrueType and non-embedded Type 1 fonts");
            }
            composer.End();
            blockComposer.ShowText(" along with");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText(" paragraph construction facilities");
            }
            composer.End();
            blockComposer.ShowText(" through the BlockComposer class.");
            blockComposer.ShowBreak(breakSize);

            blockComposer.ShowText("Since version 0.0.4 the content stream stack has been completed, providing ");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText("fully object-oriented access to the graphics objects that describe the contents on a page.");
            }
            composer.End();
            blockComposer.ShowText(" It's a great step towards a whole bunch of possibilities, such as text extraction/replacement, that next releases will progressively exploit.");
            blockComposer.ShowBreak(breakSize);

            blockComposer.ShowText("Since version 0.0.6 it has supported ");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText("Unicode");
            }
            composer.End();
            blockComposer.ShowText(" for OpenFont/TrueType fonts.");
            blockComposer.ShowBreak(breakSize);

            composer.SetFont(font,8);
            blockComposer.ShowText("This page was crafted with the nice");
            composer.BeginLocalState();
            {
              composer.SetFont(font,10);
              blockComposer.ShowText(" LazyDog font");
            }
            composer.End();
            blockComposer.ShowText(" (by Paul Neave, www.neave.com)");
              }
              blockComposer.End();

              blockComposer.Begin(descriptionFrame,XAlignmentEnum.Right,YAlignmentEnum.Top);
              {
            composer.SetFont(font,8);
            blockComposer.ShowText("Source: http://www.wikipedia.org/");
              }
              blockComposer.End();

              composer.Flush();
        }
Exemplo n.º 12
0
        private FormXObject BuildTemplate(Document document, DateTime creationDate)
        {
            // Create a template (form)!
            FormXObject template     = new FormXObject(document, document.PageSize.Value);
            SKSize      templateSize = template.Size;

            // Get form content stream!
            PrimitiveComposer composer = new PrimitiveComposer(template);

            // Showing the header image inside the common content stream...
            // Instantiate a jpeg image object!
            entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "mountains.jpg")); // Abstract image (entity).

            // Show the image inside the common content stream!
            composer.ShowXObject(
                image.ToXObject(document),
                new SKPoint(0, 0),
                new SKSize(templateSize.Width - 50, 125)
                );

            // Showing the 'PdfClown' label inside the common content stream...
            composer.BeginLocalState();
            composer.SetFillColor(new colorSpaces::DeviceRGBColor(115f / 255, 164f / 255, 232f / 255));
            // Set the font to use!
            composer.SetFont(fonts::PdfType1Font.Load(document, fonts::PdfType1Font.FamilyEnum.Times, true, false), 120);
            // Show the text!
            composer.ShowText(
                "PdfClown",
                new SKPoint(
                    0,
                    templateSize.Height - (float)composer.State.Font.GetAscent(composer.State.FontSize)
                    )
                );

            // Drawing the side rectangle...
            composer.DrawRectangle(
                SKRect.Create(
                    (float)templateSize.Width - 50,
                    0,
                    50,
                    (float)templateSize.Height
                    )
                );
            composer.Fill();
            composer.End();

            // Showing the side text inside the common content stream...
            composer.BeginLocalState();
            {
                composer.SetFont(fonts::PdfType1Font.Load(document, fonts::PdfType1Font.FamilyEnum.Helvetica, false, false), 8);
                composer.SetFillColor(colorSpaces::DeviceRGBColor.White);
                composer.BeginLocalState();
                {
                    composer.Rotate(
                        90,
                        new SKPoint(
                            templateSize.Width - 50,
                            templateSize.Height - 25
                            )
                        );
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(
                        SKRect.Create(0, 0, 300, 50),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Middle
                        );
                    {
                        blockComposer.ShowText("Generated by PDF Clown on " + creationDate);
                        blockComposer.ShowBreak();
                        blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
                    }
                    blockComposer.End();
                }
                composer.End();
            }
            composer.End();

            composer.Flush();

            return(template);
        }
Exemplo n.º 13
0
        private void BuildWelcomePage(Document document, FormXObject template)
        {
            // Add welcome 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.
            SKSize pageSize = page.Size;

            PrimitiveComposer composer = new PrimitiveComposer(page);

            // Add the background template!
            composer.ShowXObject(template);
            // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!

            /*
             * NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
             * Flow-level typographic features are currently not supported: block-level typographic features
             * are the foundations upon which flow-level typographic features will sit.
             */
            BlockComposer blockComposer = new BlockComposer(composer);

            SKSize breakSize = new SKSize(0, 20); // Size of a paragraph break.
                                                  // Instantiate the page body's font!
            fonts::Font font = fonts::PdfType0Font.Load(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "lazyDog.ttf"));

            // Showing the page title...
            // Define the box frame to force the page title within!
            SKRect frame = SKRect.Create(
                20,
                150,
                (float)pageSize.Width - 90,
                (float)pageSize.Height - 250
                );

            // Begin the block!
            blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Top);
            // Set the font to use!
            composer.SetFont(font, 56);
            // Set the text rendering mode (outline only)!
            composer.SetTextRenderMode(TextRenderModeEnum.Stroke);
            // Show the page title!
            blockComposer.ShowText("Welcome");
            // End the block!
            blockComposer.End();

            // Showing the clown photo...
            // Instantiate a jpeg image object!
            entities::Image image         = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
            SKPoint         imageLocation = new SKPoint(
                blockComposer.BoundBox.Left + blockComposer.BoundBox.Width - image.Width,
                blockComposer.BoundBox.Top + blockComposer.BoundBox.Height + 25
                );

            // Show the image!
            composer.ShowXObject(
                image.ToXObject(document),
                imageLocation
                );

            SKRect descriptionFrame = SKRect.Create(
                imageLocation.X,
                imageLocation.Y + image.Height + 5,
                image.Width,
                20
                );

            frame = SKRect.Create(
                blockComposer.BoundBox.Left,
                imageLocation.Y,
                blockComposer.BoundBox.Width - image.Width - 20,
                image.Height
                );
            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Middle);
            {
                composer.SetFont(font, 30);
                blockComposer.ShowText("This is a sample document that merely demonstrates some basic graphics features supported by PDF Clown.");
                blockComposer.ShowBreak(XAlignmentEnum.Center);
                blockComposer.ShowText("Enjoy!");
            }
            blockComposer.End();

            frame = SKRect.Create(
                blockComposer.BoundBox.Left,
                blockComposer.BoundBox.Top + blockComposer.BoundBox.Height,
                pageSize.Width - 90,
                pageSize.Height - 100 - (blockComposer.BoundBox.Top + blockComposer.BoundBox.Height)
                );
            blockComposer.Begin(frame, XAlignmentEnum.Justify, YAlignmentEnum.Bottom);
            {
                composer.SetFont(font, 14);
                blockComposer.ShowText("PS: As promised, since version 0.0.3 PDF Clown has supported");
                // Begin local state!

                /*
                 * NOTE: Local state is a powerful feature of PDF format as it lets you nest
                 * multiple graphics contexts on the graphics state stack.
                 */
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText(" embedded latin OpenFont/TrueType and non-embedded Type 1 fonts");
                }
                composer.End();
                blockComposer.ShowText(" along with");
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText(" paragraph construction facilities");
                }
                composer.End();
                blockComposer.ShowText(" through the BlockComposer class.");
                blockComposer.ShowBreak(breakSize);

                blockComposer.ShowText("Since version 0.0.4 the content stream stack has been completed, providing ");
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText("fully object-oriented access to the graphics objects that describe the contents on a page.");
                }
                composer.End();
                blockComposer.ShowText(" It's a great step towards a whole bunch of possibilities, such as text extraction/replacement, that next releases will progressively exploit.");
                blockComposer.ShowBreak(breakSize);

                blockComposer.ShowText("Since version 0.0.6 it has supported ");
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText("Unicode");
                }
                composer.End();
                blockComposer.ShowText(" for OpenFont/TrueType fonts.");
                blockComposer.ShowBreak(breakSize);

                composer.SetFont(font, 8);
                blockComposer.ShowText("This page was crafted with the nice");
                composer.BeginLocalState();
                {
                    composer.SetFont(font, 10);
                    blockComposer.ShowText(" LazyDog font");
                }
                composer.End();
                blockComposer.ShowText(" (by Paul Neave, www.neave.com)");
            }
            blockComposer.End();

            blockComposer.Begin(descriptionFrame, XAlignmentEnum.Right, YAlignmentEnum.Top);
            {
                composer.SetFont(font, 8);
                blockComposer.ShowText("Source: http://www.wikipedia.org/");
            }
            blockComposer.End();

            composer.Flush();
        }
Exemplo n.º 14
0
        private void PrintLogo(PrimitiveComposer comp, RectangleF area)
        {
            area = area.GetPaddedRectangleMm(1.5F, 1.5F, 1.5F, 1F);

            SizeF bestsize = BestFitSize(Danfe._Logo.Size, area.Size);
            PointF point = PointF.Empty;
            point.X = area.X + Math.Abs(area.Width - bestsize.Width) / 2F;
            point.Y = area.Y + Math.Abs(area.Height - bestsize.Height) / 2F;

            comp.ShowXObject(Danfe._Logo, point, bestsize);
        }
Exemplo n.º 15
0
        /**
         * <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(PdfType1Font.Load(document, PdfType1Font.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.ViewerPreferences.PageMode = ViewerPreferences.PageModeEnum.Layers; // Shows the layers tab on document opening.

            // Get the root collection of the layers displayed to the user!
            UILayers uiLayers = layerDefinition.UILayers;

            // Nested layers.
            Layer parentLayer;
            {
                parentLayer = new Layer(document, "Parent layer");
                uiLayers.Add(parentLayer);
                var childLayers = parentLayer.Children;

                var childLayer1 = new Layer(document, "Child layer 1");
                childLayers.Add(childLayer1);

                var childLayer2 = new Layer(document, "Child layer 2");
                childLayers.Add(childLayer2);
                childLayer2.Locked = true;

                /*
                 * NOTE: Graphical content can be controlled through layers in two ways:
                 * 1) marking content within content streams (that is content within the page body);
                 * 2) associating annotations and external objects (XObject) to the layers.
                 */

                XObject imageXObject = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")).ToXObject(document);
                imageXObject.Layer = childLayer1; // Associates the image to the layer.

                composer.ShowXObject(imageXObject, new SKPoint(200, 75));

                composer.BeginLayer(parentLayer); // Opens a marked block associating its contents with the specified layer.
                composer.ShowText(parentLayer.Title, new SKPoint(50, 50));
                composer.End();                   // Closes the marked block.

                composer.BeginLayer(childLayer1);
                composer.ShowText(childLayer1.Title, new SKPoint(50, 75));
                composer.End();

                composer.BeginLayer(childLayer2);
                composer.ShowText(childLayer2.Title, new SKPoint(50, 100));
                composer.End();
            }

            // Simple layer collection (labeled collection of inclusive-state layers).
            Layer simpleLayer1;
            {
                var simpleLayerCollection = new LayerCollection(document, "Simple layer collection");
                uiLayers.Add(simpleLayerCollection);

                simpleLayer1 = new Layer(document, "Simple layer 1");
                simpleLayerCollection.Add(simpleLayer1);

                var simpleLayer2 = new Layer(document, "Simple layer 2 (Design)");

                /*
                 * NOTE: Intent limits layer use in determining visibility to specific use contexts. In this
                 * case, we want to mark content as intended to represent a document designer's structural
                 * organization of artwork, hence it's outside the interactive use by document consumers.
                 */
                simpleLayer2.Intents = new HashSet <PdfName> {
                    IntentEnum.Design.Name()
                };
                simpleLayerCollection.Add(simpleLayer2);

                var simpleLayer3 = new Layer(document, "Simple layer 3");
                simpleLayerCollection.Add(simpleLayer3);

                blockComposer.Begin(SKRect.Create(50, 125, 200, 75), XAlignmentEnum.Left, YAlignmentEnum.Middle);

                composer.BeginLayer(simpleLayer1);
                blockComposer.ShowText(simpleLayer1.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(simpleLayer2);
                blockComposer.ShowText(simpleLayer2.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(simpleLayer3);
                blockComposer.ShowText(simpleLayer3.Title);
                composer.End();

                blockComposer.End();
            }

            // Radio layer collection (labeled collection of exclusive-state layers).
            Layer radioLayer2;

            {
                var radioLayerCollection = new LayerCollection(document, "Radio layer collection");
                uiLayers.Add(radioLayerCollection);

                var radioLayer1 = new Layer(document, "Radio layer 1")
                {
                    Visible = true
                };
                radioLayerCollection.Add(radioLayer1);

                radioLayer2 = new Layer(document, "Radio layer 2")
                {
                    Visible = false
                };
                radioLayerCollection.Add(radioLayer2);

                var radioLayer3 = new Layer(document, "Radio layer 3")
                {
                    Visible = false
                };
                radioLayerCollection.Add(radioLayer3);

                // Register this option group in the layer configuration!
                var optionGroup = new OptionGroup(document)
                {
                    radioLayer1, radioLayer2, radioLayer3
                };
                layerDefinition.OptionGroups.Add(optionGroup);

                blockComposer.Begin(SKRect.Create(50, 200, 200, 75), XAlignmentEnum.Left, YAlignmentEnum.Middle);

                composer.BeginLayer(radioLayer1);
                blockComposer.ShowText(radioLayer1.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(radioLayer2);
                blockComposer.ShowText(radioLayer2.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(radioLayer3);
                blockComposer.ShowText(radioLayer3.Title);
                composer.End();

                blockComposer.End();
            }

            // Layer state action.
            {
                var actionLayer = new Layer(document, "Action layer")
                {
                    Printable = false
                };

                composer.BeginLayer(actionLayer);
                composer.BeginLocalState();
                composer.SetFillColor(colors::DeviceRGBColor.Get(SKColors.Blue));
                composer.ShowText(
                    "Layer state action:\n * deselect \"" + simpleLayer1.Title + "\"\n   and \"" + radioLayer2.Title + "\"\n * toggle \"" + parentLayer.Title + "\"",
                    new SKPoint(400, 200),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0,
                    new SetLayerState(
                        document,
                        new SetLayerState.LayerState(SetLayerState.StateModeEnum.Off, simpleLayer1, radioLayer2),
                        new SetLayerState.LayerState(SetLayerState.StateModeEnum.Toggle, parentLayer)
                        )
                    );
                composer.End();
                composer.End();
            }

            // Zoom-restricted layer.
            {
                var zoomRestrictedLayer = new Layer(document, "Zoom-restricted layer")
                {
                    ZoomRange = new Interval <double>(.75, 1.251)
                };                                                // NOTE: Change this interval to test other magnification ranges.

                composer.BeginLayer(zoomRestrictedLayer);
                new TextMarkup(
                    page,
                    composer.ShowText(zoomRestrictedLayer.Title + ": this text is only visible if zoom between 75% and 125%", new SKPoint(50, 290)),
                    "This is a highlight annotation visible only if zoom is between 75% and 125%",
                    TextMarkupType.Highlight
                    )
                {
                    Layer = zoomRestrictedLayer /* Associates the annotation to the layer. */
                };
                composer.End();
            }

            // Print-only layer.
            {
                var printOnlyLayer = new Layer(document, "Print-only layer")
                {
                    Visible   = false,
                    Printable = true
                };

                composer.BeginLayer(printOnlyLayer);
                composer.BeginLocalState();
                composer.SetFillColor(colors::DeviceRGBColor.Get(SKColors.Red));
                composer.ShowText(printOnlyLayer.Title, new SKPoint(25, 300), XAlignmentEnum.Left, YAlignmentEnum.Top, 90);
                composer.End();
                composer.End();
            }

            // Language-specific layer.
            {
                var languageLayer = new Layer(document, "Language-specific layer")
                {
                    Language          = new LanguageIdentifier("en-GB"), // NOTE: Change this to test other languages and locales.
                    LanguagePreferred = true,                            // Matches any system locale (e.g. en-US, en-AU...) if layer language (en-GB) doesn't match exactly the system language.
                    Printable         = false
                };

                blockComposer.Begin(SKRect.Create(50, 320, 500, 75), XAlignmentEnum.Left, YAlignmentEnum.Top);

                composer.BeginLayer(languageLayer);
                blockComposer.ShowText(languageLayer.Title + ": this text is visible only if current system language is english (\"en\", any locale (\"en-US\", \"en-GB\", \"en-NZ\", etc.)) and is hidden on print.");
                composer.End();

                blockComposer.End();
            }

            // User-specific layer.
            {
                var userLayer = new Layer(document, "User-specific layer")
                {
                    Users = new List <string> {
                        "Lizbeth", "Alice", "Stefano", "Johann"
                    },                                                                    // NOTE: Change these entries to test other user names.
                    UserType = Layer.UserTypeEnum.Individual
                };

                blockComposer.Begin(SKRect.Create(blockComposer.BoundBox.Left, blockComposer.BoundBox.Bottom + 15, blockComposer.BoundBox.Width, 75), XAlignmentEnum.Left, YAlignmentEnum.Top);

                composer.BeginLayer(userLayer);
                blockComposer.ShowText(userLayer.Title + ": this text is visible only to " + String.Join(", ", userLayer.Users) + " (exact match).");
                composer.End();

                blockComposer.End();
            }

            // Layer membership (composite layer visibility).
            {
                var layerMembership = new LayerMembership(document)
                {
                    /*
                     * NOTE: VisibilityExpression is a more flexible alternative to the combination of
                     * VisibilityPolicy and VisibilityMembers. However, for compatibility purposes is preferable
                     * to provide both of them (the latter combination will work as a fallback in case of older
                     * viewer application).
                     */
                    VisibilityExpression = new VisibilityExpression(
                        document,
                        VisibilityExpression.OperatorEnum.And,
                        new VisibilityExpression(
                            document,
                            VisibilityExpression.OperatorEnum.Not,
                            new VisibilityExpression(
                                document,
                                VisibilityExpression.OperatorEnum.Or,
                                simpleLayer1,
                                radioLayer2
                                )
                            ),
                        parentLayer
                        ),
                    VisibilityPolicy  = LayerMembership.VisibilityPolicyEnum.AnyOff,
                    VisibilityMembers = new List <Layer> {
                        simpleLayer1, radioLayer2, parentLayer
                    }
                };

                blockComposer.Begin(SKRect.Create(blockComposer.BoundBox.Left, blockComposer.BoundBox.Bottom + 15, blockComposer.BoundBox.Width, 75), XAlignmentEnum.Left, YAlignmentEnum.Top);

                composer.BeginLayer(layerMembership);
                blockComposer.ShowText(String.Format("Layer membership: the visibility of this text is computed combining multiple layer states into an expression (\"{0}\" and \"{1}\" must be OFF while \"{2}\" must be ON).", simpleLayer1.Title, radioLayer2.Title, parentLayer.Title));
                composer.End();

                blockComposer.End();
            }

            composer.Flush();
        }
Exemplo n.º 16
0
        /**
          <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();
              }
        }
Exemplo n.º 17
0
        private void BuildFreeSoftwareDefinitionPages(
            Document document,
            FormXObject template
            )
        {
            // Add page!
              Page page = new Page(document);
              document.Pages.Add(page);
              SizeF pageSize = page.Size;

              string title = "The Free Software Definition";

              // Create the article thread!
              Article article = new Article(document);
              {
            Information articleInfo = article.Information;
            articleInfo.Title = title;
            articleInfo.Author = "Free Software Foundation, Inc.";
              }
              // Get the article beads collection to populate!
              ArticleElements articleElements = article.Elements;

              PrimitiveComposer composer = new PrimitiveComposer(page);
              // Add the background template!
              composer.ShowXObject(template);
              // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!
              /*
            NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
            Flow-level typographic features are currently not supported: block-level typographic features
            are the foundations upon which flow-level typographic features will sit.
              */
              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.Hyphenation = true;

              SizeF breakSize = new SizeF(0,10);
              // Add the font to the document!
              fonts::Font font = fonts::Font.Get(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf"));

              RectangleF frame = new RectangleF(
            20,
            150,
            (pageSize.Width - 90 - 20) / 2,
            pageSize.Height - 250
            );

              // Showing the 'GNU' image...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")); // Abstract image (entity).
              // Show the image!
              composer.ShowXObject(
            image.ToXObject(document),
            new PointF(
              (pageSize.Width - 90 - image.Width) / 2 + 20,
              pageSize.Height - 100 - image.Height)
            );

              // Showing the title...
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              composer.SetFont(font,24);
              blockComposer.ShowText(title);
              blockComposer.End();

              // Showing the copyright note...
              frame = new RectangleF(
            (float)blockComposer.BoundBox.X,
            (float)blockComposer.BoundBox.Y + blockComposer.BoundBox.Height + 32,
            (float)blockComposer.BoundBox.Width,
            (float)(pageSize.Height - 100 - image.Height - 10) - (blockComposer.BoundBox.Y + blockComposer.BoundBox.Height + 32)
            );
              blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Bottom);
              composer.SetFont(font,6);
              blockComposer.ShowText("Copyright 2004, 2005, 2006 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice is preserved.");

              // Showing the body...
              blockComposer.ShowBreak(breakSize);
              composer.SetFont(font,8.25f);
              RectangleF[] frames = new RectangleF[]
            {
              new RectangleF(
            (float)blockComposer.BoundBox.X,
            (float)pageSize.Height - 100 - image.Height - 10,
            (float)blockComposer.BoundBox.Width-image.Width/2,
            (float)image.Height + 10
            ),
              new RectangleF(
            (float)(20 + 20 + (pageSize.Width - 90 - 20) / 2),
            150,
            (float)(pageSize.Width - 90 - 20) / 2,
            (float)(pageSize.Height - 100 - image.Height - 10) - 150
            ),
              new RectangleF(
            (float)(20 + 20 + (pageSize.Width - 90 - 20) / 2 + image.Width/2),
            (float)pageSize.Height - 100 - image.Height - 10,
            (float)blockComposer.BoundBox.Width-image.Width/2,
            (float)image.Height + 10
            ),
              new RectangleF(
            20,
            150,
            (float)(pageSize.Width - 90 - 20) / 2,
            (float)(pageSize.Height - 100) - 150
            ),
              new RectangleF(
            (float)(20 + 20 + (pageSize.Width - 90 - 20) / 2),
            150,
            (float)(pageSize.Width - 90 - 20) / 2,
            (float)(pageSize.Height - 100) - 150
            )
            };
              YAlignmentEnum[] yAlignments = new YAlignmentEnum[]
            {
              YAlignmentEnum.Top,
              YAlignmentEnum.Bottom,
              YAlignmentEnum.Top,
              YAlignmentEnum.Top,
              YAlignmentEnum.Top
            };
              String[] paragraphs = new String[]
            {
              "We maintain this free software definition to show clearly what must be true about a particular software program for it to be considered free software.",
              "\"Free software\" is a matter of liberty, not price. To understand the concept, you should think of \"free\" as in \"free speech\", not as in \"free beer\".",
              "Free software is a matter of the users' freedom to run, copy, distribute, study, change and improve the software. More precisely, it refers to four kinds of freedom, for the users of the software:",
              "* The freedom to run the program, for any purpose (freedom 0).",
              "* The freedom to study how the program works, and adapt it to your needs (freedom 1). Access to the source code is a precondition for this.",
              "* The freedom to redistribute copies so you can help your neighbor (freedom 2).",
              "* The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this.",
              "A program is free software if users have all of these freedoms. Thus, you should be free to redistribute copies, either with or without modifications, either gratis or charging a fee for distribution, to anyone anywhere. Being free to do these things means (among other things) that you do not have to ask or pay for permission.",
              "You should also have the freedom to make modifications and use them privately in your own work or play, without even mentioning that they exist. If you do publish your changes, you should not be required to notify anyone in particular, or in any particular way.",
              "The freedom to use a program means the freedom for any kind of person or organization to use it on any kind of computer system, for any kind of overall job, and without being required to communicate subsequently with the developer or any other specific entity.",
              "The freedom to redistribute copies must include binary or executable forms of the program, as well as source code, for both modified and unmodified versions. (Distributing programs in runnable form is necessary for conveniently installable free operating systems.) It is ok if there is no way to produce a binary or executable form for a certain program (since some languages don't support that feature), but you must have the freedom to redistribute such forms should you find or develop a way to make them.",
              "In order for the freedoms to make changes, and to publish improved versions, to be meaningful, you must have access to the source code of the program. Therefore, accessibility of source code is a necessary condition for free software.",
              "In order for these freedoms to be real, they must be irrevocable as long as you do nothing wrong; if the developer of the software has the power to revoke the license, without your doing anything to give cause, the software is not free.",
              "However, certain kinds of rules about the manner of distributing free software are acceptable, when they don't conflict with the central freedoms. For example, copyleft (very simply stated) is the rule that when redistributing the program, you cannot add restrictions to deny other people the central freedoms. This rule does not conflict with the central freedoms; rather it protects them.",
              "You may have paid money to get copies of free software, or you may have obtained copies at no charge. But regardless of how you got your copies, you always have the freedom to copy and change the software, even to sell copies.",
              "\"Free software\" does not mean \"non-commercial\". A free program must be available for commercial use, commercial development, and commercial distribution. Commercial development of free software is no longer unusual; such free commercial software is very important.",
              "Rules about how to package a modified version are acceptable, if they don't substantively block your freedom to release modified versions. Rules that \"if you make the program available in this way, you must make it available in that way also\" can be acceptable too, on the same condition. (Note that such a rule still leaves you the choice of whether to publish the program or not.) It is also acceptable for the license to require that, if you have distributed a modified version and a previous developer asks for a copy of it, you must send one, or that you identify yourself on your modifications.",
              "In the GNU project, we use \"copyleft\" to protect these freedoms legally for everyone. But non-copylefted free software also exists. We believe there are important reasons why it is better to use copyleft, but if your program is non-copylefted free software, we can still use it.",
              "See Categories of Free Software for a description of how \"free software,\" \"copylefted software\" and other categories of software relate to each other.",
              "Sometimes government export control regulations and trade sanctions can constrain your freedom to distribute copies of programs internationally. Software developers do not have the power to eliminate or override these restrictions, but what they can and must do is refuse to impose them as conditions of use of the program. In this way, the restrictions will not affect activities and people outside the jurisdictions of these governments.",
              "Most free software licenses are based on copyright, and there are limits on what kinds of requirements can be imposed through copyright. If a copyright-based license respects freedom in the ways described above, it is unlikely to have some other sort of problem that we never anticipated (though this does happen occasionally). However, some free software licenses are based on contracts, and contracts can impose a much larger range of possible restrictions. That means there are many possible ways such a license could be unacceptably restrictive and non-free.",
              "We can't possibly list all the possible contract restrictions that would be unacceptable. If a contract-based license restricts the user in an unusual way that copyright-based licenses cannot, and which isn't mentioned here as legitimate, we will have to think about it, and we will probably decide it is non-free.",
              "When talking about free software, it is best to avoid using terms like \"give away\" or \"for free\", because those terms imply that the issue is about price, not freedom. Some common terms such as \"piracy\" embody opinions we hope you won't endorse. See Confusing Words and Phrases that are Worth Avoiding for a discussion of these terms. We also have a list of translations of \"free software\" into various languages.",
              "Finally, note that criteria such as those stated in this free software definition require careful thought for their interpretation. To decide whether a specific software license qualifies as a free software license, we judge it based on these criteria to determine whether it fits their spirit as well as the precise words. If a license includes unconscionable restrictions, we reject it, even if we did not anticipate the issue in these criteria. Sometimes a license requirement raises an issue that calls for extensive thought, including discussions with a lawyer, before we can decide if the requirement is acceptable. When we reach a conclusion about a new issue, we often update these criteria to make it easier to see why certain licenses do or don't qualify.",
              "If you are interested in whether a specific license qualifies as a free software license, see our list of licenses. If the license you are concerned with is not listed there, you can ask us about it by sending us email at <*****@*****.**>.",
              "If you are contemplating writing a new license, please contact the FSF by writing to that address. The proliferation of different free software licenses means increased work for users in understanding the licenses; we may be able to help you find an existing Free Software license that meets your needs.",
              "If that isn't possible, if you really need a new license, with our help you can ensure that the license really is a Free Software license and avoid various practical problems.",
              "Another group has started using the term \"open source\" to mean something close (but not identical) to \"free software\". We prefer the term \"free software\" because, once you have heard it refers to freedom rather than price, it calls to mind freedom. The word \"open\" never does that."
            };
              int paragraphIndex = 0;
              int paragraphTextIndex = 0;
              int frameIndex = -1;
              for(
            int paragraphCount = paragraphs.Length;
            paragraphIndex < paragraphCount;
            paragraphIndex++
            )
              {
            String paragraph = paragraphs[paragraphIndex];

            paragraphTextIndex = blockComposer.ShowText(paragraph.Substring(paragraphTextIndex)) + paragraphTextIndex;
            if(paragraphTextIndex < paragraph.Length)
            {
              if(++frameIndex < frames.Length)
              {
            blockComposer.End();

            // Add the bead to the article thread!
            articleElements.Add(new ArticleElement(page, blockComposer.BoundBox));

            // New page?
            if(frameIndex == 3)
            {
              // Close current page!
              composer.Flush();

              // Create a new page!
              document.Pages.Add(page = new Page(document));
              composer = new PrimitiveComposer(page);
              // Add the background template!
              composer.ShowXObject(template);
              blockComposer = new BlockComposer(composer);
              blockComposer.Hyphenation = true;
            }

            blockComposer.Begin(frames[frameIndex],XAlignmentEnum.Justify,yAlignments[frameIndex]);
            composer.SetFont(font,8.25f);

            // Come back to complete the interrupted paragraph!
            paragraphIndex--;
              }
              else
              {break;}
            }
            else
            {
              paragraphTextIndex = 0;

              blockComposer.ShowBreak(breakSize);
            }
              }
              blockComposer.End();

              // Add the bead to the article thread!
              articleElements.Add(new ArticleElement(page, blockComposer.BoundBox));

              blockComposer.Begin(frames[frames.Length-1],XAlignmentEnum.Justify,YAlignmentEnum.Bottom);
              composer.SetFont(font,6);
              blockComposer.ShowText("This article was crafted with the nice Traveling_Typewriter font (by Carl Krull, www.carlkrull.dk).");
              blockComposer.End();

              composer.Flush();
        }
Exemplo n.º 18
0
        /**
         * <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();
        }
Exemplo n.º 19
0
        /**
         * <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();
            }
        }
Exemplo n.º 20
0
        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();
        }
Exemplo n.º 21
0
        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();
        }
Exemplo n.º 22
0
        private void BuildFreeSoftwareDefinitionPages(
            Document document,
            FormXObject template
            )
        {
            // Add page!
            Page page = new Page(document);

            document.Pages.Add(page);
            SKSize pageSize = page.Size;

            string title = "The Free Software Definition";

            // Create the article thread!
            Article article = new Article(document);
            {
                Information articleInfo = article.Information;
                articleInfo.Title  = title;
                articleInfo.Author = "Free Software Foundation, Inc.";
            }
            // Get the article beads collection to populate!
            ArticleElements articleElements = article.Elements;

            PrimitiveComposer composer = new PrimitiveComposer(page);

            // Add the background template!
            composer.ShowXObject(template);
            // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!

            /*
             * NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
             * Flow-level typographic features are currently not supported: block-level typographic features
             * are the foundations upon which flow-level typographic features will sit.
             */
            BlockComposer blockComposer = new BlockComposer(composer);

            blockComposer.Hyphenation = true;

            SKSize breakSize = new SKSize(0, 10);
            // Add the font to the document!
            fonts::Font font = fonts::PdfType0Font.Load(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf"));

            SKRect frame = SKRect.Create(
                20,
                150,
                (pageSize.Width - 90 - 20) / 2,
                pageSize.Height - 250
                );

            // Showing the 'GNU' image...
            // Instantiate a jpeg image object!
            entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")); // Abstract image (entity).

            // Show the image!
            composer.ShowXObject(
                image.ToXObject(document),
                new SKPoint(
                    (pageSize.Width - 90 - image.Width) / 2 + 20,
                    pageSize.Height - 100 - image.Height)
                );

            // Showing the title...
            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
            composer.SetFont(font, 24);
            blockComposer.ShowText(title);
            blockComposer.End();

            // Showing the copyright note...
            frame = SKRect.Create(
                (float)blockComposer.BoundBox.Left,
                (float)blockComposer.BoundBox.Top + blockComposer.BoundBox.Height + 32,
                (float)blockComposer.BoundBox.Width,
                (float)(pageSize.Height - 100 - image.Height - 10) - (blockComposer.BoundBox.Top + blockComposer.BoundBox.Height + 32)
                );
            blockComposer.Begin(frame, XAlignmentEnum.Justify, YAlignmentEnum.Bottom);
            composer.SetFont(font, 6);
            blockComposer.ShowText("Copyright 2004, 2005, 2006 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice is preserved.");

            // Showing the body...
            blockComposer.ShowBreak(breakSize);
            composer.SetFont(font, 8.25f);
            SKRect[] frames = new SKRect[]
            {
                SKRect.Create(
                    (float)blockComposer.BoundBox.Left,
                    (float)pageSize.Height - 100 - image.Height - 10,
                    (float)blockComposer.BoundBox.Width - image.Width / 2,
                    (float)image.Height + 10
                    ),
                SKRect.Create(
                    (float)(20 + 20 + (pageSize.Width - 90 - 20) / 2),
                    150,
                    (float)(pageSize.Width - 90 - 20) / 2,
                    (float)(pageSize.Height - 100 - image.Height - 10) - 150
                    ),
                SKRect.Create(
                    (float)(20 + 20 + (pageSize.Width - 90 - 20) / 2 + image.Width / 2),
                    (float)pageSize.Height - 100 - image.Height - 10,
                    (float)blockComposer.BoundBox.Width - image.Width / 2,
                    (float)image.Height + 10
                    ),
                SKRect.Create(
                    20,
                    150,
                    (float)(pageSize.Width - 90 - 20) / 2,
                    (float)(pageSize.Height - 100) - 150
                    ),
                SKRect.Create(
                    (float)(20 + 20 + (pageSize.Width - 90 - 20) / 2),
                    150,
                    (float)(pageSize.Width - 90 - 20) / 2,
                    (float)(pageSize.Height - 100) - 150
                    )
            };
            YAlignmentEnum[] yAlignments = new YAlignmentEnum[]
            {
                YAlignmentEnum.Top,
                YAlignmentEnum.Bottom,
                YAlignmentEnum.Top,
                YAlignmentEnum.Top,
                YAlignmentEnum.Top
            };
            String[] paragraphs = new String[]
            {
                "We maintain this free software definition to show clearly what must be true about a particular software program for it to be considered free software.",
                "\"Free software\" is a matter of liberty, not price. To understand the concept, you should think of \"free\" as in \"free speech\", not as in \"free beer\".",
                "Free software is a matter of the users' freedom to run, copy, distribute, study, change and improve the software. More precisely, it refers to four kinds of freedom, for the users of the software:",
                "* The freedom to run the program, for any purpose (freedom 0).",
                "* The freedom to study how the program works, and adapt it to your needs (freedom 1). Access to the source code is a precondition for this.",
                "* The freedom to redistribute copies so you can help your neighbor (freedom 2).",
                "* The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this.",
                "A program is free software if users have all of these freedoms. Thus, you should be free to redistribute copies, either with or without modifications, either gratis or charging a fee for distribution, to anyone anywhere. Being free to do these things means (among other things) that you do not have to ask or pay for permission.",
                "You should also have the freedom to make modifications and use them privately in your own work or play, without even mentioning that they exist. If you do publish your changes, you should not be required to notify anyone in particular, or in any particular way.",
                "The freedom to use a program means the freedom for any kind of person or organization to use it on any kind of computer system, for any kind of overall job, and without being required to communicate subsequently with the developer or any other specific entity.",
                "The freedom to redistribute copies must include binary or executable forms of the program, as well as source code, for both modified and unmodified versions. (Distributing programs in runnable form is necessary for conveniently installable free operating systems.) It is ok if there is no way to produce a binary or executable form for a certain program (since some languages don't support that feature), but you must have the freedom to redistribute such forms should you find or develop a way to make them.",
                "In order for the freedoms to make changes, and to publish improved versions, to be meaningful, you must have access to the source code of the program. Therefore, accessibility of source code is a necessary condition for free software.",
                "In order for these freedoms to be real, they must be irrevocable as long as you do nothing wrong; if the developer of the software has the power to revoke the license, without your doing anything to give cause, the software is not free.",
                "However, certain kinds of rules about the manner of distributing free software are acceptable, when they don't conflict with the central freedoms. For example, copyleft (very simply stated) is the rule that when redistributing the program, you cannot add restrictions to deny other people the central freedoms. This rule does not conflict with the central freedoms; rather it protects them.",
                "You may have paid money to get copies of free software, or you may have obtained copies at no charge. But regardless of how you got your copies, you always have the freedom to copy and change the software, even to sell copies.",
                "\"Free software\" does not mean \"non-commercial\". A free program must be available for commercial use, commercial development, and commercial distribution. Commercial development of free software is no longer unusual; such free commercial software is very important.",
                "Rules about how to package a modified version are acceptable, if they don't substantively block your freedom to release modified versions. Rules that \"if you make the program available in this way, you must make it available in that way also\" can be acceptable too, on the same condition. (Note that such a rule still leaves you the choice of whether to publish the program or not.) It is also acceptable for the license to require that, if you have distributed a modified version and a previous developer asks for a copy of it, you must send one, or that you identify yourself on your modifications.",
                "In the GNU project, we use \"copyleft\" to protect these freedoms legally for everyone. But non-copylefted free software also exists. We believe there are important reasons why it is better to use copyleft, but if your program is non-copylefted free software, we can still use it.",
                "See Categories of Free Software for a description of how \"free software,\" \"copylefted software\" and other categories of software relate to each other.",
                "Sometimes government export control regulations and trade sanctions can constrain your freedom to distribute copies of programs internationally. Software developers do not have the power to eliminate or override these restrictions, but what they can and must do is refuse to impose them as conditions of use of the program. In this way, the restrictions will not affect activities and people outside the jurisdictions of these governments.",
                "Most free software licenses are based on copyright, and there are limits on what kinds of requirements can be imposed through copyright. If a copyright-based license respects freedom in the ways described above, it is unlikely to have some other sort of problem that we never anticipated (though this does happen occasionally). However, some free software licenses are based on contracts, and contracts can impose a much larger range of possible restrictions. That means there are many possible ways such a license could be unacceptably restrictive and non-free.",
                "We can't possibly list all the possible contract restrictions that would be unacceptable. If a contract-based license restricts the user in an unusual way that copyright-based licenses cannot, and which isn't mentioned here as legitimate, we will have to think about it, and we will probably decide it is non-free.",
                "When talking about free software, it is best to avoid using terms like \"give away\" or \"for free\", because those terms imply that the issue is about price, not freedom. Some common terms such as \"piracy\" embody opinions we hope you won't endorse. See Confusing Words and Phrases that are Worth Avoiding for a discussion of these terms. We also have a list of translations of \"free software\" into various languages.",
                "Finally, note that criteria such as those stated in this free software definition require careful thought for their interpretation. To decide whether a specific software license qualifies as a free software license, we judge it based on these criteria to determine whether it fits their spirit as well as the precise words. If a license includes unconscionable restrictions, we reject it, even if we did not anticipate the issue in these criteria. Sometimes a license requirement raises an issue that calls for extensive thought, including discussions with a lawyer, before we can decide if the requirement is acceptable. When we reach a conclusion about a new issue, we often update these criteria to make it easier to see why certain licenses do or don't qualify.",
                "If you are interested in whether a specific license qualifies as a free software license, see our list of licenses. If the license you are concerned with is not listed there, you can ask us about it by sending us email at <*****@*****.**>.",
                "If you are contemplating writing a new license, please contact the FSF by writing to that address. The proliferation of different free software licenses means increased work for users in understanding the licenses; we may be able to help you find an existing Free Software license that meets your needs.",
                "If that isn't possible, if you really need a new license, with our help you can ensure that the license really is a Free Software license and avoid various practical problems.",
                "Another group has started using the term \"open source\" to mean something close (but not identical) to \"free software\". We prefer the term \"free software\" because, once you have heard it refers to freedom rather than price, it calls to mind freedom. The word \"open\" never does that."
            };
            int paragraphIndex     = 0;
            int paragraphTextIndex = 0;
            int frameIndex         = -1;

            for (int paragraphCount = paragraphs.Length; paragraphIndex < paragraphCount; paragraphIndex++)
            {
                String paragraph = paragraphs[paragraphIndex];

                paragraphTextIndex = blockComposer.ShowText(paragraph.Substring(paragraphTextIndex)) + paragraphTextIndex;
                if (paragraphTextIndex < paragraph.Length)
                {
                    if (++frameIndex < frames.Length)
                    {
                        blockComposer.End();

                        // Add the bead to the article thread!
                        articleElements.Add(new ArticleElement(page, blockComposer.BoundBox));

                        // New page?
                        if (frameIndex == 3)
                        {
                            // Close current page!
                            composer.Flush();

                            // Create a new page!
                            document.Pages.Add(page = new Page(document));
                            composer = new PrimitiveComposer(page);
                            // Add the background template!
                            composer.ShowXObject(template);
                            blockComposer             = new BlockComposer(composer);
                            blockComposer.Hyphenation = true;
                        }

                        blockComposer.Begin(frames[frameIndex], XAlignmentEnum.Justify, yAlignments[frameIndex]);
                        composer.SetFont(font, 8.25f);

                        // Come back to complete the interrupted paragraph!
                        paragraphIndex--;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    paragraphTextIndex = 0;

                    blockComposer.ShowBreak(breakSize);
                }
            }
            blockComposer.End();

            // Add the bead to the article thread!
            articleElements.Add(new ArticleElement(page, blockComposer.BoundBox));

            blockComposer.Begin(frames[frames.Length - 1], XAlignmentEnum.Justify, YAlignmentEnum.Bottom);
            composer.SetFont(font, 6);
            blockComposer.ShowText("This article was crafted with the nice Traveling_Typewriter font (by Carl Krull, www.carlkrull.dk).");
            blockComposer.End();

            composer.Flush();
        }
Exemplo n.º 23
0
        /**
          <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();
        }
Exemplo n.º 24
0
        protected override void ToXObjectInternal(PrimitiveComposer comp)
        {
            BlockComposer bComp = new BlockComposer(comp);

            PrintIdentificacaoEmitente(RetEmitente, bComp, comp);
            PrintDescricaoDanfe(RetDescDanfe, bComp, comp);

            var emitente = Danfe.Model.Emitente;

            comp.SafeDrawRectangle(RetCodigoBarras);
            comp.SafeDrawRectangle(RetCampoVariavel);

            comp.SetFont(Danfe.Font, 8);
            bComp.SafeBegin(RetCampoVariavel, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(MensagemConsulta);
            bComp.End();

            comp.Stroke();

            var barcode = new Barcode128C(Danfe.Model.ChaveAcesso, RetCodigoBarras.Size).ToXObject(Danfe.Document);
            comp.ShowXObject(barcode, new PointF(RetCodigoBarras.X, RetCodigoBarras.Y));
        }