Ejemplo n.º 1
0
        private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //MessageBox.Show(e.PageSettings.PaperSize);
            pageSize = e.PageSettings.PaperSize;

            Point newPt = UCS.shiftAnchor(UCS.Type.form, UCS.Corner.TopLeft, (UCS.Corner)anchor.SelectedIndex,
                                          pageSize.Width, pageSize.Height,

                                          (int)w.Value, (int)h.Value,

                                          new Point((int)x.Value, (int)y.Value)
                                          );

            e.Graphics.DrawImage(new Bitmap(stampname), newPt);
        }
Ejemplo n.º 2
0
        public void PdfStamp(string fileout, string stamp, string filein)
        {
            if (File.Exists(filein) && File.Exists(stamp))
            {
                PdfDocument pdf = new PdfDocument(new PdfReader(filein), new PdfWriter(fileout));
                // MessageBox.Show(pdf.GetNumberOfPages().ToString());
                for (var i = 0; i < pdf.GetNumberOfPages(); i++)
                {
                    PdfCanvas canvas = new PdfCanvas(pdf.GetPage(i + 1));
                    ImageData image  = ImageDataFactory.Create(stamp);
                    image.SetRotation(rotation);
                    canvas.SaveState();
                    PdfExtGState state = new PdfExtGState();

                    state.SetFillOpacity(transprency > 1f ? (transprency / 100) : transprency);
                    canvas.SetExtGState(state);


                    System.Drawing.Point newPt =/* new System.Drawing.Point(0, 0);*/
                                                 UCS.shiftAnchor(UCS.Type.pdf, UCS.Corner.TopLeft, anchor,
                                                                 (int)pdf.GetPage(i + 1).GetPageSize().GetWidth(), (int)pdf.GetPage(i + 1).GetPageSize().GetHeight(),

                                                                 (int)image.GetWidth(), (int)image.GetHeight(),

                                                                 new System.Drawing.Point(x, y)
                                                                 );


                    //TODO: add width & height to image
                    canvas.AddImage(image, newPt.X, newPt.Y, false);

                    canvas.RestoreState();
                }
                pdf.Close();
            }
        }