Exemplo n.º 1
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));

            Barcode128 code128 = new Barcode128(pdfDoc);

            code128.SetCode("12345XX789XXX");
            code128.SetCodeType(Barcode128.CODE128);
            PdfFormXObject xObject = code128.CreateFormXObject(ColorConstants.BLACK,
                                                               ColorConstants.BLACK, pdfDoc);

            float x      = 36;
            float y      = 750;
            float width  = xObject.GetWidth();
            float height = xObject.GetHeight();

            // Draw the rectangle with set background color and add the created barcode object.
            PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());

            canvas.SaveState();
            canvas.SetFillColor(ColorConstants.LIGHT_GRAY);
            canvas.Rectangle(x, y, width, height);
            canvas.Fill();
            canvas.RestoreState();
            canvas.AddXObjectAt(xObject, 36, 750);

            pdfDoc.Close();
        }
Exemplo n.º 2
0
        public void CreatePdf(PdfDocument pdfDocument, Document document, bool isLast)
        {
            document.SetLeftMargin(100);
            Barcode128 b = new Barcode128(pdfDocument);

            b.SetCodeType(Barcode128.CODE128);
            b.SetCode(ID);

            PdfFormXObject bobject = b.CreateFormXObject(pdfDocument);
            BarcodeQRCode  qr      = new BarcodeQRCode(ID);

            document.Add(new Paragraph(String.Format("{0} {1} {2}", Testee.Surname, Testee.Forename, Testee.Birthday.ToString("yyyy-MM-dd"))).SetFontSize(25).SetPaddingBottom(10));
            document.Add(new Paragraph("ID:"));
            document.Add(new Paragraph(ID).SetFontSize(40));
            document.Add(new Paragraph("ID NICHT DOPPELT SCANNEN").SetFontColor(ColorConstants.RED).SetBold().SetPaddingBottom(20));
            //document.Add(new Image(bobject).SetAutoScale(true));
            Div d = new Div();

            d.SetWidth(UnitValue.CreatePercentValue(33));
            d.Add(new Image(bobject).SetAutoScale(true));
            d.SetMarginBottom(20);
            document.Add(d);
            Div q = new Div();

            q.SetWidth(UnitValue.CreatePercentValue(50));
            q.Add(new Image(qr.CreateFormXObject(pdfDocument)).SetAutoScale(true));
            document.Add(q);
            if (!isLast)
            {
                document.Add(new AreaBreak());
            }
            //document.Close();
        }
Exemplo n.º 3
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            String      code   = "675-FH-A12";

            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();

            table.AddCell("Change baseline:");

            Barcode128 code128 = new Barcode128(pdfDoc);

            // If value is positive, the text distance under the bars. If zero or negative,
            // the text distance above the bars.
            code128.SetBaseline(-1);
            code128.SetSize(12);
            code128.SetCode(code);
            code128.SetCodeType(Barcode128.CODE128);
            Image code128Image = new Image(code128.CreateFormXObject(pdfDoc));

            // Notice that in iText5 in default PdfPCell constructor (new PdfPCell(Image img))
            // this image does not fit the cell, but it does in addCell().
            // In iText7 there is no constructor (new Cell(Image img)),
            // so the image adding to the cell can be done only using method add().
            Cell cell = new Cell().Add(code128Image);

            table.AddCell(cell);
            table.AddCell("Add text and bar code separately:");

            code128 = new Barcode128(pdfDoc);

            // Suppress the barcode text
            code128.SetFont(null);
            code128.SetCode(code);
            code128.SetCodeType(Barcode128.CODE128);

            // Let the image resize automatically by setting it to be autoscalable.
            code128Image = new Image(code128.CreateFormXObject(pdfDoc)).SetAutoScale(true);
            cell         = new Cell();
            cell.Add(new Paragraph("PO #: " + code));
            cell.Add(code128Image);
            table.AddCell(cell);

            doc.Add(table);

            doc.Close();
        }
Exemplo n.º 4
0
        public MemoryStream CreatePdf(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            _logger.LogInformation("Creating barcode for '{Text}'", text);

            var properties = new WriterProperties();

            properties.SetPdfVersion(PdfVersion.PDF_1_4);

            var stream = new MemoryStream();

            using var writer = new PdfWriter(stream, properties);
            var pdfDoc = new PdfDocument(writer);

            PdfFont fontOcrb  = PdfFontFactory.CreateFont("wwwroot/OCRB.otf", PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED);
            Color   cmykBlack = new DeviceCmyk(0, 0, 0, 100);
            var     gState    = new PdfExtGState().SetFillOverPrintFlag(true).SetStrokeOverPrintFlag(true).SetOverprintMode(1);

            var code128 = new Barcode128(pdfDoc);

            code128.SetBaseline(7.67f);
            code128.SetSize(9f);
            code128.SetFont(fontOcrb);
            code128.SetX(0.72f);
            code128.SetBarHeight(14.17f);
            code128.SetCode(text);
            code128.SetCodeType(Barcode128.CODE128);

            var xObject = code128.CreateFormXObject(cmykBlack, cmykBlack, pdfDoc);

            pdfDoc.AddNewPage(new iText.Kernel.Geom.PageSize(xObject.GetWidth(), xObject.GetHeight()));
            PdfCanvas canvas = new PdfCanvas(pdfDoc.GetFirstPage());

            canvas.SaveState();
            canvas.SetExtGState(gState);
            canvas.AddXObjectAt(xObject, 0f, 0f);
            canvas.RestoreState();

            pdfDoc.Close();

            return(stream);
        }
Exemplo n.º 5
0
        private void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc, new PageSize(290, 112));

            doc.SetMargins(5, 5, 5, 5);

            Table table = new Table(new float[] { 160, 120 });

            // first row
            Cell cell = new Cell(1, 2).Add(new Paragraph("Some text here"));

            cell.SetHeight(30);
            cell.SetBorder(Border.NO_BORDER);
            table.AddCell(cell);

            // second row
            cell = new Cell().Add(new Paragraph("Some more text").SetFontSize(10));
            cell.SetHeight(30);
            cell.SetVerticalAlignment(VerticalAlignment.MIDDLE);
            cell.SetBorder(Border.NO_BORDER);
            table.AddCell(cell);

            Barcode128 code128 = new Barcode128(pdfDoc);

            code128.SetCode("14785236987541");
            code128.SetCodeType(Barcode128.CODE128);

            Image code128Image = new Image(code128.CreateFormXObject(pdfDoc));

            cell = new Cell().Add(code128Image.SetAutoScale(true));
            cell.SetBorder(Border.NO_BORDER);
            cell.SetHeight(30);
            table.AddCell(cell);

            // third row
            table.AddCell(cell.Clone(true));
            cell = new Cell().Add(new Paragraph("and something else here").SetFontSize(10));
            cell.SetBorder(Border.NO_BORDER);
            cell.SetTextAlignment(TextAlignment.RIGHT);
            table.AddCell(cell);

            doc.Add(table);

            doc.Close();
        }
Exemplo n.º 6
0
        public MemoryStream GetPage()
        {
            MemoryStream pdfStream = new MemoryStream();
            PdfWriter    writer    = new PdfWriter(pdfStream);

            writer.SetCloseStream(false);
            var template = new PdfDocument(new PdfReader(TemplatePdf), writer);
            var form     = PdfAcroForm.GetAcroForm(template, false);
            var fields   = form.GetFormFields();

            fields["head"].SetValue(StringReplace(FormSettings.Head));
            fields["title"].SetValue(StringReplace(FormSettings.Title));
            fields["name"].SetValue(Applicant.Name);
            fields["sid"].SetValue(Applicant.Sid);
            fields["college"].SetValue(Applicant.College);
            fields["district"].SetValue(Applicant.District);
            fields["tel"].SetValue(Applicant.Tel);
            fields["mail"].SetValue(Applicant.Mail);
            fields["apply"].SetValue(string.Join('\t', Applicant.ApplyingArray));
            fields["resume"].SetValue(Applicant.Resume);
            fields["note"].SetValue(StringReplace(FormSettings.Note));

            if (FormSettings.IsAddBarcode)
            {
                Barcode128 barcode = new Barcode128(template);
                barcode.SetCode(Applicant.Sid);
                Image image = new Image(barcode.CreateFormXObject(template));
                image.SetFixedPosition(430, 790);
                Document document = new Document(template);
                document.Add(image);
            }

            form.FlattenFields();
            template.Close();
            pdfStream.Position = 0;
            return(pdfStream);
        }
Exemplo n.º 7
0
        public void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc, new PageSize(340, 842));

            // The default barcode EAN 13 type
            doc.Add(new Paragraph("Barcode EAN.UCC-13"));
            BarcodeEAN codeEAN = new BarcodeEAN(pdfDoc);

            codeEAN.SetCode("4512345678906");
            doc.Add(new Paragraph("default:"));
            codeEAN.FitWidth(250);
            doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc)));
            codeEAN.SetGuardBars(false);
            doc.Add(new Paragraph("without guard bars:"));
            doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc)));
            codeEAN.SetBaseline(-1);
            codeEAN.SetGuardBars(true);
            doc.Add(new Paragraph("text above:"));
            doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc)));
            codeEAN.SetBaseline(codeEAN.GetSize());

            // Barcode EAN UPC A type
            doc.Add(new Paragraph("Barcode UCC-12 (UPC-A)"));
            codeEAN.SetCodeType(BarcodeEAN.UPCA);
            codeEAN.SetCode("785342304749");
            doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc)));

            // Barcode EAN 8 type
            doc.Add(new Paragraph("Barcode EAN.UCC-8"));
            codeEAN.SetCodeType(BarcodeEAN.EAN8);
            codeEAN.SetBarHeight(codeEAN.GetSize() * 1.5f);
            codeEAN.SetCode("34569870");
            codeEAN.FitWidth(250);
            doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc)));

            // Barcode UPC E type
            doc.Add(new Paragraph("Barcode UPC-E"));
            codeEAN.SetCodeType(BarcodeEAN.UPCE);
            codeEAN.SetCode("03456781");
            codeEAN.FitWidth(250);
            doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc)));
            codeEAN.SetBarHeight(codeEAN.GetSize() * 3);

            // Barcode EANSUPP type
            doc.Add(new Paragraph("Bookland - BarcodeEANSUPP"));
            doc.Add(new Paragraph("ISBN 0-321-30474-8"));
            codeEAN = new BarcodeEAN(pdfDoc);
            codeEAN.SetCodeType(BarcodeEAN.EAN13);
            codeEAN.SetCode("9781935182610");
            BarcodeEAN codeSUPP = new BarcodeEAN(pdfDoc);

            codeSUPP.SetCodeType(BarcodeEAN.SUPP5);
            codeSUPP.SetCode("55999");
            codeSUPP.SetBaseline(-2);
            BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);

            doc.Add(new Image(eanSupp.CreateFormXObject(null, ColorConstants.BLUE, pdfDoc)));

            // Barcode CODE 128 type
            doc.Add(new Paragraph("Barcode 128"));
            Barcode128 code128 = new Barcode128(pdfDoc);

            code128.SetCode("0123456789 hello");
            code128.FitWidth(250);
            doc.Add(new Image(code128.CreateFormXObject(pdfDoc))
                    .SetRotationAngle(Math.PI / 2)
                    .SetMargins(10, 10, 10, 10));
            code128.SetCode("0123456789\uffffMy Raw Barcode (0 - 9)");
            code128.SetCodeType(Barcode128.CODE128_RAW);
            code128.FitWidth(250);
            doc.Add(new Image(code128.CreateFormXObject(pdfDoc)));

            // Data for the barcode
            String        code402 = "24132399420058289";
            String        code90  = "3700000050";
            String        code421 = "422356";
            StringBuilder data    = new StringBuilder(code402);

            data.Append(Barcode128.FNC1);
            data.Append(code90);
            data.Append(Barcode128.FNC1);
            data.Append(code421);

            Barcode128 shipBarCode = new Barcode128(pdfDoc);

            shipBarCode.SetX(0.75f);
            shipBarCode.SetN(1.5f);
            shipBarCode.SetSize(10f);
            shipBarCode.SetTextAlignment(Barcode1D.ALIGN_CENTER);
            shipBarCode.SetBaseline(10f);
            shipBarCode.SetBarHeight(50f);
            shipBarCode.SetCode(data.ToString());
            shipBarCode.FitWidth(250);
            doc.Add(new Image(shipBarCode.CreateFormXObject(ColorConstants.BLACK, ColorConstants.BLUE, pdfDoc)));

            // CODE 128 type barcode, which is composed of 3 blocks with AI 01, 3101 and 10
            Barcode128 uccEan128 = new Barcode128(pdfDoc);

            uccEan128.SetCodeType(Barcode128.CODE128_UCC);
            uccEan128.SetCode("(01)00000090311314(10)ABC123(15)060916");
            uccEan128.FitWidth(250);
            doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.BLACK, pdfDoc)));
            uccEan128.SetCode("0191234567890121310100035510ABC123");
            uccEan128.FitWidth(250);
            doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.RED, pdfDoc)));
            uccEan128.SetCode("(01)28880123456788");
            uccEan128.FitWidth(250);
            doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.BLACK, pdfDoc)));

            // Barcode INTER25 type
            doc.Add(new Paragraph("Barcode Interrevealed 2 of 5"));
            BarcodeInter25 code25 = new BarcodeInter25(pdfDoc);

            code25.SetGenerateChecksum(true);
            code25.SetCode("41-1200076041-001");
            code25.FitWidth(250);
            doc.Add(new Image(code25.CreateFormXObject(pdfDoc)));
            code25.SetCode("411200076041001");
            code25.FitWidth(250);
            doc.Add(new Image(code25.CreateFormXObject(pdfDoc)));
            code25.SetCode("0611012345678");
            code25.SetChecksumText(true);
            code25.FitWidth(250);
            doc.Add(new Image(code25.CreateFormXObject(pdfDoc)));

            // Barcode POSTNET type
            doc.Add(new Paragraph("Barcode Postnet"));
            BarcodePostnet codePost = new BarcodePostnet(pdfDoc);

            doc.Add(new Paragraph("ZIP"));
            codePost.SetCode("01234");
            codePost.FitWidth(250);
            doc.Add(new Image(codePost.CreateFormXObject(pdfDoc)));
            doc.Add(new Paragraph("ZIP+4"));
            codePost.SetCode("012345678");
            codePost.FitWidth(250);
            doc.Add(new Image(codePost.CreateFormXObject(pdfDoc)));
            doc.Add(new Paragraph("ZIP+4 and dp"));
            codePost.SetCode("01234567890");
            codePost.FitWidth(250);
            doc.Add(new Image(codePost.CreateFormXObject(pdfDoc)));

            // Barcode PLANET type
            doc.Add(new Paragraph("Barcode Planet"));
            BarcodePostnet codePlanet = new BarcodePostnet(pdfDoc);

            codePlanet.SetCode("01234567890");
            codePlanet.SetCodeType(BarcodePostnet.TYPE_PLANET);
            codePlanet.FitWidth(250);
            doc.Add(new Image(codePlanet.CreateFormXObject(pdfDoc)));

            // Barcode CODE 39 type
            doc.Add(new Paragraph("Barcode 3 of 9"));
            Barcode39 code39 = new Barcode39(pdfDoc);

            code39.SetCode("ITEXT IN ACTION");
            code39.FitWidth(250);
            doc.Add(new Image(code39.CreateFormXObject(pdfDoc)));

            doc.Add(new Paragraph("Barcode 3 of 9 extended"));
            Barcode39 code39ext = new Barcode39(pdfDoc);

            code39ext.SetCode("iText in Action");
            code39ext.SetStartStopText(false);
            code39ext.SetExtended(true);
            code39ext.FitWidth(250);
            doc.Add(new Image(code39ext.CreateFormXObject(pdfDoc)));

            // Barcode CODABAR type
            doc.Add(new Paragraph("Codabar"));
            BarcodeCodabar codabar = new BarcodeCodabar(pdfDoc);

            codabar.SetCode("A123A");
            codabar.SetStartStopText(true);
            codabar.FitWidth(250);
            doc.Add(new Image(codabar.CreateFormXObject(pdfDoc)));

            doc.Add(new AreaBreak());

            // Barcode PDF417 type
            doc.Add(new Paragraph("Barcode PDF417"));
            BarcodePDF417 pdf417 = new BarcodePDF417();
            String        text   = "Call me Ishmael. Some years ago--never mind how long "
                                   + "precisely --having little or no money in my purse, and nothing "
                                   + "particular to interest me on shore, I thought I would sail about "
                                   + "a little and see the watery part of the world.";

            pdf417.SetCode(text);

            PdfFormXObject xObject = pdf417.CreateFormXObject(pdfDoc);
            Image          img     = new Image(xObject);

            doc.Add(img.SetAutoScale(true));

            doc.Add(new Paragraph("Barcode Datamatrix"));
            BarcodeDataMatrix datamatrix = new BarcodeDataMatrix();

            datamatrix.SetCode(text);
            Image imgDM = new Image(datamatrix.CreateFormXObject(pdfDoc));

            doc.Add(imgDM.ScaleToFit(250, 250));

            // Barcode QRCode type
            doc.Add(new Paragraph("Barcode QRCode"));
            BarcodeQRCode qrcode = new BarcodeQRCode("Moby Dick by Herman Melville");

            img = new Image(qrcode.CreateFormXObject(pdfDoc));
            doc.Add(img.ScaleToFit(250, 250));

            doc.Close();
        }
Exemplo n.º 8
0
        private void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            doc.SetMargins(0f, 0f, 0f, 0f);

            String img_path = "../../resource/image/1.png";
            String FONT     = "../../resource/font/arial.ttf";

            Image image_1 = new Image(ImageDataFactory.Create(img_path));
            Image image_2 = new Image(ImageDataFactory.Create(img_path));

            image_1.ScaleAbsolute(img_size_width, img_size_height);
            image_2.ScaleAbsolute(img_size_width, img_size_height);

            pdfDoc.AddNewPage(new PageSize(paper_width, paper_height));

            image_1.SetFixedPosition(1, offset_x, paper_height - img_size_height);
            doc.Add(image_1);
            image_2.SetFixedPosition(1, offset_x + paper_width - img_size_width, paper_height - img_size_height);
            doc.Add(image_2);

            PdfFont TitleFont = PdfFontFactory.CreateFont(FONT, null, true);

            Paragraph p             = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            Text      text_header_1 = new Text("MONTEREY");

            //PdfFont TitleFont = PdfFontFactory.CreateFont(FontConstants.COURIER);
            text_header_1.SetFont(TitleFont).SetBold().SetItalic().SetFontSize(20);
            p.Add(text_header_1);
            doc.Add(p);

            p = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            Text text_header_2 = new Text("BOTTLE DEPOT");

            text_header_2.SetFont(TitleFont).SetBold().SetItalic().SetFontSize(13);
            p.SetMultipliedLeading(-0.8f);
            p.Add(text_header_2);
            doc.Add(p);

            p = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            Text text_header_3 = new Text("2240 - 68 ST NE");

            text_header_3.SetFont(TitleFont).SetBold().SetFontSize(9);
            p.SetMultipliedLeading(0);
            p.Add(text_header_3);
            doc.Add(p);

            p             = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            text_header_3 = new Text("CALGARY, AB T1Y 0A2");
            text_header_3.SetFont(TitleFont).SetBold().SetFontSize(9);
            p.SetMultipliedLeading(0);
            p.Add(text_header_3);
            doc.Add(p);

            p             = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            text_header_3 = new Text("PH:(403) 590-6665");
            text_header_3.SetFont(TitleFont).SetBold().SetFontSize(9);
            p.SetMultipliedLeading(0);
            p.Add(text_header_3);
            doc.Add(p);

            PdfFont special_Font = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H, true);

            p = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            Text text_header_4 = new Text("* * P A I D - R E P R I N T * *");

            text_header_4.SetFont(special_Font).SetBold().SetFontSize(14);
            p.SetMultipliedLeading(2f);
            p.Add(text_header_4);
            doc.Add(p);


            String     code    = "741235";
            Barcode128 code128 = new Barcode128(pdfDoc);

            code128.SetFont(null);
            code128.SetCode(code);
            code128.SetCodeType(Barcode128.CODE128);
            Image     code128Image = new Image(code128.CreateFormXObject(pdfDoc)).ScaleAbsolute(paper_width * 0.4f, paper_width * 0.15f);
            Paragraph paragraph    = new Paragraph(code).SetTextAlignment(TextAlignment.CENTER);

            code128Image.SetMarginLeft(paper_width * 0.29f);
            Cell cell = new Cell();

            cell.Add(code128Image);
            cell.Add(paragraph);
            doc.Add(cell);

            string[] org_lines = System.IO.File.ReadAllLines("../../resource/input_table.csv");
            Table    table     = new Table(UnitValue.CreatePercentArray(new float[] { 3, 3, 3 })).UseAllAvailableWidth();

            table.SetTextAlignment(TextAlignment.CENTER);
            table.SetMargin(15f);
            for (int i = 0; i < org_lines.Length - 1; i++)
            {
                string[] temp = org_lines[i].Split(',');
                for (int j = 0; j < 3; j++)
                {
                    table.AddCell(temp[j]);
                }
            }
            doc.Add(table);

            p = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            string[] total_temp = org_lines[org_lines.Length - 1].Split(',');
            text_header_3 = new Text(total_temp[1] + "  " + total_temp[2]);
            text_header_3.SetFont(TitleFont).SetBold().SetFontSize(15);
            p.SetMultipliedLeading(0);
            p.Add(text_header_3);
            doc.Add(p);


            p = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            DateTime localDate = DateTime.Now;
            string   format    = "MMM d, yyyy\t\t\t\t\t";

            text_header_3 = new Text(localDate.ToString(format) + localDate.ToString("t"));
            text_header_3.SetFont(TitleFont).SetFontSize(12);
            p.SetMultipliedLeading(2);
            p.Add(text_header_3);
            doc.Add(p);

            p             = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            text_header_3 = new Text("You were served at MONTEREY-6 by Subash.");
            text_header_3.SetFont(TitleFont).SetFontSize(12);
            p.SetMultipliedLeading(2);
            p.Add(text_header_3);
            doc.Add(p);

            p             = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
            text_header_3 = new Text("Thank you for your patronage.");
            text_header_3.SetFont(TitleFont).SetBold().SetFontSize(12);
            p.SetMultipliedLeading(1);
            p.Add(text_header_3);
            doc.Add(p);

            doc.Close();
            MessageBox.Show("File saved to C:\\Neosmart Solutions Inc\\PDFs\\result.pdf correctly!");
        }
Exemplo n.º 9
0
        public byte[] TasksByProjectAsPdf(SqlContext context, int projectId, User currentUser, string taskGroupScope)
        {
            var buffer       = new byte[0];
            var stream       = new MemoryStream();
            var timeZone     = DateTimeZoneProviders.Tzdb.GetZoneOrNull(currentUser.TimeZone);
            var nowInstant   = SystemClock.Instance.GetCurrentInstant();
            var nowLocal     = nowInstant.InZone(timeZone);
            var nowDateTime  = nowLocal.LocalDateTime.ToDateTimeUnspecified();
            var organization = context.Organizations.Find(currentUser.OrganizationId);

            var project = context.Jobs
                          .Include("Customer")
                          .Where(p => p.Id == projectId)
                          .FirstOrDefault();

            var writer   = new PdfWriter(stream);
            var pdf      = new PdfDocument(writer);
            var document = new Document(pdf);

            // Define document properties.
            var info = pdf.GetDocumentInfo();

            info.SetTitle($"Barcodes for Project {project.Number} - {project.Name}");
            info.SetAuthor(currentUser.Name);
            info.SetCreator("BRIZBEE");

            // Page formatting.
            document.SetMargins(30, 30, 30, 30);

            // Set page header and footer.
            pdf.AddEventHandler(PdfDocumentEvent.END_PAGE, new MyEventHandler(organization.Name));

            var generatedParagraph = new Paragraph($"GENERATED {nowDateTime.ToString("ddd, MMM d, yyyy h:mm:ss tt").ToUpper()}");

            generatedParagraph.SetFont(fontP);
            generatedParagraph.SetFontSize(8);
            generatedParagraph.SetHorizontalAlignment(HorizontalAlignment.RIGHT);
            generatedParagraph.SetTextAlignment(TextAlignment.RIGHT);
            generatedParagraph.SetPaddingBottom(5);
            document.Add(generatedParagraph);

            var table = new Table(UnitValue.CreatePercentArray(new float[] { 50, 50 }))
                        .UseAllAvailableWidth();

            // Project details are at the top of the table.
            var detailsCell = new Cell(0, 2);

            detailsCell.SetPadding(20);

            var customerParagraph = new Paragraph();

            customerParagraph.SetFont(fontH1);
            customerParagraph.SetPaddingBottom(0);

            if (organization.ShowCustomerNumber)
            {
                customerParagraph.Add($"CUSTOMER: {project.Customer.Number} - {project.Customer.Name.ToUpper()}");
            }
            else
            {
                customerParagraph.Add($"CUSTOMER: {project.Customer.Name.ToUpper()}");
            }

            var projectParagraph = new Paragraph();

            projectParagraph.SetFont(fontH1);
            projectParagraph.SetPaddingBottom(10);

            if (organization.ShowProjectNumber)
            {
                projectParagraph.Add($"PROJECT: {project.Number} - {project.Name.ToUpper()}");
            }
            else
            {
                projectParagraph.Add($"PROJECT: {project.Name.ToUpper()}");
            }

            var descriptionParagraph = new Paragraph($"DESCRIPTION: {project.Description}");

            descriptionParagraph.SetFont(fontP);
            descriptionParagraph.SetFontSize(9);

            detailsCell.Add(customerParagraph);
            detailsCell.Add(projectParagraph);
            detailsCell.Add(descriptionParagraph);
            table.AddCell(detailsCell);

            var tasks = new List <Brizbee.Core.Models.Task>(0);

            if (string.IsNullOrEmpty(taskGroupScope) || taskGroupScope == "Unspecified")
            {
                tasks = context.Tasks
                        .Where(t => t.JobId == projectId)
                        .ToList();
            }
            else
            {
                tasks = context.Tasks
                        .Where(t => t.JobId == projectId)
                        .Where(t => t.Group == taskGroupScope)
                        .ToList();
            }

            foreach (var task in tasks)
            {
                try
                {
                    // Generate a barcode.
                    Barcode128 barCode = new Barcode128(pdf);
                    barCode.SetTextAlignment(Barcode128.ALIGN_CENTER);
                    barCode.SetCode(task.Number);
                    barCode.SetStartStopText(false);
                    barCode.SetCodeType(Barcode128.CODE128);
                    barCode.SetExtended(true);
                    barCode.SetAltText("");
                    barCode.SetBarHeight(50);

                    var barCodeCell = new Cell();
                    barCodeCell.SetPadding(20);
                    barCodeCell.SetHorizontalAlignment(HorizontalAlignment.CENTER);

                    var barCodeParagraph = new Paragraph();
                    barCodeParagraph.SetTextAlignment(TextAlignment.CENTER);
                    barCodeParagraph.Add(new Image(barCode.CreateFormXObject(pdf)));

                    barCodeCell.Add(barCodeParagraph);

                    var subtitleParagraph = new Paragraph();
                    subtitleParagraph.SetFont(fontSubtitle);
                    subtitleParagraph.SetTextAlignment(TextAlignment.CENTER);
                    subtitleParagraph.Add($"{task.Number} - {task.Name.ToUpper()}");

                    barCodeCell.Add(subtitleParagraph);

                    table.AddCell(barCodeCell);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }

            if (tasks.Count % 2 != 0)
            {
                // Add a blank cell to balance the columns.
                var blankCell = new Cell();
                table.AddCell(blankCell);
            }

            document.Add(table);

            for (int i = 0; i <= pdf.GetNumberOfPages(); i++)
            {
            }

            document.Close();

            buffer = stream.ToArray();

            return(buffer);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            SQLiteConnection connection = new SQLiteConnection();

            SQLiteConnection.CreateFile("Data.sqlite");
            string script = File.ReadAllText(System.IO.Path.Combine(AppContext.BaseDirectory, "Database1.sql"));

            connection = new SQLiteConnection(new SQLiteConnectionStringBuilder {
                DataSource = "Data.sqlite"
            }.ToString());
            connection.Open();
            var createDB = connection.CreateCommand();

            createDB.CommandText = script;
            createDB.ExecuteNonQuery();
            connection.Close();
            connection.Open();
            var insertCommand = connection.CreateCommand();

            insertCommand.CommandText = "INSERT INTO Books (Number, Title, Publisher, Version, Year, Medium, Place, DayBought, Pages, Price) " +
                                        "VALUES (@Number,@Title,@Publisher,@Version,@Year,@Medium,@Place,@Date,@Pages,@Price)";
            insertCommand.Parameters.AddWithValue("Number", 123);
            insertCommand.Parameters.AddWithValue("Title", "qwerqwr'");
            insertCommand.Parameters.AddWithValue("Publisher", "pub");
            insertCommand.Parameters.AddWithValue("Version", 1);
            insertCommand.Parameters.AddWithValue("Year", 2010);
            insertCommand.Parameters.AddWithValue("Medium", "med");
            insertCommand.Parameters.AddWithValue("Place", "bla");
            insertCommand.Parameters.AddWithValue("Date", "12122010");
            insertCommand.Parameters.AddWithValue("Pages", 15);
            insertCommand.Parameters.AddWithValue("Price", 15.2);
            insertCommand.ExecuteNonQuery();
            connection.Close();


            //using (PdfWriter pdfWriter = new PdfWriter(exportFile))
            //{
            //    using (iText.Kernel.Pdf.PdfDocument pdf = new iText.Kernel.Pdf.PdfDocument(pdfWriter))
            //    {
            //        Rectangle envelope = new Rectangle(3016, 1327);
            //        PageSize ps = new PageSize(envelope);
            //        //ps.ApplyMargins(0, 0, 0, 0, true);
            //        Document document = new Document(pdf, ps);
            //        document.SetMargins(0, 0, 0, 0);
            //        Paragraph text = new Paragraph("Signature").SetTextAlignment(TextAlignment.CENTER).SetFontSize(200);
            //        Paragraph num = new Paragraph("011120").SetTextAlignment(TextAlignment.CENTER).SetFontSize(200);
            //        Barcode128 barcode128 = new Barcode128(pdf);
            //        barcode128.SetCodeType(Barcode128.CODE_C);
            //        barcode128.SetCode("011120");
            //        barcode128.FitWidth(2800);
            //        barcode128.SetBarHeight(700);
            //        barcode128.SetAltText("");

            //        Image barcodeImage = new Image(barcode128.CreateFormXObject(pdf));
            //        barcodeImage.SetHorizontalAlignment(HorizontalAlignment.CENTER);
            //        document.Add(text);
            //        document.Add(barcodeImage);
            //        document.Add(num);
            //    }
            //}
            //Spire.Pdf.PdfDocument document1 = new Spire.Pdf.PdfDocument();
            //document1.LoadFromFile(exportFile);
            //System.Drawing.Image img = document1.SaveAsImage(0);
            //img.Save(exportImage);
            //document1.SaveToFile(System.IO.Path.Combine(exportFolder, "bc.svg"), FileFormat.SVG);

            //Process proc = new Process();
            //proc.StartInfo.FileName = exportImage;
            //proc.StartInfo.UseShellExecute = true;
            //proc.Start();
            //Process.Start("explorer.exe", "/select, " + exportImage);

            using (PdfWriter writer = new PdfWriter(exportFile))
            {
                using (iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(writer))
                {
                    float cellMainWidth  = 176.5f;
                    float cellMainHeight = 80f;
                    float cellSpaceWidth = 3.2f;
                    pdfDocument.SetDefaultPageSize(PageSize.A4);
                    Document document = new Document(pdfDocument);
                    document.SetMargins(1.51f * 28.33f, 20f, 1.31f * 28.33f, 20f);
                    Barcode128 barcode = new Barcode128(pdfDocument);
                    barcode.SetCodeType(Barcode128.CODE_C);
                    barcode.SetCode("012345");
                    barcode.SetSize(14);
                    barcode.SetBaseline(15);
                    barcode.SetBarHeight(35f);
                    barcode.FitWidth(160f);
                    Image barcodeImage = new Image(barcode.CreateFormXObject(pdfDocument));
                    barcodeImage.SetHorizontalAlignment(HorizontalAlignment.CENTER);
                    //barcodeImage.Scale(2.5f, 2f);
                    Paragraph text           = new Paragraph("TEST - TEST - TEST").SetTextAlignment(TextAlignment.CENTER).SetFontSize(14);
                    Paragraph num            = new Paragraph("012345").SetTextAlignment(TextAlignment.CENTER).SetFontSize(14);
                    Paragraph barcodeCombine = new Paragraph().Add(text).Add(barcodeImage);
                    Table     table          = new Table(5);
                    int       col            = 3;
                    int       row            = 8;
                    for (int i = 1; i <= 9; i++)
                    {
                        for (int j = 1; j <= 3; j++)
                        {
                            Cell cellMain = new Cell().SetBorder(Border.NO_BORDER);
                            cellMain.SetVerticalAlignment(VerticalAlignment.MIDDLE);
                            cellMain.SetHeight(cellMainHeight);
                            cellMain.SetWidth(cellMainWidth);
                            if (i == row && j == col)
                            {
                                cellMain.Add(text).Add(barcodeImage);
                            }
                            table.AddCell(cellMain);
                            if (j % 3 != 0)
                            {
                                Cell cellSpace = new Cell().SetBorder(Border.NO_BORDER);
                                cellSpace.SetHeight(cellMainHeight);
                                cellSpace.SetWidth(cellSpaceWidth);
                                cellSpace.SetMargin(0);
                                table.AddCell(cellSpace);
                            }
                        }
                    }


                    //cellMain.Add(num);

                    //table.AddCell(cellMain);

                    //cellMain = new Cell();
                    //cellMain.SetVerticalAlignment(VerticalAlignment.MIDDLE);
                    //cellMain.SetHeight(cellMainHeight);
                    //cellMain.SetWidth(cellMainWidth);
                    //table.AddCell(cellMain);
                    //cellSpace = new Cell();
                    //cellSpace.SetHeight(cellMainHeight);
                    //cellSpace.SetWidth(cellSpaceWidth);
                    //table.AddCell(cellSpace);
                    //cellMain = new Cell();
                    //cellMain.SetVerticalAlignment(VerticalAlignment.MIDDLE);
                    //cellMain.SetHeight(cellMainHeight);
                    //cellMain.SetWidth(cellMainWidth);
                    //table.AddCell(cellMain);
                    //cellMain = new Cell();
                    //cellMain.SetVerticalAlignment(VerticalAlignment.MIDDLE);
                    //cellMain.SetHeight(cellMainHeight);
                    //cellMain.SetWidth(cellMainWidth);
                    //table.AddCell(cellMain);
                    document.Add(table);
                }
            }
            Process proc = new Process();

            proc.StartInfo.FileName        = exportFile;
            proc.StartInfo.UseShellExecute = true;
            proc.EnableRaisingEvents       = true;
            proc.Start();
            proc.Exited += Proc_Exited;

            //Spire.Pdf.PdfDocument document1 = new Spire.Pdf.PdfDocument();
            //document1.LoadFromFile(exportFile);
            //System.Drawing.Image img = document1.SaveAsImage(0, 300, 300);
            //img.Save(exportImage);
        }
 public bool ProcessContent(string content, ProcessorContext context)
 {
     barcode.SetCode(_content);
     return(true);
 }