示例#1
0
        private void ShowText(PdfContentByte cb, float x, float y, float xPrevious, float yPrevious, double xmidden, double ymidden, String character)
        {
            double corner = CalculateCorner(x, y, xPrevious, yPrevious);

            cb.SaveState();
            PdfTemplate template2 = cb.CreateTemplate(1000, 1000);

            template2.BeginText();
            template2.SetColorFill(BaseColor.BLACK);
            BaseFont bf = BaseFont.CreateFont();

            template2.SetFontAndSize(bf, fontsize);
            //template2.SetTextRise(10);
            //double halfWidthOfCharacter = cb.GetEffectiveStringWidth(character+"", true) / 2.0;
            template2.SetTextMatrix(0, 0);
            template2.ShowText(character + "");
            template2.EndText();
            Matrix translation = new Matrix();

            translation.Translate((float)xmidden, (float)ymidden);
            cb.ConcatCTM(translation);
            Matrix rotation = new Matrix();

            rotation.Rotate((float)corner);
            cb.ConcatCTM(rotation);
            cb.ConcatCTM(1, 0, 0, -1, 0, 0);
            cb.AddTemplate(template2, 0, 0);
            cb.RestoreState();
        }
示例#2
0
        protected override void Draw(PdfContentByte cb)
        {
            //TODO if width and height not know: what to do
            //PdfTemplate template = cb.CreateTemplate(this.width, this.height);
            PdfTemplate template = cb.CreateTemplate(500, 500);

            //draw the list of elements on the new template
            foreach (IElement elem in this.list)
            {
                Graphic graphic = (Graphic)elem;

                if (applyCSSToElements)
                {
                    graphic.Draw(template, GetCombinedCss(graphic.GetCss(), GetCss()));
                }
                else
                {
                    graphic.Draw(template, graphic.GetCss());
                }
            }
            //add the template at the x, y position
            System.Drawing.Drawing2D.Matrix translation = new System.Drawing.Drawing2D.Matrix();
            translation.Translate(this.x, this.y);
            cb.ConcatCTM(translation);

            cb.Add(template);
        }
示例#3
0
// ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         */
        public byte[] CreatePdf()
        {
            // step 1
            Rectangle rect = new Rectangle(-595, -842, 595, 842);

            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document(rect)) {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    PdfContentByte canvas = writer.DirectContent;
                    canvas.MoveTo(-595, 0);
                    canvas.LineTo(595, 0);
                    canvas.MoveTo(0, -842);
                    canvas.LineTo(0, 842);
                    canvas.Stroke();
                    // Read the PDF containing the logo
                    PdfReader   reader   = new PdfReader(RESOURCE);
                    PdfTemplate template = writer.GetImportedPage(reader, 1);
                    // add it at different positions using different transformations
                    canvas.SaveState();
                    canvas.AddTemplate(template, 0, 0);
                    canvas.ConcatCTM(0.5f, 0, 0, 0.5f, -595, 0);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.ConcatCTM(1, 0, 0, 1, 595, 595);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.RestoreState();

                    canvas.SaveState();
                    canvas.ConcatCTM(1, 0, 0.4f, 1, -750, -650);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.RestoreState();

                    canvas.SaveState();
                    canvas.ConcatCTM(0, -1, -1, 0, 650, 0);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.ConcatCTM(0.2f, 0, 0, 0.5f, 0, 300);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.RestoreState();
                }
                return(ms.ToArray());
            }
        }
示例#4
0
 public void OutputText(int x, int y, int flag, int x1, int y1, int x2, int y2, string text) {
     MetaFont font = state.CurrentFont;
     float refX = state.TransformX(x);
     float refY = state.TransformY(y);
     float angle = state.TransformAngle(font.Angle);
     float sin = (float)Math.Sin(angle);
     float cos = (float)Math.Cos(angle);
     float fontSize = font.GetFontSize(state);
     BaseFont bf = font.Font;
     int align = state.TextAlign;
     float textWidth = bf.GetWidthPoint(text, fontSize);
     float tx = 0;
     float ty = 0;
     float descender = bf.GetFontDescriptor(BaseFont.DESCENT, fontSize);
     float ury = bf.GetFontDescriptor(BaseFont.BBOXURY, fontSize);
     cb.SaveState();
     cb.ConcatCTM(cos, sin, -sin, cos, refX, refY);
     if ((align & MetaState.TA_CENTER) == MetaState.TA_CENTER)
         tx = -textWidth / 2;
     else if ((align & MetaState.TA_RIGHT) == MetaState.TA_RIGHT)
         tx = -textWidth;
     if ((align & MetaState.TA_BASELINE) == MetaState.TA_BASELINE)
         ty = 0;
     else if ((align & MetaState.TA_BOTTOM) == MetaState.TA_BOTTOM)
         ty = -descender;
     else
         ty = -ury;
     Color textColor;
     if (state.BackgroundMode == MetaState.OPAQUE) {
         textColor = state.CurrentBackgroundColor;
         cb.SetColorFill(textColor);
         cb.Rectangle(tx, ty + descender, textWidth, ury - descender);
         cb.Fill();
     }
     textColor = state.CurrentTextColor;
     cb.SetColorFill(textColor);
     cb.BeginText();
     cb.SetFontAndSize(bf, fontSize);
     cb.SetTextMatrix(tx, ty);
     cb.ShowText(text);
     cb.EndText();
     if (font.IsUnderline()) {
         cb.Rectangle(tx, ty - fontSize / 4, textWidth, fontSize / 15);
         cb.Fill();
     }
     if (font.IsStrikeout()) {
         cb.Rectangle(tx, ty + fontSize / 3, textWidth, fontSize / 15);
         cb.Fill();
     }
     cb.RestoreState();
 }
示例#5
0
// ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         */
        public byte[] CreatePdf()
        {
            // step 1
            Rectangle rect = new Rectangle(-595, -842, 595, 842);

            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document(rect)) {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    PdfContentByte canvas = writer.DirectContent;
                    // draw coordinate system
                    canvas.MoveTo(-595, 0);
                    canvas.LineTo(595, 0);
                    canvas.MoveTo(0, -842);
                    canvas.LineTo(0, 842);
                    canvas.Stroke();
                    // read the PDF with the logo
                    PdfReader   reader   = new PdfReader(RESOURCE);
                    PdfTemplate template = writer.GetImportedPage(reader, 1);
                    // add it
                    canvas.SaveState();
                    canvas.AddTemplate(template, 0, 0);
                    AffineTransform af = new AffineTransform();
                    af.Translate(-595, 0);
                    af.Scale(0.5f, 0.5f);
                    canvas.Transform(af);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.ConcatCTM(AffineTransform.GetTranslateInstance(595, 595));
                    canvas.AddTemplate(template, 0, 0);
                    canvas.RestoreState();

                    canvas.SaveState();
                    af = new AffineTransform(1f, 0f, 0.4f, 1f, -750f, -650f);
                    canvas.AddTemplate(template, af);
                    canvas.RestoreState();

                    canvas.SaveState();
                    af = new AffineTransform(0, -1, -1, 0, 650, 0);
                    canvas.AddTemplate(template, af);
                    af = new AffineTransform(0, -0.2f, -0.5f, 0, 350, 0);
                    canvas.AddTemplate(template, af);
                    canvas.RestoreState();
                }
                return(ms.ToArray());
            }
        }
示例#6
0
 // ===========================================================================
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(new Rectangle(200, 120)))
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfContentByte canvas = writer.DirectContent;
         // state 1:
         canvas.SetRGBColorFill(0xFF, 0x45, 0x00);
         // fill a rectangle in state 1
         canvas.Rectangle(10, 10, 60, 60);
         canvas.Fill();
         canvas.SaveState();
         // state 2;
         canvas.SetLineWidth(3);
         canvas.SetRGBColorFill(0x8B, 0x00, 0x00);
         // fill and stroke a rectangle in state 2
         canvas.Rectangle(40, 20, 60, 60);
         canvas.FillStroke();
         canvas.SaveState();
         // state 3:
         canvas.ConcatCTM(1, 0, 0.1f, 1, 0, 0);
         canvas.SetRGBColorStroke(0xFF, 0x45, 0x00);
         canvas.SetRGBColorFill(0xFF, 0xD7, 0x00);
         // fill and stroke a rectangle in state 3
         canvas.Rectangle(70, 30, 60, 60);
         canvas.FillStroke();
         canvas.RestoreState();
         // stroke a rectangle in state 2
         canvas.Rectangle(100, 40, 60, 60);
         canvas.Stroke();
         canvas.RestoreState();
         // fill and stroke a rectangle in state 1
         canvas.Rectangle(130, 50, 60, 60);
         canvas.FillStroke();
     }
 }
示例#7
0
        /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
         * barcode is always placed at coodinates (0, 0). Use the
         * translation matrix to move it elsewhere.<p>
         * The bars and text are written in the following colors:<p>
         * <P><TABLE BORDER=1>
         * <TR>
         *   <TH><P><CODE>barColor</CODE></TH>
         *   <TH><P><CODE>textColor</CODE></TH>
         *   <TH><P>Result</TH>
         *   </TR>
         * <TR>
         *   <TD><P><CODE>null</CODE></TD>
         *   <TD><P><CODE>null</CODE></TD>
         *   <TD><P>bars and text painted with current fill color</TD>
         *   </TR>
         * <TR>
         *   <TD><P><CODE>barColor</CODE></TD>
         *   <TD><P><CODE>null</CODE></TD>
         *   <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
         *   </TR>
         * <TR>
         *   <TD><P><CODE>null</CODE></TD>
         *   <TD><P><CODE>textColor</CODE></TD>
         *   <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
         *   </TR>
         * <TR>
         *   <TD><P><CODE>barColor</CODE></TD>
         *   <TD><P><CODE>textColor</CODE></TD>
         *   <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
         *   </TR>
         * </TABLE>
         * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
         * @param barColor the color of the bars. It can be <CODE>null</CODE>
         * @param textColor the color of the text. It can be <CODE>null</CODE>
         * @return the dimensions the barcode occupies
         */
        public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
        {
            if (supp.Font != null)
            {
                supp.BarHeight = ean.BarHeight + supp.Baseline - supp.Font.GetFontDescriptor(BaseFont.CAPHEIGHT, supp.Size);
            }
            else
            {
                supp.BarHeight = ean.BarHeight;
            }
            Rectangle eanR = ean.BarcodeSize;

            cb.SaveState();
            ean.PlaceBarcode(cb, barColor, textColor);
            cb.RestoreState();
            cb.SaveState();
            cb.ConcatCTM(1, 0, 0, 1, eanR.Width + n, eanR.Height - ean.BarHeight);
            supp.PlaceBarcode(cb, barColor, textColor);
            cb.RestoreState();
            return(this.BarcodeSize);
        }
        public void BarcodeTest01()
        {
            String filename = "barcodeDataMatrix01.pdf";
            String code     = "AAAAAAAAAA;BBBBAAAA3;00028;BBBAA05;AAAA;AAAAAA;1234567;AQWXSZ;JEAN;;;;7894561;AQWXSZ;GEO;;;;1;1;1;1;0;0;1;0;1;0;0;0;1;0;1;0;0;0;0;0;0;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1";

            Document  document = new Document(PageSize.A4);
            PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(outFolder + filename, FileMode.Create));

            document.Open();
            document.Add(new Paragraph("Datamatrix test 01"));
            PdfContentByte cb = writer.DirectContent;

            cb.ConcatCTM(AffineTransform.GetTranslateInstance(PageSize.A4.Width / 2 - 100, PageSize.A4.Height / 2 - 100));
            BarcodeDatamatrix barcode = new BarcodeDatamatrix();

            barcode.Generate(code);
            barcode.PlaceBarcode(cb, BaseColor.GREEN, 5, 5);
            document.Close();

            CompareDocuments(filename);
        }
        public void BarcodeTest02()
        {
            String filename = "barcodeDataMatrix02.pdf";
            String code     = "дима";
            String encoding = "UTF-8";

            Document  document = new Document(PageSize.A4);
            PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(outFolder + filename, FileMode.Create));

            document.Open();
            document.Add(new Paragraph("Datamatrix test 02"));
            PdfContentByte cb = writer.DirectContent;

            cb.ConcatCTM(AffineTransform.GetTranslateInstance(PageSize.A4.Width / 2 - 100, PageSize.A4.Height / 2 - 100));
            BarcodeDatamatrix barcode = new BarcodeDatamatrix();

            barcode.Generate(code, encoding);
            barcode.PlaceBarcode(cb, BaseColor.GREEN, 5, 5);
            document.Close();

            CompareDocuments(filename);
        }
示例#10
0
        public virtual void DeviceNCmykRedRgbBlueGradient()
        {
            Document document = new Document();
            // step 2
            String    dest_file = DEST_FOLDER + "/device_n_gradient_CmykRedRgbBlue.pdf";
            PdfWriter writer    = PdfWriter.GetInstance(document, new FileStream(dest_file, FileMode.Create));

            // step 3
            document.Open();
            // step 4
            PdfContentByte  canvas       = writer.DirectContent;
            PdfSpotColor    psc_red      = new PdfSpotColor("Spot Red", new CMYKColor(0f, 1f, 1f, 0f));
            PdfSpotColor    psc_blue     = new PdfSpotColor("Spot Blue", new BaseColor(0, 0, 255));
            PdfDeviceNColor deviceNColor = new PdfDeviceNColor(new PdfSpotColor[] { psc_red, psc_blue });

            canvas.SaveState();
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Clip();
            canvas.NewPath();
            canvas.SaveState();
            canvas.ConcatCTM(329f, 0f, 0f, -329f, 89f, 506.5f);
            canvas.PaintShading(PdfShading.SimpleAxial(writer, 0, 0, 1, 0, new DeviceNColor(deviceNColor, new float[] { 1, 0 }),
                                                       new DeviceNColor(deviceNColor, new float[] { 0, 1 })));
            canvas.RestoreState();
            canvas.RestoreState();
            canvas.SetCMYKColorStroke(0, 0, 0, 0xFF);
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Stroke();
            document.Close();

            CompareTool compareTool = new CompareTool();
            String      error       = compareTool.Compare(dest_file, TEST_RESOURCES_PATH + "cmp_device_n_gradient_CmykRedRgbBlue.pdf", DEST_FOLDER, "diff_");

            if (error != null)
            {
                Assert.Fail(error);
            }
        }
示例#11
0
        public void BarcodeTest04()
        {
            String filename = "barcodeDataMatrix04.pdf";
            String code     = "01AbcdefgAbcdefg123451231231234";

            Document  document = new Document(PageSize.A4);
            PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(outFolder + filename, FileMode.Create));

            document.Open();
            document.Add(new Paragraph("Datamatrix test 04"));
            PdfContentByte cb = writer.DirectContent;

            cb.ConcatCTM(AffineTransform.GetTranslateInstance(PageSize.A4.Width / 2 - 100, PageSize.A4.Height / 2 - 100));
            BarcodeDatamatrix barcode = new BarcodeDatamatrix();

            barcode.Width  = 36;
            barcode.Height = 12;
            barcode.Generate(code);
            barcode.PlaceBarcode(cb, BaseColor.BLACK, 5, 5);
            document.Close();

            CompareDocuments(filename);
        }
示例#12
0
        public virtual void LabSpotBasedGradient()
        {
            // step 1
            Document document = new Document(PageSize.A3);
            // step 2
            String    dest_file = DEST_FOLDER + "/lab_spot_based_gradient.pdf";
            PdfWriter writer    = PdfWriter.GetInstance(document, new FileStream(dest_file, FileMode.Create));

            // step 3
            document.Open();
            // step 4
            PdfContentByte canvas      = writer.DirectContent;
            PdfLabColor    pdfLabColor = new PdfLabColor(new float[] { 0.9505f, 1.0f, 1.0890f }, new float[] { 0f, 0.5f, 1.5f },
                                                         new float[] { -10, 100, -10, 100 });
            PdfDeviceNColor pdfDeviceNNChannelColor =
                new PdfDeviceNColor(new PdfSpotColor[] {
                new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))),
                new PdfSpotColor("labBlue", pdfLabColor.Rgb2lab(new BaseColor(0, 0, 255)))
            });
            PdfSpotColor psc_lab3     = new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83)));
            PdfSpotColor psc_lab2     = new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96)));
            PdfSpotColor psc_lab1     = new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0)));
            PdfSpotColor psc_lab_blue = new PdfSpotColor("labBlue", new BaseColor(0, 0, 100));

            PdfDeviceNColor pdfDeviceNNChannelColor2 = new PdfDeviceNColor(new PdfSpotColor[] { psc_lab_blue, psc_lab2, psc_lab1 });

            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 0, 255)), 36, 878, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96)), 90, 878, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83)), 144, 878, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 50, 50)), 198, 878, 36, 36);

            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 0, 255)).ToRgb(), 36, 824, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96)).ToRgb(), 90, 824, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83)).ToRgb(), 144, 824, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 50, 50)).ToRgb(), 198, 824, 36, 36);


            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 1f), 36, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 0.8f), 90, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 0.6f), 144, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 0.2f), 198, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 1f), 252, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 0.8f), 306, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 0.6f), 360, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 0.2f), 416, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 1.0f), 470, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 0.8f), 524, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 0.6f), 578, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 0.2f), 634, 986, 36, 36);

            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 1f), 36, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 0.8f), 90, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 0.6f), 144, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 0.2f), 198, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 1f), 252, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 0.8f), 306, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 0.6f), 360, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 0.2f), 416, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 1.0f), 470, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 0.8f), 524, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 0.6f), 578, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 0.2f), 634, 932, 36, 36);

            ColorRectangle(canvas, new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] { psc_lab2, psc_lab_blue, psc_lab1 }), new float[] { 0, 0.0f, 1 }), 36, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.1f, 0.1f }), 90, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.2f, 0.2f }), 144, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.3f, 0.3f }), 198, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.4f, 0.4f }), 252, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] { psc_lab2, psc_lab_blue, psc_lab1, psc_lab3 }), new float[] { 0.5f, 0.5f, 1, 0.5f }), 306, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor2, new float[] { 0.6f, 0.1f, 0.5f }), 360, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.7f, 0.7f }), 416, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.8f, 0.8f }), 470, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] { psc_lab2, psc_lab_blue, psc_lab1 }), new float[] { 0.9f, 0.9f, 1 }), 524, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 1, 1 }), 578, 770, 36, 36);

            canvas.SaveState();
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Clip();
            canvas.NewPath();
            canvas.SaveState();
            canvas.ConcatCTM(329f, 0f, 0f, -329f, 89f, 506.5f);
            canvas.PaintShading(PdfShading.SimpleAxial(writer, 0, 0, 1, 0, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 1, 0 }), new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0, 1 })));
            canvas.RestoreState();
            canvas.RestoreState();
            canvas.SetColorStroke(new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 1, 1 }));
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Stroke();

            // step 5
            document.Close();

            CompareTool compareTool = new CompareTool();
            String      error       = compareTool.Compare(dest_file, TEST_RESOURCES_PATH + "cmp_lab_spot_based_gradient.pdf", DEST_FOLDER, "diff");

            if (error != null)
            {
                Assert.Fail(error);
            }
        }
示例#13
0
 /** Shows a line of text. Only the first line is written.
  * @param canvas where the text is to be written to
  * @param alignment the alignment. It is not influenced by the run direction
  * @param phrase the <CODE>Phrase</CODE> with the text
  * @param x the x reference position
  * @param y the y reference position
  * @param rotation the rotation to be applied in degrees counterclockwise
  * @param runDirection the run direction
  * @param arabicOptions the options for the arabic shaping
  */
 public static void ShowTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions)
 {
     if (alignment != Element.ALIGN_LEFT && alignment != Element.ALIGN_CENTER
     && alignment != Element.ALIGN_RIGHT)
     alignment = Element.ALIGN_LEFT;
     canvas.SaveState();
     ColumnText ct = new ColumnText(canvas);
     float lly = -1;
     float ury = 2;
     float llx;
     float urx;
     switch (alignment) {
     case Element.ALIGN_LEFT:
         llx = 0;
         urx = 20000;
         break;
     case Element.ALIGN_RIGHT:
         llx = -20000;
         urx = 0;
         break;
     default:
         llx = -20000;
         urx = 20000;
         break;
     }
     if (rotation == 0) {
     llx += x;
     lly += y;
     urx += x;
     ury += y;
     }
     else {
     double alpha = rotation * Math.PI / 180.0;
     float cos = (float)Math.Cos(alpha);
     float sin = (float)Math.Sin(alpha);
     canvas.ConcatCTM(cos, sin, -sin, cos, x, y);
     }
     ct.SetSimpleColumn(phrase, llx, lly, urx, ury, 2, alignment);
     if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
     if (alignment == Element.ALIGN_LEFT)
         alignment = Element.ALIGN_RIGHT;
     else if (alignment == Element.ALIGN_RIGHT)
         alignment = Element.ALIGN_LEFT;
     }
     ct.Alignment = alignment;
     ct.ArabicOptions = arabicOptions;
     ct.RunDirection = runDirection;
     ct.Go();
     canvas.RestoreState();
 }
示例#14
0
 /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
  * barcode is always placed at coodinates (0, 0). Use the
  * translation matrix to move it elsewhere.<p>
  * The bars and text are written in the following colors:<p>
  * <P><TABLE BORDER=1>
  * <TR>
  *   <TH><P><CODE>barColor</CODE></TH>
  *   <TH><P><CODE>textColor</CODE></TH>
  *   <TH><P>Result</TH>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P>bars and text painted with current fill color</TD>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>barColor</CODE></TD>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P><CODE>textColor</CODE></TD>
  *   <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>barColor</CODE></TD>
  *   <TD><P><CODE>textColor</CODE></TD>
  *   <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
  *   </TR>
  * </TABLE>
  * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
  * @param barColor the color of the bars. It can be <CODE>null</CODE>
  * @param textColor the color of the text. It can be <CODE>null</CODE>
  * @return the dimensions the barcode occupies
  */
 public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor)
 {
     if (supp.Font != null)
         supp.BarHeight = ean.BarHeight + supp.Baseline - supp.Font.GetFontDescriptor(BaseFont.CAPHEIGHT, supp.Size);
     else
         supp.BarHeight = ean.BarHeight;
     Rectangle eanR = ean.BarcodeSize;
     cb.SaveState();
     ean.PlaceBarcode(cb, barColor, textColor);
     cb.RestoreState();
     cb.SaveState();
     cb.ConcatCTM(1, 0, 0, 1, eanR.Width + n, eanR.Height - ean.BarHeight);
     supp.PlaceBarcode(cb, barColor, textColor);
     cb.RestoreState();
     return this.BarcodeSize;
 }
示例#15
0
        public virtual void DeviceNSpotBasedGradient()
        {
            // step 1
            Document document = new Document(PageSize.A3);
            // step 2
            String    dest_file = DEST_FOLDER + "/device_n_gradient_base.pdf";
            PdfWriter writer    = PdfWriter.GetInstance(document, new FileStream(dest_file, FileMode.Create));

            // step 3
            document.Open();
            // step 4
            PdfContentByte canvas         = writer.DirectContent;
            PdfSpotColor   psc_gray       = new PdfSpotColor("iTextGray", new GrayColor(0f));
            PdfSpotColor   psc_cmyk_yell  = new PdfSpotColor("iTextYellow", new CMYKColor(0f, 0f, 1f, 0f));
            PdfSpotColor   psc_cmyk_magen = new PdfSpotColor("iTextMagenta", new CMYKColor(0f, 1f, 0f, 0f));
            PdfSpotColor   psc_rgb_blue   = new PdfSpotColor("iTextBlue", new BaseColor(0, 0, 255));

            PdfDeviceNColor pdfDeviceNNChannelColor =
                new PdfDeviceNColor(new PdfSpotColor[] { psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue });
            PdfDeviceNColor pdfDeviceNNChannelColor2 =
                new PdfDeviceNColor(new PdfSpotColor[] { psc_cmyk_magen, psc_cmyk_yell, psc_rgb_blue });

            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextGray", new GrayColor(0f)), 0.8f), 36, 824, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextYellow", new CMYKColor(0f, 0f, 1f, 0f)), 0.8f), 90, 824,
                           36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextMagenta", new CMYKColor(0f, 1f, 0f, 0f)), 0.4f), 144, 824,
                           36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextBlue", new BaseColor(0, 0, 255)), 0.7f), 198, 824, 36, 36);

            ColorRectangle(canvas,
                           new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] { psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue }),
                                            new float[] { 0, 0.0f, 1 }), 36, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.1f, 0.1f, 1 }), 90, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.2f, 0.2f, 1 }), 144, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.3f, 0.3f, 1 }), 198, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.4f, 0.4f, 1 }), 252, 770, 36, 36);
            ColorRectangle(canvas,
                           new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] { psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue, psc_gray }),
                                            new float[] { 0.5f, 0.5f, 1, 0.5f }), 306, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor2, new float[] { 0.6f, 0.1f, 1 }), 360, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.7f, 0.7f, 1 }), 416, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0.8f, 0.8f, 1 }), 470, 770, 36, 36);
            ColorRectangle(canvas,
                           new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] { psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue }),
                                            new float[] { 0.9f, 0.9f, 1 }), 524, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 1, 1, 1 }), 578, 770, 36, 36);

            PdfDeviceNColor pdfDeviceNColor = new PdfDeviceNColor(new PdfSpotColor[] { psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue });

            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0, 0, 1 }));
            canvas.Rectangle(36, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.1f, 0.1f, 1 }));
            canvas.Rectangle(90, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.2f, 0.2f, 1 }));
            canvas.Rectangle(144, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.3f, 0.3f, 1 }));
            canvas.Rectangle(198, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.4f, 0.4f, 1 }));
            canvas.Rectangle(252, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.5f, 0.5f, 1 }));
            canvas.Rectangle(306, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.6f, 0.1f, 1 }));
            canvas.Rectangle(360, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.7f, 0.7f, 1 }));
            canvas.Rectangle(416, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.8f, 0.8f, 1 }));
            canvas.Rectangle(470, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 0.9f, 0.9f, 1 }));
            canvas.Rectangle(524, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] { 1, 1, 1 }));
            canvas.Rectangle(578, 716, 36, 36);
            canvas.FillStroke();

            canvas.SaveState();
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Clip();
            canvas.NewPath();
            canvas.SaveState();
            canvas.ConcatCTM(329f, 0f, 0f, -329f, 89f, 506.5f);
            canvas.PaintShading(PdfShading.SimpleAxial(writer, 0, 0, 1, 0,
                                                       new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 1, 1, 0 }),
                                                       new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 0, 0, 1 })));
            canvas.RestoreState();
            canvas.RestoreState();
            canvas.SetColorStroke(new DeviceNColor(pdfDeviceNNChannelColor, new float[] { 1, 1, 1 }));
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Stroke();

            // step 5
            document.Close();

            CompareTool compareTool = new CompareTool();
            String      error       = compareTool.Compare(dest_file, TEST_RESOURCES_PATH + "cmp_device_n_gradient_base.pdf", DEST_FOLDER, "diff_");

            if (error != null)
            {
                Assert.Fail(error);
            }
        }
示例#16
0
 protected override void Draw(PdfContentByte cb)
 {
     //change the coordinate system for all what follows
     //bottom left corner to top right corner
     cb.ConcatCTM(1, 0, 0, -1, -viewBox.Left, height - viewBox.Bottom);
 }
示例#17
0
        void DrawGroup(PdfContentByte cb)
        {
            //TODO if width and height not know: what to do
            //PdfTemplate template = cb.CreateTemplate(this.width, this.height);
            PdfTemplate template = cb.CreateTemplate(500, 500);
            //draw the list of elements on the new template

            IList <int> xSpacing = null, ySpacing = null;
            float       defaultSpacing = template.CharacterSpacing;
            float       rise           = 0;

            template.BeginText();
            //
            foreach (IElement elem in this.list)
            {
                Text text = (Text)elem;
                //CssSvgAppliers.GetInstance().ApplyForText(, text.GetCss(), text.GetChunk());
                CssSvgAppliers.GetInstance().ApplyForText(template, text.GetCss(), text.GetChunk());

                if (!text.IsRelative())
                {
                    //when there are x,y coordinates in the text or tspan
                    template.SetTextMatrix(text.GetX(), -1 * text.GetY());
                }

                //System.out.Println(text.chunk.GetFont());

                //the spacing
                if (text.Dx != null)
                {
                    xSpacing = text.Dx;
                }
                if (text.Dy != null)
                {
                    ySpacing = text.Dy;
                    rise     = 0;
                }
                if (xSpacing != null || ySpacing != null)
                {
                    String display = text.GetText();
                    for (int i = 0; i < display.Length; i++)
                    {
                        if (xSpacing != null && xSpacing.Count > 0)
                        {
                            template.SetCharacterSpacing(xSpacing[0]);
                            xSpacing.Remove(0);
                        }
                        if (ySpacing != null && ySpacing.Count > 0)
                        {
                            rise = rise - ySpacing[0];
                            template.SetTextRise(rise);
                            ySpacing.Remove(0);
                        }
                        else
                        {
                            template.SetTextRise(rise);
                        }
                        template.ShowText(display.Substring(i, 1));

                        template.SetCharacterSpacing(defaultSpacing);
                    }
                }
                else
                {
                    template.ShowText(text.GetText());
                }
            }
            template.EndText();
            //add the template at the x, y position
            cb.ConcatCTM(1, 0, 0, -1, 0, 0);

            cb.Add(template);
        }