Exemplo n.º 1
0
    internal PdfFormXObject(PdfDocument thisDocument, XForm form)
      : base(thisDocument)
    {
      Elements.SetName(Keys.Type, "/XObject");
      Elements.SetName(Keys.Subtype, "/Form");

      //if (form.IsTemplate)
      //{ }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfContentWriter"/> class
 /// for creating a content stream of the specified form.
 /// </summary>
 public PdfContentWriter(DocumentRenderingContext context, XForm form, RenderMode renderMode) // , XGraphics gfx, XGraphicsPdfPageOptions options)
 {
   this.context = context;
   this.form = form;
   this.contentStreamDictionary = form;
   this.renderMode = renderMode;
   //this.colorMode = page.document.Options.ColorMode;
   //this.options = options;
   this.content = new StringBuilder();
   this.graphicsState = new PdfGraphicsState(this);
 }
Exemplo n.º 3
0
    void RealizeImageBrush(ImageBrush brush, ref XForm xform, ref XImage xImage)
    {
      //Debug.Assert(xform != null);

      //xform = new XForm(this.writer.Owner, new XRect(brush.Viewbox.X * 3 / 4, brush.Viewbox.Y * 3 / 4, brush.Viewbox.Width * 3 / 4, brush.Viewbox.Height * 3 / 4));

      //string imageUri = brush.ImageSource;


      FixedPage fpage = brush.GetParent<FixedPage>();
      if (fpage == null)
        Debug.Assert(false);

      FixedPayload payload = fpage.Document.Payload;

      // Get the font object.
      // Important: font.PdfFont is not yet defined here on the first call
      string uriString = brush.ImageSource;
      BitmapSource image = payload.GetImage(uriString);

      //      int factor = 1;
      //int width = (int)(100 * factor);
      //int height = (int)(100 * factor);
      //DrawingVisual visual = new DrawingVisual();
      //DrawingContext vdc = visual.RenderOpen();
      //vdc.DrawRectangle(Brushes.GreenYellow, null, new Rect(0, 0, width, height));
      //vdc.DrawLine(new Pen(Brushes.Red, 3), new Point(0, 0), new Point(100, 100));
      //vdc.DrawLine(new Pen(Brushes.Red, 3), new Point(100, 0), new Point(0, 100));
      //vdc.Close();
      //RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 72 * factor, 72 * factor, PixelFormats.Default);
      //rtb.Render(visual);

      //BitmapImage bitmapImage = new BitmapImage(

      xImage = XImage.FromBitmapSource(image);



      //XGraphics gfx = XGraphics.FromForm(xform);
      //gfx.DrawRectangle(XBrushes.Firebrick, new XRect(0, 0, 100, 100));


      //PdfContentWriter formWriter = new PdfContentWriter(xform, RenderMode.Default);

      ////formWriter.Size = brush.Viewport.Size;
      //formWriter.BeginContent(false);

      ////formWriter.WriteElement(visual);
      //formWriter.EndContent();
    }
Exemplo n.º 4
0
    void RealizeVisualBrush(VisualBrush brush, ref XForm xform)
    {
      //Debug.Assert(xform != null);

      xform = new XForm(this.writer.Owner, new XRect(brush.Viewbox.X * 3 / 4, brush.Viewbox.Y * 3 / 4, brush.Viewbox.Width * 3 / 4, brush.Viewbox.Height * 3 / 4));

      Visual visual = brush.Visual;
      PdfContentWriter formWriter = new PdfContentWriter(this.writer.Context, xform, RenderMode.Default);


      //formWriter.Size = brush.Viewport.Size;
      formWriter.BeginContent(false);
      formWriter.WriteElement(visual);
      formWriter.EndContent();
    }
Exemplo n.º 5
0
        public static void PDFExport(string Paydate)
        {
            string InvoiceNumber = "" + SelectedInvoiceNumber + "";

            PdfDocument document = new PdfDocument();
            document.Info.Title = "Invoice";
            document.Info.Author = "Jack Huckins";
            document.Info.Subject = "Service Invoice";

            PdfPage page = new PdfPage();
            page = document.AddPage();
            page.Width = XUnit.FromInch(8.5);
            page.Height = XUnit.FromInch(11);

            XGraphics gfx = default(XGraphics);
            gfx = XGraphics.FromPdfPage(page);

            XForm form = new XForm(document, XUnit.FromMillimeter(300), XUnit.FromMillimeter(300));

            XGraphics formGfx = default(XGraphics);
            formGfx = XGraphics.FromForm(form);

            XGraphicsState state = default(XGraphicsState);
            state = formGfx.Save();
            //..... Invoice Results
            GetInvResults(Paydate);
            PrepareInvoiceTop(formGfx, state, InvoiceNumber);
            PrepareInvoiceData(6, 217, formGfx);
            PrepareFooter(formGfx);

            state = formGfx.Save();
            formGfx.Dispose();
            gfx.DrawImage(form, 0, 0);
            //document.Save("c:\\Invoices\\Inv " + InvoiceNumber + ".pdf")
            SetReportPath();
            document.Save(ReportPath);
            TimeConnector.Data.ActionLog.Insert("PDF Export", "" + InvoiceNumber + "");
            //UpdatePDFLabel("30 second Check", Form1.lblPDFStatus);
            //var _with1 = ViewPDF;
            //_with1.PdfName = Export.ReportPath;
            //_with1.Show();
        }
Exemplo n.º 6
0
    /// <summary>
    /// Creates an XForm from an image brush.
    /// </summary>
    public static XForm FromImageBrush(DocumentRenderingContext context, ImageBrush brush)
    {
      XPImage xpImage = ImageBuilder.FromImageBrush(context, brush);
      XImage ximage = xpImage.XImage;
      double width = ximage.PixelWidth;
      double height = ximage.PixelHeight;

      // view box in point
      // XRect box = new XRect(brush.Viewbox.X * 0.75, brush.Viewbox.Y * 0.75, brush.Viewbox.Width * 0.75, brush.Viewbox.Height * 0.75);
      XRect box = new XRect(0, 0, width, height);
      XForm xform = new XForm(context.PdfDocument, box);

      PdfContentWriter formWriter = new PdfContentWriter(context, xform, RenderMode.Default);

      Debug.Assert(ximage != null);

      PdfFormXObject pdfForm = xform.PdfForm;
      pdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix());

      //formWriter.Size = brush.Viewport.Size;
      formWriter.BeginContentRaw();

      string imageID = formWriter.Resources.AddImage(new PdfImage(context.PdfDocument, ximage));
      XMatrix matrix = new XMatrix();
      double scaleX = brush.Viewport.Width / brush.Viewbox.Width * 4 / 3 * ximage.PointWidth;
      double scaleY = brush.Viewport.Height / brush.Viewbox.Height * 4 / 3 * ximage.PointHeight;
      matrix.TranslatePrepend(-brush.Viewbox.X, -brush.Viewbox.Y);
      matrix.ScalePrepend(scaleX, scaleY);
      matrix.TranslatePrepend(brush.Viewport.X / scaleX, brush.Viewport.Y / scaleY);

      matrix = new XMatrix(width, 0, 0, -height, 0, height);
      formWriter.WriteLiteral("q\n");
      // TODO:WriteClip(path.Data);
      //formWriter.WriteLiteral("{0:0.###} 0 0 -{1:0.###} {2:0.###} {3:0.###} cm 100 Tz {4} Do Q\n",
      //  matrix.M11, matrix.M22, matrix.OffsetX, matrix.OffsetY + brush.Viewport.Height, imageID);
      formWriter.WriteMatrix(matrix);
      formWriter.WriteLiteral(imageID + " Do Q\n");

      formWriter.EndContent();

      return xform;
    }
Exemplo n.º 7
0
        /// <summary>
        /// May I have a new polling cards generator for this election?
        /// </summary>
        /// <param name="electionName">The name of the election</param>
        /// <param name="electionDate">The date of the election</param>
        /// <param name="electionTime">The timespan of the election</param>
        public PollingCards(string electionName, string electionDate, string electionTime)
        {
            Contract.Requires(electionName != null);
            Contract.Requires(electionDate != null);
            Contract.Requires(electionTime != null);

            //Create the a new document
            document = new PdfDocument();

            //Create a template containing the non specific voter details
            template = new XForm(document,XUnit.FromMillimeter(Width), XUnit.FromMillimeter(Height));
            XGraphics gfx = XGraphics.FromForm(template);
            AddWatermark(gfx);
            DrawGraphics(gfx);
            ElectionDetails(gfx, electionName, electionDate, electionTime);
            Descriptions(gfx);

            //Release the XGraphics object
            gfx.Dispose();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets a PdfFormXObject from an XPdfForm. Because the returned objects must be unique, always
        /// a new instance of PdfFormXObject is created if none exists for the specified form. 
        /// </summary>
        public PdfFormXObject GetForm(XForm form)
        {
            // If the form already has a PdfFormXObject, return it.
            if (form._pdfForm != null)
            {
                Debug.Assert(form.IsTemplate, "An XPdfForm must not have a PdfFormXObject.");
                if (ReferenceEquals(form._pdfForm.Owner, Owner))
                    return form._pdfForm;
                //throw new InvalidOperationException("Because of a current limitation of PDFsharp an XPdfForm object can be used only within one single PdfDocument.");

                // Dispose PdfFromXObject when document has changed
                form._pdfForm = null;
            }

            XPdfForm pdfForm = form as XPdfForm;
            if (pdfForm != null)
            {
                // Is the external PDF file from which is imported already known for the current document?
                Selector selector = new Selector(form);
                PdfImportedObjectTable importedObjectTable;
                if (!_forms.TryGetValue(selector, out importedObjectTable))
                {
                    // No: Get the external document from the form and create ImportedObjectTable.
                    PdfDocument doc = pdfForm.ExternalDocument;
                    importedObjectTable = new PdfImportedObjectTable(Owner, doc);
                    _forms[selector] = importedObjectTable;
                }

                PdfFormXObject xObject = importedObjectTable.GetXObject(pdfForm.PageNumber);
                if (xObject == null)
                {
                    xObject = new PdfFormXObject(Owner, importedObjectTable, pdfForm);
                    importedObjectTable.SetXObject(pdfForm.PageNumber, xObject);
                }
                return xObject;
            }
            Debug.Assert(form.GetType() == typeof(XForm));
            form._pdfForm = new PdfFormXObject(Owner, form);
            return form._pdfForm;
        }
Exemplo n.º 9
0
    /// <summary>
    /// Creates an XForm from a visual brush.
    /// </summary>
    public static XForm FromVisualBrush(DocumentRenderingContext context, VisualBrush brush)
    {
      //XPImage xpImage = ImageBuilder.FromImageBrush(context, brush);
      //XImage ximage = xpImage.XImage;
      double width = brush.Viewport.Width;
      double height = brush.Viewport.Height;

      // view box in point
      // XRect box = new XRect(brush.Viewbox.X * 0.75, brush.Viewbox.Y * 0.75, brush.Viewbox.Width * 0.75, brush.Viewbox.Height * 0.75);
      XRect box = new XRect(0, 0, width, height);
      XForm xform = new XForm(context.PdfDocument, box);

      PdfContentWriter formWriter = new PdfContentWriter(context, xform, RenderMode.Default);
      PdfFormXObject pdfForm = xform.PdfForm;
      pdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix());

      //formWriter.Size = brush.Viewport.Size;
      formWriter.BeginContent(false);
      formWriter.WriteElement(brush.Visual);
      formWriter.EndContent();

      return xform;
    }
Exemplo n.º 10
0
    public void RealizeFill(Brush brush, double opacity, ref XForm xform, ref XImage ximage) // PdfColorMode colorMode)
    {
      SolidColorBrush sbrush;
      LinearGradientBrush lbrush;
      RadialGradientBrush rbrush;
      ImageBrush ibrush;
      VisualBrush vbrush;
      if ((sbrush = brush as SolidColorBrush) != null)
      {
        Color color = sbrush.Color;
        //color = ColorSpaceHelper.EnsureColorMode(colorMode, color);

        this.writer.WriteRgb(color, " rg\n");

        //if (this.renderer.Owner.Version >= 14 && this.realizedStrokeColor.A != color.A)
        //if (this.realizedFillColor.ScA != color.ScA)
        {
          PdfExtGState extGState = this.writer.Owner.ExtGStateTable.GetExtGStateNonStroke(color.ScA);
          string gs = this.writer.Resources.AddExtGState(extGState);
          this.writer.WriteLiteral("{0} gs\n", gs);

          // Must create transparany group
          if (color.ScA < 1)
            this.writer.CreateDefaultTransparencyGroup();
        }
        this.realizedFillColor = color;

        //if (colorMode != PdfColorMode.Cmyk)
        //{
        //  if (this.realizedFillColor.Rgb != color.Rgb)
        //  {
        //    this.renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Rgb));
        //    this.renderer.Append(" rg\n");
        //  }
        //}
        //else
        //{
        //  if (!ColorSpaceHelper.IsEqualCmyk(this.realizedFillColor, color))
        //  {
        //    this.renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Cmyk));
        //    this.renderer.Append(" k\n");
        //  }
        //}

        //if (this.renderer.Owner.Version >= 14 && this.realizedFillColor.A != color.A)
        //{
        //  PdfExtGState extGState = this.renderer.Owner.ExtGStateTable.GetExtGStateNonStroke(color.A);
        //  string gs = this.renderer.Resources.AddExtGState(extGState);
        //  this.renderer.AppendFormat("{0} gs\n", gs);

        //  // Must create transparany group
        //  if (this.renderer.page != null && color.A < 1)
        //    this.renderer.page.transparencyUsed = true;
        //}
        //this.realizedFillColor = color;
      }
      else if ((lbrush = brush as LinearGradientBrush) != null)
      {
        // NOT IN USE ANYMORE
        //RealizeLinearGradientBrush(lbrush, xform);
      }
      else if ((rbrush = brush as RadialGradientBrush) != null)
      {
        // NOT IN USE ANYMORE
        //RealizeRadialGradientBrush(rbrush, xform);
      }
      else if ((ibrush = brush as ImageBrush) != null)
      {
        // NOT IN USE ANYMORE
        //RealizeImageBrush(ibrush, ref xform, ref ximage);
      }
      else if ((vbrush = brush as VisualBrush) != null)
      {
        // NOT IN USE ANYMORE
        //RealizeVisualBrush(vbrush, ref xform);
      }
      else
      {
        //return new SolidColorBrush(Colors//
        //Debugger.Break();
      }
    }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of FormSelector from an XPdfForm.
 /// </summary>
 public Selector(XForm form)
 {
     // HACK: just use full path to identify
     _path = form._path.ToLowerInvariant();
 }
Exemplo n.º 12
0
    //    public XGraphicsPdfPageOptions PageOptions
    //    {
    //      get { return this.options; }
    //    }

    /// <summary>
    /// Closes the underlying content stream.
    /// </summary>
    void Close()
    {
      if (this.page != null)
      {
        PdfContent content = page.RenderContent;
        content.CreateStream(PdfEncoders.RawEncoding.GetBytes(GetContent()));

        //this.gfx = null;
        this.page.RenderContent.pdfRenderer = null;
        this.page.RenderContent = null;
        this.page = null;
      }
      else if (this.form != null)
      {
        this.form.pdfForm.CreateStream(PdfEncoders.RawEncoding.GetBytes(GetContent()));
        this.form.pdfRenderer = null;
        this.form = null;
      }
      else if (this.contentDictionary != null)
      {
        this.contentDictionary.CreateStream(PdfEncoders.RawEncoding.GetBytes(GetContent()));
        this.contentDictionary = null;
      }
      else
        Debug.Assert(false, "Undefined content target.");
    }
    void RealizeRadialGradientBrush(RadialGradientBrush brush, XForm xform)
    {
      XMatrix matrix = new XMatrix(); // this.renderer.defaultViewMatrix;
      //matrix.MultiplyPrepend(this.Transform);
      matrix = this.currentTransform;
      //matrix.MultiplyPrepend(XMatrix.CreateScaling(1.3, 1));
      PdfShadingPattern pattern = new PdfShadingPattern(this.writer.Owner);
      pattern.Elements[PdfShadingPattern.Keys.PatternType] = new PdfInteger(2); // shading pattern

      // Setup shading
      PdfShading shading = new PdfShading(this.writer.Owner);

      PdfColorMode colorMode = PdfColorMode.Rgb; //this.document.Options.ColorMode;

      PdfDictionary function = BuildShadingFunction(brush.GradientStops, colorMode);

      shading.Elements[PdfShading.Keys.ShadingType] = new PdfInteger(3); // Radial shading
      //if (colorMode != PdfColorMode.Cmyk)
      shading.Elements[PdfShading.Keys.ColorSpace] = new PdfName("/DeviceRGB");
      //else
      //shading.Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");

      double x0 = brush.GradientOrigin.X;
      double y0 = brush.GradientOrigin.Y;
      double r0 = 0;
      double x1 = brush.Center.X;
      double y1 = brush.Center.Y;
      double r1 = brush.RadiusX;

      shading.Elements[PdfShading.Keys.Coords] =
        new PdfLiteral("[{0:0.###} {1:0.###} {2:0.###} {3:0.###} {4:0.###} {5:0.###}]", x0, y0, r0, x1, y1, r1);

      // old: Elements[Keys.Background] = new PdfRawItem("[0 1 1]");
      // old: Elements[Keys.Domain] = 
      shading.Elements[PdfShading.Keys.Function] = function;
      shading.Elements[PdfShading.Keys.Extend] = new PdfLiteral("[true true]");

      // Setup pattern
      pattern.Elements[PdfShadingPattern.Keys.Shading] = shading;
      pattern.Elements[PdfShadingPattern.Keys.Matrix] = PdfLiteral.FromMatrix(matrix); // new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");

      string name = this.writer.Resources.AddPattern(pattern);
      this.writer.WriteLiteral("/Pattern cs\n", name);
      this.writer.WriteLiteral("{0} scn\n", name);

      double alpha = brush.Opacity * brush.GradientStops.GetAverageAlpha();
      if (alpha < 1)
      {
#if true
        PdfExtGState extGState = this.writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha);
        string gs = this.writer.Resources.AddExtGState(extGState);
        this.writer.WriteLiteral("{0} gs\n", gs);
#else
        if (xform == null)
        {
          PdfExtGState extGState = this.writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha);
          string gs = this.writer.Resources.AddExtGState(extGState);
          this.writer.WriteGraphicState(extGState);
        }
        else
        {
          //PdfFormXObject pdfForm = this.writer.Owner.FormTable.GetForm(form);
          PdfFormXObject pdfForm = xform.pdfForm;
          pdfForm.Elements.SetString("/@", "This is the Form XObject of the soft mask");

          string formName = this.writer.Resources.AddForm(pdfForm);

          PdfTransparencyGroupAttributes tgAttributes = new PdfTransparencyGroupAttributes(this.writer.Owner);
          //this.writer.Owner.Internals.AddObject(tgAttributes);
          tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB");

          // Set reference to transparency group attributes
          pdfForm.Elements.SetObject(PdfFormXObject.Keys.Group, tgAttributes);
          pdfForm.Elements[PdfFormXObject.Keys.Matrix] = new PdfLiteral("[1.001 0 0 1.001 0.001 0.001]");


          PdfSoftMask softmask = new PdfSoftMask(this.writer.Owner);
          this.writer.Owner.Internals.AddObject(softmask);
          softmask.Elements.SetString("/@", "This is the soft mask");
          softmask.Elements.SetName(PdfSoftMask.Keys.S, "/Luminosity");
          softmask.Elements.SetReference(PdfSoftMask.Keys.G, pdfForm);
          //pdfForm.Elements.SetName(PdfFormXObject.Keys.Type, "Group");
          //pdfForm.Elements.SetName(PdfFormXObject.Keys.ss.Ss.Type, "Group");

          PdfExtGState extGState = new PdfExtGState(this.writer.Owner);
          this.writer.Owner.Internals.AddObject(extGState);
          extGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask);
          this.writer.WriteGraphicState(extGState);
        }
#endif
      }
    }
Exemplo n.º 14
0
 /// <summary>
 /// Implements the interface because the primary function is internal.
 /// </summary>
 string IContentStream.GetFormName(XForm form)
 {
     return GetFormName(form);
 }
Exemplo n.º 15
0
    /// <summary>
    /// Creates a new instance of the XGraphics class from a PdfSharp.Drawing.XForm object.
    /// </summary>
    public static XGraphics FromForm(XForm form)
    {
      if (form.gfx != null)
        return form.gfx;

      return new XGraphics(form);
    }
Exemplo n.º 16
0
        public static bool Attach_DrukWplaty(SPWeb web, SPListItem item, string nazwaPliku, string odbiorca, string numerRachunku, double kwotaDoZaplaty, string zleceniodawca, string tytulem)
        {
            //const int maxLen = 27;
            const int maxLen = 46;
            odbiorca = odbiorca.ToUpper();
            zleceniodawca = zleceniodawca.ToUpper();
            tytulem = tytulem.ToUpper();

            //unormowanie nazwy pliku
            nazwaPliku = CleanupFileName(nazwaPliku);

            if (numerRachunku.Length != 26)
            {
                return false;
            }

            if (item.Attachments.Count > 0)
            {
                foreach (string fname in item.Attachments)
                {
                    if (fname == nazwaPliku)
                    {
                        item.Attachments.DeleteNow(fname);
                        break;
                    }
                }
            }

            string pdfFilePath = @"SiteAssets/Templates/DW-Przelew.pdf";
            int x0 = 89;
            int y0 = 76;

            //string pdfFilePath = @"SiteAssets/Templates/PolecenieWplaty-Template.pdf";
            //int x0 = 95;
            //int y0 = 115;

            //string pdfFilePath = @"SiteAssets/Templates/MyTemplate.pdf";

            SPFile file = web.GetFile(pdfFilePath);

            if (file.Exists)
            {
                int bufferSize = 20480;
                byte[] byteBuffer = new byte[bufferSize];
                //byteBuffer = File.ReadAllBytes(pdfFilePath);
                byteBuffer = file.OpenBinary();

                MemoryStream coverSheetContent = new MemoryStream();

                coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length);
                int t = PdfReader.TestPdfFile(coverSheetContent);
                PdfDocument document = PdfReader.Open(coverSheetContent);
                PdfPage page = document.Pages[0];

                // Create an empty XForm object with the specified width and height
                // A form is bound to its target document when it is created. The reason is that the form can 
                // share fonts and other objects with its target document.
                XForm form = new XForm(document, XUnit.FromMillimeter(138), XUnit.FromMillimeter(77));

                // Create an XGraphics object for drawing the contents of the form.
                XGraphics formGfx = XGraphics.FromForm(form);

                // Draw a large transparent rectangle to visualize the area the form occupies
                XColor back = XColors.Orange;
                back.A = 0.2;
                XSolidBrush brush = new XSolidBrush(back);
                formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

                // On a form you can draw...

                // ... text

                XFont font = new XFont("Verdana", 10, XFontStyle.Bold); //XFont("Verdana", 10, XFontStyle.Regular)

                string odbiorca2 = string.Empty;
                if (odbiorca.Length > maxLen)
                {
                    odbiorca2 = odbiorca.Substring(maxLen, odbiorca.Length - maxLen);
                    if (odbiorca2.Length > maxLen)
                    {
                        odbiorca2 = odbiorca2.Substring(0, maxLen);
                    }
                    odbiorca = odbiorca.Substring(0, maxLen);
                }

                formGfx.DrawString(odbiorca, font, XBrushes.Navy, 8, 8, XStringFormats.TopLeft);
                formGfx.DrawString(odbiorca2, font, XBrushes.Navy, 8, 33, XStringFormats.TopLeft);
                //formGfx.DrawString("Numer rachunku odbiorcy przekazu pocztowego", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 8, 57, XStringFormats.TopLeft);

                int n = 0;
                formGfx.DrawString(numerRachunku.Substring(n, 2), font, XBrushes.Navy, 13, 57, XStringFormats.TopLeft); n = n + 2;

                int offset = 57;
                int targetX = 48;

                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 1 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 2 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 3 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 4 * offset, 57, XStringFormats.TopLeft); n = n + 4;
                formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 5 * offset, 57, XStringFormats.TopLeft);

                formGfx.DrawString("***" + String.Format("{0:#,0.00}", kwotaDoZaplaty) + "***", font, XBrushes.Navy, 220, 81, XStringFormats.TopLeft);

                int zlote = (int)kwotaDoZaplaty;
                int grosze = (int)(100 * kwotaDoZaplaty) % 100;
                string kwota = String.Format("{0} {1}",
                    KwotaSlownie.LiczbaSlownie(zlote),
                    grosze + "/100");

                formGfx.DrawString("***" + kwota + "***", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 8, 106, XStringFormats.TopLeft);

                string zleceniodawca2 = string.Empty;
                if (zleceniodawca.Length > maxLen)
                {
                    zleceniodawca2 = zleceniodawca.Substring(maxLen, zleceniodawca.Length - maxLen);
                    if (zleceniodawca2.Length > maxLen)
                    {
                        zleceniodawca2 = zleceniodawca2.Substring(0, maxLen);
                    }
                    zleceniodawca = zleceniodawca.Substring(0, maxLen);
                }
                formGfx.DrawString(zleceniodawca, font, XBrushes.Navy, 8, 130, XStringFormats.TopLeft);
                formGfx.DrawString(zleceniodawca2, font, XBrushes.Navy, 8, 154, XStringFormats.TopLeft);

                string tytulem2 = string.Empty;
                if (tytulem.Length > maxLen)
                {
                    tytulem2 = tytulem.Substring(maxLen, tytulem.Length - maxLen);
                    if (tytulem2.Length > maxLen)
                    {
                        tytulem2 = tytulem2.Substring(0, maxLen);
                    }
                    tytulem = tytulem.Substring(0, maxLen);
                }
                formGfx.DrawString(tytulem, font, XBrushes.Navy, 8, 178, XStringFormats.TopLeft);
                formGfx.DrawString(tytulem2, font, XBrushes.Navy, 8, 201, XStringFormats.TopLeft);




                XPen pen = XPens.LightBlue.Clone();
                pen.Width = 2.5;

                XGraphics gfx = XGraphics.FromPdfPage(page);

                // Draw the form on the page of the document in its original size
                gfx.DrawImage(form, x0, y0);
                gfx.DrawImage(form, x0, y0 + 300);

                MemoryStream ms = new MemoryStream();
                document.Save(ms);

                item.Attachments.AddNow(nazwaPliku, ms.GetBuffer());
                //item.SystemUpdate();

                return true;
            }

            else
            {
                return false;
            }


        }
    public override void RenderPage(XGraphics gfx)
    {
#if true_
      // Create a new PDF document
      //PdfDocument document = new PdfDocument();

      // Create a font
      XFont font = new XFont("Verdana", 16);

      // Create a new page
      //PdfPage page = document.AddPage();
      //XGraphics gfx = XGraphics.FromPdfPage(page);
      //gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormat.Default);

      // Step 1: Create an XForm and draw some graphics on it

      // Create an empty XForm object with the specified width and height
      // A form is bound to its target document when it is created. The reason is that the form can 
      // share fonts and other objects with its target document.
      XForm form = new XForm(gfx, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55));

      // Create an XGraphics object for drawing the contents of the form.
      XGraphics formGfx = XGraphics.FromForm(form);

      // Draw a large transparent rectangle to visualize the area the form occupies
      XColor back = XColors.Orange;
      back.A = 0.2;
      XSolidBrush brush = new XSolidBrush(back);
      formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);


      // On a form you can draw...

      //// ... text
      //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.TopLeft);
      //XPen pen = XPens.LightBlue.Clone();
      //pen.Width = 2.5;

      // ... graphics like Bézier curves
      //formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20, 100,140 175,33.3"));

      //// ... raster images like GIF files
      //XGraphicsState state = formGfx.Save();
      //formGfx.RotateAtTransform(17, new XPoint(30, 30));
      //formGfx.DrawImage(XImage.FromFile("../../../../XGraphicsLab/images/Test.gif"), 20, 20);
      //formGfx.Restore(state);

      //// ... and forms like XPdfForm objects
      //state = formGfx.Save();
      //formGfx.RotateAtTransform(-8, new XPoint(165, 115));
      //formGfx.DrawImage(XPdfForm.FromFile("../../../../PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * Math.Sqrt(2)));
      //formGfx.Restore(state);

      // When you finished drawing on the form, dispose the XGraphic object.
      formGfx.Dispose();


      // Step 2: Draw the XPdfForm on your PDF page like an image

      // Draw the form on the page of the document in its original size
      gfx.DrawImage(form, 20, 50);

#if true_
      // Draw it stretched
      gfx.DrawImage(form, 300, 100, 250, 40);

      // Draw and rotate it
      int d = 25;
      for (int idx = 0; idx < 360; idx += d)
      {
        gfx.DrawImage(form, 300, 480, 200, 200);
        gfx.RotateAtTransform(d, new XPoint(300, 480));
      }
#endif

      //// Save the document...
      //string filename = "XForms.pdf";
      //document.Save(filename);
      //// ...and start a viewer.
      //Process.Start(filename);
#else
      //base.RenderPage(gfx);

      int cx = 300;
      int cy = 240;
      XForm form;
      //if (gfx.PdfPage == null)
        form = new XForm(gfx, cx, cy);
      //else
      //  form = new XForm(gfx.PdfPage.Owner, cx, cy);

      double dx = gfx.PageSize.Width;
      double dy = gfx.PageSize.Height;

      XGraphics formgfx = XGraphics.FromForm(form);
      XSolidBrush brush = new XSolidBrush(XColor.FromArgb(128, 0, 255, 255));
      formgfx.DrawRectangle(brush, -1000, -1000, 2000, 2000);
      formgfx.DrawLine(XPens.Red, 0, 0, cx, cy);
      formgfx.DrawLine(XPens.Red, cx, 0, 0, cy);

      XFont font = new XFont("Times", 16, XFontStyle.BoldItalic);
      formgfx.DrawString("Text", font, XBrushes.DarkOrange, 0, 0, XStringFormats.TopLeft);
      formgfx.DrawString("Text", font, XBrushes.DarkOrange, new XRect(0, 0, cx, cy), XStringFormats.Center);

      // Required to finish drawing the form. Both cases are correct.
#if true
      formgfx.Dispose();
#else
      form.DrawingFinished();
#endif
      gfx.DrawImage(form, 50, 50);

#if true_
      gfx.TranslateTransform(dx / 2, dy / 2);
      gfx.RotateTransform(-25);
      gfx.TranslateTransform(-dx / 2, -dy / 2);

      gfx.DrawImage(form, (dx - form.Width) / 2, (dy - form.Height) / 2, form.Width, form.Height);
#endif
#endif
    }
Exemplo n.º 18
0
        /// <summary>
        /// Creates the normal appearance form X object for the annotation that represents
        /// this acro form text field.
        /// </summary>
        void RenderAppearance()
        {
#if true_
            PdfFormXObject xobj = new PdfFormXObject(Owner);
            Owner.Internals.AddObject(xobj);
            xobj.Elements["/BBox"] = new PdfLiteral("[0 0 122.653 12.707]");
            xobj.Elements["/FormType"] = new PdfLiteral("1");
            xobj.Elements["/Matrix"] = new PdfLiteral("[1 0 0 1 0 0]");
            PdfDictionary res = new PdfDictionary(Owner);
            xobj.Elements["/Resources"] = res;
            res.Elements["/Font"] = new PdfLiteral("<< /Helv 28 0 R >> /ProcSet [/PDF /Text]");
            xobj.Elements["/Subtype"] = new PdfLiteral("/Form");
            xobj.Elements["/Type"] = new PdfLiteral("/XObject");

            string s =
              "/Tx BMC " + '\n' +
              "q" + '\n' +
              "1 1 120.653 10.707 re" + '\n' +
              "W" + '\n' +
              "n" + '\n' +
              "BT" + '\n' +
              "/Helv 7.93 Tf" + '\n' +
              "0 g" + '\n' +
              "2 3.412 Td" + '\n' +
              "(Hello ) Tj" + '\n' +
              "20.256 0 Td" + '\n' +
              "(XXX) Tj" + '\n' +
              "ET" + '\n' +
              "Q" + '\n' +
              "";//"EMC";
            int length = s.Length;
            byte[] stream = new byte[length];
            for (int idx = 0; idx < length; idx++)
                stream[idx] = (byte)s[idx];
            xobj.CreateStream(stream);

            // Get existing or create new appearance dictionary
            PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
            if (ap == null)
            {
                ap = new PdfDictionary(_document);
                Elements[PdfAnnotation.Keys.AP] = ap;
            }

            // Set XRef to normal state
            ap.Elements["/N"] = xobj.Reference;




            //// HACK
            //string m =
            //"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>" + '\n' +
            //"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c321 44.398116, Tue Aug 04 2009 14:24:39\"> " + '\n' +
            //"   <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"> " + '\n' +
            //"         <pdf:Producer>PDFsharp 1.40.2150-g (www.pdfsharp.com) (Original: Powered By Crystal)</pdf:Producer> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:xap=\"http://ns.adobe.com/xap/1.0/\"> " + '\n' +
            //"         <xap:ModifyDate>2011-07-11T23:15:09+02:00</xap:ModifyDate> " + '\n' +
            //"         <xap:CreateDate>2011-05-19T16:26:51+03:00</xap:CreateDate> " + '\n' +
            //"         <xap:MetadataDate>2011-07-11T23:15:09+02:00</xap:MetadataDate> " + '\n' +
            //"         <xap:CreatorTool>Crystal Reports</xap:CreatorTool> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> " + '\n' +
            //"         <dc:format>application/pdf</dc:format> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\"> " + '\n' +
            //"         <xapMM:DocumentID>uuid:68249d89-baed-4384-9a2d-fbf8ace75c45</xapMM:DocumentID> " + '\n' +
            //"         <xapMM:InstanceID>uuid:3d5f2f46-c140-416f-baf2-7f9c970cef1d</xapMM:InstanceID> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"   </rdf:RDF> " + '\n' +
            //"</x:xmpmeta> " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"<?xpacket end=\"w\"?>";

            //PdfDictionary mdict = (PdfDictionary)_document.Internals.GetObject(new PdfObjectID(32));

            //length = m.Length;
            //stream = new byte[length];
            //for (int idx = 0; idx < length; idx++)
            //  stream[idx] = (byte)m[idx];

            //mdict.Stream.Value = stream;




#else
            PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect);
            XForm form = new XForm(_document, rect.Size);
            XGraphics gfx = XGraphics.FromForm(form);

            if (_backColor != XColor.Empty)
                gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location);

            string text = Text;
            if (text.Length > 0)
                gfx.DrawString(Text, Font, new XSolidBrush(ForeColor),
                  rect.ToXRect() - rect.Location + new XPoint(2, 0), XStringFormats.TopLeft);

            form.DrawingFinished();
            form.PdfForm.Elements.Add("/FormType", new PdfLiteral("1"));

            // Get existing or create new appearance dictionary.
            PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
            if (ap == null)
            {
                ap = new PdfDictionary(_document);
                Elements[PdfAnnotation.Keys.AP] = ap;
            }

            // Set XRef to normal state
            ap.Elements["/N"] = form.PdfForm.Reference;

            PdfFormXObject xobj = form.PdfForm;
            string s = xobj.Stream.ToString();
            // Thank you Adobe: Without putting the content in 'EMC brackets'
            // the text is not rendered by PDF Reader 9 or higher.
            s = "/Tx BMC\n" + s + "\nEMC";
            xobj.Stream.Value = new RawEncoding().GetBytes(s);
#endif
        }
    void RealizeLinearGradientBrush(LinearGradientBrush brush, XForm xform)
    {
      XMatrix matrix = this.currentTransform;
      PdfShadingPattern pattern = new PdfShadingPattern(this.writer.Owner);
      pattern.Elements[PdfShadingPattern.Keys.PatternType] = new PdfInteger(2); // shading pattern

      // Setup shading
      PdfShading shading = new PdfShading(this.writer.Owner);
      PdfColorMode colorMode = PdfColorMode.Rgb; //this.document.Options.ColorMode;

      PdfDictionary function = BuildShadingFunction(brush.GradientStops, colorMode);
      function.Elements.SetString("/@", "This is the shading function of a LinearGradientBrush");
      shading.Elements[PdfShading.Keys.Function] = function;

      shading.Elements[PdfShading.Keys.ShadingType] = new PdfInteger(2); // Axial shading
      //if (colorMode != PdfColorMode.Cmyk)
      shading.Elements[PdfShading.Keys.ColorSpace] = new PdfName("/DeviceRGB");
      //else
      //shading.Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");

      //double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
      double x1 = brush.StartPoint.X;
      double y1 = brush.StartPoint.Y;
      double x2 = brush.EndPoint.X;
      double y2 = brush.EndPoint.Y;

      shading.Elements[PdfShading.Keys.Coords] = new PdfLiteral("[{0:0.###} {1:0.###} {2:0.###} {3:0.###}]", x1, y1, x2, y2);

      // old: Elements[Keys.Background] = new PdfRawItem("[0 1 1]");
      // old: Elements[Keys.Domain] = 
      shading.Elements[PdfShading.Keys.Extend] = new PdfLiteral("[true true]");

      // Setup pattern
      pattern.Elements[PdfShadingPattern.Keys.Shading] = shading;
      pattern.Elements[PdfShadingPattern.Keys.Matrix] = PdfLiteral.FromMatrix(matrix); // new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");

      string name = this.writer.Resources.AddPattern(pattern);
      this.writer.WriteLiteral("/Pattern cs\n", name);
      this.writer.WriteLiteral("{0} scn\n", name);

      double alpha = brush.Opacity * brush.GradientStops.GetAverageAlpha();
      if (alpha < 1 && this.writer.renderMode == RenderMode.Default)
      {
#if true
        PdfExtGState extGState = this.writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha);
        string gs = this.writer.Resources.AddExtGState(extGState);
        this.writer.WriteLiteral("{0} gs\n", gs);
#else
#if true
        if (xform == null)
        {
          PdfExtGState extGState = this.writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha);
          string gs = this.writer.Resources.AddExtGState(extGState);
          this.writer.WriteGraphicState(extGState);
        }
        else
        {
          //PdfFormXObject pdfForm = this.writer.Owner.FormTable.GetForm(form);
          PdfFormXObject pdfForm = xform.pdfForm;
          pdfForm.Elements.SetString("/@", "This is the Form XObject of the soft mask");

          string formName = this.writer.Resources.AddForm(pdfForm);

          PdfTransparencyGroupAttributes tgAttributes = new PdfTransparencyGroupAttributes(this.writer.Owner);
          //this.writer.Owner.Internals.AddObject(tgAttributes);
          tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB");

          // Set reference to transparency group attributes
          pdfForm.Elements.SetObject(PdfFormXObject.Keys.Group, tgAttributes);
          pdfForm.Elements[PdfFormXObject.Keys.Matrix] = new PdfLiteral("[1.001 0 0 1.001 0.001 0.001]");


          PdfSoftMask softmask = new PdfSoftMask(this.writer.Owner);
          this.writer.Owner.Internals.AddObject(softmask);
          softmask.Elements.SetString("/@", "This is the soft mask");
          softmask.Elements.SetName(PdfSoftMask.Keys.S, "/Luminosity");
          softmask.Elements.SetReference(PdfSoftMask.Keys.G, pdfForm);
          //pdfForm.Elements.SetName(PdfFormXObject.Keys.Type, "Group");
          //pdfForm.Elements.SetName(PdfFormXObject.Keys.ss.Ss.Type, "Group");

          PdfExtGState extGState = new PdfExtGState(this.writer.Owner);
          this.writer.Owner.Internals.AddObject(extGState);
          extGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask);
          this.writer.WriteGraphicState(extGState);
        }

#else
        XForm form = new XForm(this.writer.Owner, 220, 140);
        XGraphics formGfx = XGraphics.FromForm(form);

        // draw something
        //XSolidBrush xbrush = new XSolidBrush(XColor.FromArgb(128, 128, 128));
        XLinearGradientBrush xbrush = new XLinearGradientBrush(new XPoint(0, 0), new XPoint(220,0), XColors.White, XColors.Black);
        formGfx.DrawRectangle(xbrush, -10000, -10000, 20000, 20000);
        //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.TopLeft);
        formGfx.Dispose();

        // Close form
        form.Finish();
        PdfFormXObject pdfForm = this.writer.Owner.FormTable.GetForm(form);
        string formName = this.writer.Resources.AddForm(pdfForm);

        //double x = 20, y = 20;
        //double cx = 1;
        //double cy = 1;

        //this.writer.AppendFormat("q {2:0.###} 0 0 -{3:0.###} {0:0.###} {4:0.###} cm 100 Tz {5} Do Q\n",
        //  x, y, cx, cy, y + 0, formName);

        //this.writer.AppendFormat("q {2:0.###} 0 0 -{3:0.###} {0:0.###} {4:0.###} cm 100 Tz {5} Do Q\n",
        //  x, y, cx, cy, y + 220/1.5, formName);

        PdfTransparencyGroupAttributes tgAttributes = new PdfTransparencyGroupAttributes(this.writer.Owner);
        this.writer.Owner.Internals.AddObject(tgAttributes);

        tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB");


        // Set reference to transparency group attributes
        pdfForm.Elements.SetReference(PdfFormXObject.Keys.Group, tgAttributes);


        PdfSoftMask softmask = new PdfSoftMask(this.writer.Owner);
        this.writer.Owner.Internals.AddObject(softmask);
        softmask.Elements.SetName(PdfSoftMask.Keys.S, "/Luminosity");
        softmask.Elements.SetReference(PdfSoftMask.Keys.G, pdfForm);
        //pdfForm.Elements.SetName(PdfFormXObject.Keys.Type, "Group");
        //pdfForm.Elements.SetName(PdfFormXObject.Keys.ss.Ss.Type, "Group");

        PdfExtGState extGState = new PdfExtGState(this.writer.Owner);
        this.writer.Owner.Internals.AddObject(extGState);
        extGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask);
        this.writer.WriteGraphicState(extGState);
#endif
#endif
      }
    }
Exemplo n.º 20
0
 /// <summary>
 /// Gets the resource name of the specified form within this form.
 /// </summary>
 internal string GetFormName(XForm form)
 {
   Debug.Assert(IsTemplate, "This function is for form templates only.");
   PdfFormXObject pdfForm = this.document.FormTable.GetForm(form);
   Debug.Assert(pdfForm != null);
   string name = Resources.AddForm(pdfForm);
   return name;
 }
Exemplo n.º 21
0
        public static bool Attach_DrukWplatyZUS(SPWeb web, SPListItem item, string nazwaPliku, string numerRachunku, double kwotaDoZaplaty, string nadawca, string nip, string typIdentyfikatora, string drugiIdentyfikator, string identyfikatorDeklaracji)
        {
            const int maxLen = 27;

            nazwaPliku = CleanupFileName(nazwaPliku);

            if (numerRachunku.Length != 26)
            {
                return false;
            }
            else
            {
                numerRachunku = String.Format(@"{0}                  {1}", numerRachunku.Substring(0, 2), numerRachunku.Substring(20, 1));
            }

            if (item.Attachments.Count > 0)
            {
                foreach (string fname in item.Attachments)
                {
                    if (fname == nazwaPliku)
                    {
                        item.Attachments.DeleteNow(fname);
                        break;
                    }
                }
            }

            string pdfFilePath = @"SiteAssets/Templates/DW-ZUS.pdf";
            int x0 = 92;
            int dx = 135;
            int y0 = 76;
            int dy = 78;
            int formoffset = 304;

            double ofset0 = 14.15; //odstępo pomiędzy znakami
            double ofset1 = 24.1; //odstęp pomiędzy liniami

            int c01 = 3;
            int r01 = 58;
            int r02 = r01 + (int)(ofset1 * 1);
            int r03 = r01 + (int)(ofset1 * 2);
            int c02 = 215;
            int r04 = r01 + (int)(ofset1 * 3);
            int r05 = r01 + (int)(ofset1 * 4);
            int r06 = r01 + (int)(ofset1 * 5);
            int r07 = r01 + (int)(ofset1 * 6);



            SPFile file = web.GetFile(pdfFilePath);

            if (file.Exists)
            {
                int bufferSize = 20480;
                byte[] byteBuffer = new byte[bufferSize];
                byteBuffer = file.OpenBinary();

                MemoryStream coverSheetContent = new MemoryStream();

                coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length);
                int t = PdfReader.TestPdfFile(coverSheetContent);
                PdfDocument document = PdfReader.Open(coverSheetContent);
                PdfPage page = document.Pages[0];

                XForm form = new XForm(document, XUnit.FromMillimeter(dx), XUnit.FromMillimeter(dy));
                XGraphics formGfx = XGraphics.FromForm(form);
#if DEBUG
                XColor back = XColors.Orange;
#else
                XColor back = XColors.White;
#endif
                back.A = 0.2;
                XSolidBrush brush = new XSolidBrush(back);
                formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

                XFont font = new XFont("Verdana", 10, XFontStyle.Bold);

                PlotText(numerRachunku, c01, r01, ofset0, formGfx, font);

                PlotText((string)(String.Format("{0:#0.00}", kwotaDoZaplaty) + "************").Substring(0, 12), c02, r02, ofset0, formGfx, font);

                int zlote = (int)kwotaDoZaplaty;
                int grosze = (int)(100 * kwotaDoZaplaty) % 100;
                string kwota = String.Format("{0} {1}",
                    KwotaSlownie.LiczbaSlownie(zlote),
                    grosze + "/100");

                formGfx.DrawString("*" + kwota + "*", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, c01, r03, XStringFormats.TopLeft);

                string nadawca2 = string.Empty;
                if (nadawca.Length > maxLen)
                {
                    nadawca2 = nadawca.Substring(maxLen, nadawca.Length - maxLen);
                    if (nadawca2.Length > maxLen)
                    {
                        nadawca2 = nadawca2.Substring(0, maxLen);
                    }
                    nadawca = nadawca.Substring(0, maxLen);
                }
                PlotText(nadawca, c01, r04, ofset0, formGfx, font);
                PlotText(nadawca2, c01, r05, ofset0, formGfx, font);

                PlotText(nip, c01, r06, ofset0, formGfx, font);
                PlotText(typIdentyfikatora, c01 + (int)(11 * ofset0), r06, ofset0, formGfx, font);
                PlotText(drugiIdentyfikator, c01 + (int)(13 * ofset0), r06, ofset0, formGfx, font);

                PlotText(identyfikatorDeklaracji, c01, r07, ofset0, formGfx, font);


                XPen pen = XPens.LightBlue.Clone();
                pen.Width = 2.5;

                XGraphics gfx = XGraphics.FromPdfPage(page);

                // Draw the form on the page of the document in its original size
                gfx.DrawImage(form, x0, y0);
                gfx.DrawImage(form, x0, y0 + formoffset);

                MemoryStream ms = new MemoryStream();
                document.Save(ms);

                item.Attachments.AddNow(nazwaPliku, ms.GetBuffer());
                //item.SystemUpdate();

                return true;
            }

            else
            {
                return false;
            }

        }
Exemplo n.º 22
0
    /// <summary>
    /// Initializes a new instance of the XGraphics class used for drawing on a form.
    /// </summary>
    XGraphics(XForm form)
    {
      if (form == null)
        throw new ArgumentNullException("form");

      this.form = form;
      form.AssociateGraphics(this);

      this.gsStack = new GraphicsStateStack(this);
#if GDI && !WPF
      this.targetContext = XGraphicTargetContext.GDI;
      // If form.Owner is null create a meta file.
      if (form.Owner == null)
      {
        MemoryStream stream = new MemoryStream();
        Graphics refgfx = Graphics.FromHwnd(IntPtr.Zero);
        IntPtr hdc = refgfx.GetHdc();

#if true_
        // This code comes from my C++ RenderContext and checks some confusing details in connection 
        // with metafiles.
        //                                                                                    Display                 | LaserJet
        //                                                                               DPI   96 : 120               | 300
        // physical device size in MM                                                    ---------------------------------------------
        int horzSizeMM    = NativeMethods.GetDeviceCaps(hdc, NativeMethods.HORZSIZE);    // = 360 : 360               | 198 (not 210)
        int vertSizeMM    = NativeMethods.GetDeviceCaps(hdc, NativeMethods.VERTSIZE);    // = 290 : 290               | 288 (hot 297)
        // Cool:
        // My monitor is a Sony SDM-N80 and it's size is EXACTLY 360mm x 290mm!!
        // It is an 18.1" Flat Panel LCD display from 2002 and these are the values
        // an older display drivers reports in about 2003:
        //        Display  
        //  DPI   96 : 120
        //  --------------
        //       330 : 254
        //       254 : 203
        // Obviously my ATI driver reports the exact size of the monitor.


        // device size in pixel
        int horzSizePixel = NativeMethods.GetDeviceCaps(hdc, NativeMethods.HORZRES);     // = 1280 : 1280             | 4676
        int vertSizePixel = NativeMethods.GetDeviceCaps(hdc, NativeMethods.VERTRES);     // = 1024 : 1024             | 6814

        // 'logical' device resolution in DPI
        int logResX       = NativeMethods.GetDeviceCaps(hdc, NativeMethods.LOGPIXELSX);  // = 96 : 120                | 600
        int logResY       = NativeMethods.GetDeviceCaps(hdc, NativeMethods.LOGPIXELSY);  // = 96 : 120                | 600

        // now we can get the 'physical' device resolution...
        float phyResX = horzSizePixel / (horzSizeMM / 25.4f);  // = 98.521210 : 128.00000   | 599.85052
        float phyResY = vertSizePixel / (vertSizeMM / 25.4f);  // = 102.40000 : 128.12611   | 600.95691

        // ...and rescale the size of the meta rectangle.
        float magicX = logResX / phyResX;                      // = 0.97440946 : 0.93750000 | 1.0002491
        float magicY = logResY / phyResY;                      // = 0.93750000 : 0.93657720 | 0.99840766

        // use A4 page in point
        // adjust size of A4 page so that meta file fits with DrawImage...
        //RectangleF rcMagic = new RectangleF(0, 0, magicX * form.Width, magicY * form.Height);
        //m_PreviewMetafile = new Metafile(hdc, rcMagic, MetafileFrameUnitPoint,
        //  EmfTypeEmfPlusOnly, L"some description");
#endif

        RectangleF rect = new RectangleF(0, 0, form.PixelWidth, form.PixelHeight);
        this.metafile = new Metafile(stream, hdc, rect, MetafileFrameUnit.Pixel); //, EmfType.EmfPlusOnly);

        // Petzold disposes the refgfx object, although the hdc is in use of the metafile
        refgfx.ReleaseHdc(hdc);
        refgfx.Dispose();

        this.gfx = Graphics.FromImage(this.metafile);
        this.gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        this.drawGraphics = true;
      }
      else
      {
        this.metafile = null;
        this.gfx = Graphics.FromHwnd(IntPtr.Zero);
      }
      if (form.Owner != null)
        this.renderer = new PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer(form, this);
      this.pageSize = form.Size;
      Initialize();
#endif
#if WPF && !GDI
      this.targetContext = XGraphicTargetContext.WPF;
#if !SILVERLIGHT
      // If form.Owner is null create a meta file.
      if (form.Owner == null)
      {
        this.dv = new DrawingVisual();
        this.dc = this.dv.RenderOpen();
        this.drawGraphics = true;
      }
      else
      {
        this.dv = new DrawingVisual();
        this.dc = this.dv.RenderOpen();
      }
      if (form.Owner != null)
        this.renderer = new PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer(form, this);
      this.pageSize = form.Size;
      Initialize();
#else
      throw new NotImplementedException(); // AGHACK
      //Initialize();
#endif
#endif
    }
 /// <summary>
 /// Initializes a new instance of FormSelector from an XPdfForm.
 /// </summary>
 public Selector(XForm form)
 {
   // HACK: just use full path to identify
   this.path = form.path.ToLower(CultureInfo.InvariantCulture);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Gets the resource name of the specified form within this page.
 /// </summary>
 internal string GetFormName(XForm form)
 {
     PdfFormXObject pdfForm = _document.FormTable.GetForm(form);
     Debug.Assert(pdfForm != null);
     string name = Resources.AddForm(pdfForm);
     return name;
 }
Exemplo n.º 25
0
        // draws a single Paper Wallet in to a PdfSharp XForm
        private PdfSharp.Drawing.XForm getSingleWallet(PdfDocument doc, WalletBundle b, XImage imgArtwork, string address, string privkey, int numberWithinBatch, bool layoutDebugging)
        {
            WalletTemplate t = b.template;

            double width  = t.widthMM;
            double height = t.heightMM;

            XUnit walletSizeWide = XUnit.FromMillimeter(width);
            XUnit walletSizeHigh = XUnit.FromMillimeter(height);

            PdfSharp.Drawing.XForm form = new PdfSharp.Drawing.XForm(doc, walletSizeWide, walletSizeHigh);


            using (XGraphics formGfx = XGraphics.FromForm(form))
            {
                XGraphicsState state = formGfx.Save();

                bool interpolateArtwork = true;
                bool interpolateQRcodes = false;

                // XImage imgArtwork is now provided by caller, so this process only has to be done ONCE - because the artwork does not change between Wallets in a run!
                //XImage imgArtwork = XImage.FromGdiPlusImage(b.getArtworkImage());
                imgArtwork.Interpolate = interpolateArtwork;

                formGfx.DrawImage(imgArtwork, new RectangleF(0f, 0f, (float)walletSizeWide.Point, (float)walletSizeHigh.Point));

                // draw the QR codes and legible-text things

                // Address
                // QR
                Bitmap bmpAddress = BtcAddress.QR.EncodeQRCode(address);
                XImage imgAddress = XImage.FromGdiPlusImage(bmpAddress);
                imgAddress.Interpolate = interpolateQRcodes;

                XUnit addressQrLeft = XUnit.FromMillimeter(t.addressQrLeftMM);
                XUnit addressQrTop  = XUnit.FromMillimeter(t.addressQrTopMM);
                XUnit addressQrSize = XUnit.FromMillimeter(t.addressQrSizeMM);

                // only print Address QR if called for
                if (t.addressQrSizeMM > 0.1)
                {
                    XRect addressQrRect = new XRect(addressQrLeft.Point, addressQrTop.Point, addressQrSize.Point, addressQrSize.Point);
                    formGfx.DrawImage(imgAddress, addressQrRect);
                }

                // text address
                string         addressSplitForLines = addressOrReferencePrep(address, t.addressTextCharsPerLine, t.addressTextContentVariant, numberWithinBatch);
                XFont          fontAddress          = new XFont(t.addressTextFontName, t.addressTextFontSize, t.addressTextFontStyle);
                XTextFormatter tf = new XTextFormatter(formGfx);

                XUnit addressTxtLeft   = XUnit.FromMillimeter(t.addressTextLeftMM);
                XUnit addressTxtTop    = XUnit.FromMillimeter(t.addressTextTopMM);
                XUnit addressTxtWidth  = XUnit.FromMillimeter(t.addressTextWidthMM);
                XUnit addressTxtHeight = XUnit.FromMillimeter(t.addressTextHeightMM);

                XRect addressRect = new XRect(addressTxtLeft.Point, addressTxtTop.Point, addressTxtWidth.Point, addressTxtHeight.Point);
                tf.Alignment = XParagraphAlignment.Center;

                TextRotation addressTxtRotation        = t.addressTextRotation;
                double       addressTxtRotationDegrees = RotationMarkerToDegrees(addressTxtRotation);

                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XBrushes.PowderBlue, addressRect);
                }

                XPoint rotateCentre      = new XPoint(addressTxtLeft + (addressTxtWidth / 2), addressTxtTop + (addressTxtHeight / 2));
                XPoint matrixRotatePoint = new XPoint(addressRect.X + (addressRect.Width / 2), addressRect.Y + (addressRect.Height / 2));

                XMatrix rotateMatrix = new XMatrix();
                rotateMatrix.RotateAtAppend(addressTxtRotationDegrees, rotateCentre);
                addressRect.Transform(rotateMatrix);

                if (layoutDebugging)
                {
                    // draw a little tracer dot for where the centre of rotation is going to be
                    double rotateDotSize = 2.0;
                    formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize);
                }

                // maybe even do some rotation of the lovely text!
                formGfx.Save();

                formGfx.RotateAtTransform(addressTxtRotationDegrees, rotateCentre);
                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XPens.OrangeRed, addressRect);
                }

                if (t.addressTextWidthMM > 0.1)
                {
                    tf.DrawString(addressSplitForLines, fontAddress, t.GetBrushAddress, addressRect);
                }
                formGfx.Restore();

                // Privkey
                // QR
                Bitmap bmpPrivkey = BtcAddress.QR.EncodeQRCode(privkey);
                XImage imgPrivkey = XImage.FromGdiPlusImage(bmpPrivkey);
                imgPrivkey.Interpolate = interpolateQRcodes;

                XUnit privkeyQrLeft = XUnit.FromMillimeter(t.privkeyQrLeftMM);
                XUnit privkeyQrTop  = XUnit.FromMillimeter(t.privkeyQrTopMM);
                XUnit privkeyQrSize = XUnit.FromMillimeter(t.privkeyQrSizeMM);

                XRect privkeyQrRect = new XRect(privkeyQrLeft.Point, privkeyQrTop.Point, privkeyQrSize.Point, privkeyQrSize.Point);

                // only print privkey QR if specified - but you'd have to be an UTTER IDIOT to want to exclude this. Still, user input comes first!
                if (t.privkeyQrSizeMM > 0.1)
                {
                    formGfx.DrawImage(imgPrivkey, privkeyQrRect);
                }

                // legible
                string privkeySplitForLines = lineSplitter(privkey, t.privkeyTextCharsPerLine);

                XFont fontPrivkey = new XFont(t.privkeyTextFontName, t.privkeyTextFontSize, t.privkeyTextFontStyle);

                XUnit privkeyTxtLeft   = XUnit.FromMillimeter(t.privkeyTextLeftMM);
                XUnit privkeyTxtTop    = XUnit.FromMillimeter(t.privkeyTextTopMM);
                XUnit privkeyTxtWidth  = XUnit.FromMillimeter(t.privkeyTextWidthMM);
                XUnit privkeyTxtHeight = XUnit.FromMillimeter(t.privkeyTextHeightMM);

                TextRotation privkeyTxtRotation        = t.privkeyTextRotation;
                double       privkeyTxtRotationDegrees = RotationMarkerToDegrees(privkeyTxtRotation);

                XRect privkeyRect = new XRect(privkeyTxtLeft.Point, privkeyTxtTop.Point, privkeyTxtWidth.Point, privkeyTxtHeight.Point);

                if (layoutDebugging)
                {
                    // draw a tracer rectangle for the original un-rotated text rectangle
                    formGfx.DrawRectangle(XBrushes.PowderBlue, privkeyRect);
                }

                // rotate that lovely text around its middle when drawing!
                rotateCentre = new XPoint(privkeyTxtLeft + (privkeyTxtWidth / 2), privkeyTxtTop + (privkeyTxtHeight / 2));

                matrixRotatePoint = new XPoint(privkeyRect.X + (privkeyRect.Width / 2), privkeyRect.Y + (privkeyRect.Height / 2));

                rotateMatrix = new XMatrix();
                rotateMatrix.RotateAtAppend(privkeyTxtRotationDegrees, rotateCentre);
                privkeyRect.Transform(rotateMatrix);

                if (layoutDebugging)
                {
                    // draw a little tracer dot for where the centre of rotation is going to be
                    double rotateDotSize = 2.0;
                    formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize);
                }

                formGfx.Save();

                formGfx.RotateAtTransform(privkeyTxtRotationDegrees, rotateCentre);

                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XPens.OrangeRed, privkeyRect);
                }

                // only print privkey text if specified.
                if (t.privkeyTextWidthMM > 0.1)
                {
                    tf.DrawString(privkeySplitForLines, fontPrivkey, t.GetBrushPrivkey, privkeyRect);
                }

                formGfx.Restore();
            }



            return(form);
        }
Exemplo n.º 26
0
    /// <summary>
    /// Creates the normal appearance form X object for the annotation that represents
    /// this acro form text field.
    /// </summary>
    void RenderAppearance()
    {
      PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect);
      XForm form = new XForm(this.document, rect.Size);
      XGraphics gfx = XGraphics.FromForm(form);

      if (backColor != XColor.Empty)
        gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location);

      string text = Text;
      if (text.Length > 0)
        gfx.DrawString(Text, Font, new XSolidBrush(ForeColor),
          rect.ToXRect() - rect.Location + new XPoint(2, 0), XStringFormats.TopLeft);

      form.DrawingFinished();

      // Get existing or create new appearance dictionary
      PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
      if (ap == null)
      {
        ap = new PdfDictionary(this.document);
        Elements[PdfAnnotation.Keys.AP] = ap;
      }

      // Set XRef to normal state
      ap.Elements["/N"] = form.PdfForm.Reference;
    }
Exemplo n.º 27
0
    static void Main(string[] args)
    {
      // Create a new PDF document
      PdfDocument document = new PdfDocument();

      // Create a font
      XFont font = new XFont("Verdana", 16);

      // Create a new page
      PdfPage page = document.AddPage();
      XGraphics gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards);
      //gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormat.Default);

      // Step 1: Create an XForm and draw some graphics on it

      // Create an empty XForm object with the specified width and height
      // A form is bound to its target document when it is created. The reason is that the form can 
      // share fonts and other objects with its target document.
      XForm form = new XForm(document, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55));

      // Create an XGraphics object for drawing the contents of the form.
      XGraphics formGfx = XGraphics.FromForm(form);

      // Draw a large transparent rectangle to visualize the area the form occupies
      XColor back = XColors.Orange;
      back.A = 0.2;
      XSolidBrush brush = new XSolidBrush(back);
      formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);


      // On a form you can draw...

      // ... text
      formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormats.TopLeft);
      XPen pen = XPens.LightBlue.Clone();
      pen.Width = 2.5;

      // ... graphics like Bézier curves
      formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20 100,140 175,33.3"));

      // ... raster images like GIF files
      XGraphicsState state = formGfx.Save();
      formGfx.RotateAtTransform(17, new XPoint(30, 30));
      formGfx.DrawImage(XImage.FromFile("../../../../../../dev/XGraphicsLab/images/Test.gif"), 20, 20);
      formGfx.Restore(state);

      // ... and forms like XPdfForm objects
      state = formGfx.Save();
      formGfx.RotateAtTransform(-8, new XPoint(165, 115));
      formGfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * Math.Sqrt(2)));
      formGfx.Restore(state);

      // When you finished drawing on the form, dispose the XGraphic object.
      formGfx.Dispose();


      // Step 2: Draw the XPdfForm on your PDF page like an image

      // Draw the form on the page of the document in its original size
      gfx.DrawImage(form, 20, 50);

#if true
      // Draw it stretched
      gfx.DrawImage(form, 300, 100, 250, 40);

      // Draw and rotate it
      int d = 25;
      for (int idx = 0; idx < 360; idx += d)
      {
        gfx.DrawImage(form, 300, 480, 200, 200);
        gfx.RotateAtTransform(d, new XPoint(300, 480));
      }
#endif

      // Save the document...
      string filename = "XForms.pdf";
      document.Save(filename);
      // ...and start a viewer.
      Process.Start(filename);
    }
Exemplo n.º 28
0
        public static bool Attach_DrukWplatyPD(SPWeb web, SPListItem item, string nazwaPliku, string odbiorca, string numerRachunku, double kwotaDoZaplaty, string zleceniodawca, string nip, string typIdentyfikatora, string okres, string symbolFormularza, string identyfikacjaZobowiazania)
        {
            const int maxLen = 27;
            odbiorca = odbiorca.ToUpper();
            zleceniodawca = zleceniodawca.ToUpper();

            //unormowanie nazwy pliku
            nazwaPliku = CleanupFileName(nazwaPliku);

            if (numerRachunku.Length != 26)
            {
                return false;
            }

            if (item.Attachments.Count > 0)
            {
                foreach (string fname in item.Attachments)
                {
                    if (fname == nazwaPliku)
                    {
                        item.Attachments.DeleteNow(fname);
                        break;
                    }
                }
            }

            string pdfFilePath = @"SiteAssets/Templates/DW-Podatek.pdf";
            int x0 = 90;
            int dx = 136;
            int y0 = 74;
            int dy = 76;
            double ofset0 = 14.3;
            int c01 = 3;
            int r01 = 7;
            int r02 = 31;
            int r03 = 55;
            int c02 = 218;
            int r04 = 81;
            int r05 = 103;
            int r06 = 127;
            int r07 = 152;
            int r08 = 176;
            int r09 = 200;


            SPFile file = web.GetFile(pdfFilePath);

            if (file.Exists)
            {
                int bufferSize = 20480;
                byte[] byteBuffer = new byte[bufferSize];
                //byteBuffer = File.ReadAllBytes(pdfFilePath);
                byteBuffer = file.OpenBinary();

                MemoryStream coverSheetContent = new MemoryStream();

                coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length);
                int t = PdfReader.TestPdfFile(coverSheetContent);
                PdfDocument document = PdfReader.Open(coverSheetContent);
                PdfPage page = document.Pages[0];

                XForm form = new XForm(document, XUnit.FromMillimeter(dx), XUnit.FromMillimeter(dy));
                XGraphics formGfx = XGraphics.FromForm(form);

                // Draw a large transparent rectangle to visualize the area the form occupies
#if DEBUG
                XColor back = XColors.Orange;
#else
                XColor back = XColors.White;
#endif

                back.A = 0.2;
                XSolidBrush brush = new XSolidBrush(back);
                formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

                XFont font = new XFont("Verdana", 10, XFontStyle.Bold); //XFont("Verdana", 10, XFontStyle.Regular)

                string odbiorca2 = string.Empty;
                if (odbiorca.Length > maxLen)
                {
                    odbiorca2 = odbiorca.Substring(maxLen, odbiorca.Length - maxLen);
                    if (odbiorca2.Length > maxLen)
                    {
                        odbiorca2 = odbiorca2.Substring(0, maxLen);
                    }
                    odbiorca = odbiorca.Substring(0, maxLen);
                }

                PlotText(odbiorca, c01, r01, ofset0, formGfx, font);

                PlotText(odbiorca2, c01, r02, ofset0, formGfx, font);

                PlotText(numerRachunku, c01, r03, ofset0, formGfx, font);

                PlotText("X", c01 + (int)(9 * ofset0) + 2, r04 - 3, ofset0, formGfx, font);
                PlotText((string)(String.Format("{0:#0.00}", kwotaDoZaplaty) + "************").Substring(0, 12), c02, r04, ofset0, formGfx, font);

                int zlote = (int)kwotaDoZaplaty;
                int grosze = (int)(100 * kwotaDoZaplaty) % 100;
                string kwota = String.Format("{0} {1}",
                    KwotaSlownie.LiczbaSlownie(zlote),
                    grosze + "/100");

                formGfx.DrawString("*" + kwota + "*", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, c01, r05, XStringFormats.TopLeft);

                string zleceniodawca2 = string.Empty;
                if (zleceniodawca.Length > maxLen)
                {
                    zleceniodawca2 = zleceniodawca.Substring(maxLen, zleceniodawca.Length - maxLen);
                    if (zleceniodawca2.Length > maxLen)
                    {
                        zleceniodawca2 = zleceniodawca2.Substring(0, maxLen);
                    }
                    zleceniodawca = zleceniodawca.Substring(0, maxLen);
                }
                PlotText(zleceniodawca, c01, r06, ofset0, formGfx, font);
                PlotText(zleceniodawca2, c01, r07, ofset0, formGfx, font);

                PlotText(nip, c01, r08, ofset0, formGfx, font);
                PlotText(typIdentyfikatora, c01 + (int)(15 * ofset0), r08, ofset0, formGfx, font);
                PlotText(okres, c01 + (int)(19 * ofset0), r08, ofset0, formGfx, font);
                PlotText(symbolFormularza, c01, r09, ofset0, formGfx, font);
                PlotText(identyfikacjaZobowiazania, c01 + (int)(7 * ofset0), r09, ofset0, formGfx, font);


                XPen pen = XPens.LightBlue.Clone();
                pen.Width = 2.5;

                XGraphics gfx = XGraphics.FromPdfPage(page);

                // Draw the form on the page of the document in its original size
                gfx.DrawImage(form, x0, y0);
                gfx.DrawImage(form, x0, y0 + 300);

                MemoryStream ms = new MemoryStream();
                document.Save(ms);

                item.Attachments.AddNow(nazwaPliku, ms.GetBuffer());
                //item.SystemUpdate();

                return true;
            }

            else
            {
                return false;
            }


        }
Exemplo n.º 29
0
 string IContentStream.GetFormName(XForm form)
 {
   throw new NotImplementedException();
 }
Exemplo n.º 30
0
        /// <summary>
        /// Take in an enumerable of people objects and a background image. Gives back a printable pdf of badges.
        /// </summary>
        /// <param name="people">People to print badges for.</param>
        /// <param name="background">Background image of badge.</param>
        /// <returns>PDF MemoryStream for returning to web user.</returns>
        public static MemoryStream MakeBadge(IEnumerable<People> people,
											 Image background)
        {
            // settings for Avery 5392 cardstock with badges printed horizontally (4 x 3)
            // offsets used to layout the text
            const double baseYOffset = 1.0;
            const double baseXOffset = .25;
            const double imageYOffset = .1;
            const double imageXOffset = .1;
            const double textWidth = 3.5;
            const double nameTextXOffset = 0.25;
            const double nameTextYOffset = 1.3;
            const double nameTextHeight = .3;
            const double companyTextXOffset = 0.25;
            const double companyTextYOffset = 1.7;
            const double companyTextHeight = .2;
            const double alumTextXOffset = 0.25;
            const double alumTextYOffset = 1.9;
            const double alumTextHeight = .2;
            const double badgeWidth = 3.8;
            const double badgeHeight = 2.8;
            const int maxNameBigFontLength = 17;
            const int bigFontSize = 20;
            const int smallFontSize = 16;
            const int titleFontSize = 14;
            const string fontName = "Helvetica";
            const XFontStyle nameFontStyle = XFontStyle.Regular;
            const XFontStyle titleFontStyle = XFontStyle.Regular;
            // the rest just build it
            //make a new document
            var doc = new PdfDocument();
            // badge is 4 inches wide and 3 inches tall
            // it's smaller here so we can leave some spacing around the edges so they print right
            var badge = new XForm(doc,
                                  XUnit.FromInch(badgeWidth),
                                  XUnit.FromInch(badgeHeight));
            // graphic for form
            XGraphics formGfx = XGraphics.FromForm(badge);
            // add background image to template
            formGfx.DrawImage(background, 0, 0, XUnit.FromInch(badgeWidth), XUnit.FromInch(badgeHeight));
            // Save the template to clone out with people's names
            //var template = formGfx.Save();
            int counter = 0;
            PdfPage page;
            XGraphics pageGfx = null;
            foreach (People person in people)
            {
                // make long names smaller
                int fontSize = person.name.Length > maxNameBigFontLength
                                ? smallFontSize
                                : bigFontSize;
                var nameFont = new XFont(fontName, fontSize, nameFontStyle);
                var titleFont = new XFont(fontName, titleFontSize, titleFontStyle);
                // there are 3 columns with 2 rows with each column being 3 inches and row being 4 inches
                // these offsets choose which badge is being printed by simple algebra
                double rowOffset = ((counter % 6) / 2) * 3.0;
                double columnOffset = (counter % 2) * 4.0;
                if (counter % 6 == 0)
                {
                    // add a new page
                    page = doc.AddPage();
                    // set it landscape
                    //page.Orientation = PageOrientation.Landscape;
                    // make a graphic on the page
                    pageGfx = XGraphics.FromPdfPage(page);
                }
                // one liner placement of badges
                pageGfx.DrawImage(badge,
                                  XUnit.FromInch(baseXOffset + columnOffset + imageXOffset),
                                  XUnit.FromInch(baseYOffset + rowOffset + imageYOffset));
                // draw their name
                pageGfx.DrawString(person.name,
                                   nameFont,
                                   XBrushes.Black,
                                   new XRect(
                                    XUnit.FromInch(baseXOffset + columnOffset +
                                                   nameTextXOffset),
                                    XUnit.FromInch(baseYOffset + rowOffset + nameTextYOffset),
                                    XUnit.FromInch(textWidth),
                                    XUnit.FromInch(nameTextHeight)),
                                   XStringFormats.Center);
                // draw their title (company, alum)
                if (person.CompanyPerson != null)
                {
                    pageGfx.DrawString(person.CompanyPerson.Company.name,
                                       titleFont,
                                       XBrushes.Black,
                                       new XRect(
                                        XUnit.FromInch(baseXOffset + columnOffset +
                                                       companyTextXOffset),
                                        XUnit.FromInch(baseYOffset + rowOffset +
                                                       companyTextYOffset),
                                        XUnit.FromInch(textWidth),
                                        XUnit.FromInch(companyTextHeight)),
                                       XStringFormats.Center);
                }
                if (person.is_alum)
                {
                    pageGfx.DrawString("Alum",
                                       titleFont,
                                       XBrushes.Black,
                                       new XRect(
                                        XUnit.FromInch(baseXOffset + columnOffset +
                                                       alumTextXOffset),
                                        XUnit.FromInch(baseYOffset + rowOffset +
                                                       alumTextYOffset),
                                        XUnit.FromInch(textWidth),
                                        XUnit.FromInch(alumTextHeight)),
                                       XStringFormats.Center);
                }
                counter += 1;
            }
            var ms = new MemoryStream();
            doc.Save(ms, false);
            ms.Seek(0, SeekOrigin.Begin); // go to the beginning
            return ms;
        }
Exemplo n.º 31
0
    ///// <summary>
    ///// Makes the specified pen and brush to the current graphics objects.
    ///// </summary>
    //void Realize(Pen pen, XBrush brush)
    //{
    //  BeginPage();
    //  BeginGraphic();
    //  RealizeTransform();

    //  if (pen != null)
    //    this.gfxState.RealizePen(pen, this.colorMode); // this.page.document.Options.ColorMode);

    //  if (brush != null)
    //    this.gfxState.RealizeBrush(brush, this.colorMode); // this.page.document.Options.ColorMode);
    //}

    /// <summary>
    /// Makes the specified brush to the current graphics object.
    /// </summary>
    public void RealizeFill(Brush brush, ref XForm xform, ref XImage ximage)
    {
      this.graphicsState.RealizeFill(brush, 1, ref xform, ref ximage);
    }