Ejemplo n.º 1
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Fonts.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;

                PdfFont systemFont = pdf.AddFont("Arial", false, true, false, true);
                canvas.Font = systemFont;
                canvas.DrawString(10, 50, "Hello, world!");

                PdfFont builtInFont = pdf.AddFont(PdfBuiltInFont.TimesRoman);
                canvas.Font = builtInFont;
                canvas.DrawString(10, 70, "Hello, world!");

                PdfFont fontFromFile = pdf.AddFontFromFile(@"..\Sample data\HolidayPi_BT.ttf");
                canvas.Font = fontFromFile;
                canvas.DrawString(10, 90, "Hello, world!");

                // Remove unused glyphs from TrueType fonts to optimize size of result PDF file.
                systemFont.RemoveUnusedGlyphs();
                fontFromFile.RemoveUnusedGlyphs();

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Fonts.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;

                PdfFont systemFont = pdf.AddFont("Arial", FontStyle.Italic | FontStyle.Strikeout);
                canvas.Font = systemFont;
                canvas.DrawString(10, 50, "Hello, world!");

                PdfFont builtInFont = pdf.AddFont(PdfBuiltInFont.TimesRoman);
                canvas.Font = builtInFont;
                canvas.DrawString(10, 70, "Hello, world!");

                PdfFont fontFromFile = pdf.AddFontFromFile("Sample data/HolidayPi_BT.ttf");
                canvas.Font = fontFromFile;
                canvas.DrawString(10, 90, "Hello, world!");

                // Remove unused glyphs from TrueType fonts to optimize size of result PDF file.
                systemFont.RemoveUnusedGlyphs();
                fontFromFile.RemoveUnusedGlyphs();

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;
                canvas.FontSize = 12;

                canvas.Font = pdf.AddFont(PdfBuiltInFont.CourierBold);
                canvas.DrawString(10, 50, "Chinese(traditional): ");
                canvas.DrawString(10, 70, "Russian: ");
                canvas.DrawString(10, 90, "Portugal: ");

                canvas.Font = pdf.AddFont("NSimSun");
                canvas.DrawString(180, 50, "世界您好");
                canvas.Font.RemoveUnusedGlyphs();

                canvas.Font = pdf.AddFont("Times New Roman");
                canvas.DrawString(180, 70, "Привет, мир");
                canvas.DrawString(180, 90, "Olá mundo");
                canvas.Font.RemoveUnusedGlyphs();

                pdf.Save("Internationalization.pdf");
            }

            Process.Start("Internationalization.pdf");
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            const string PathToFile = "HeaderAndFooter.pdf";

            using (var pdf = new PdfDocument(@"Sample Data/BRAILLE CODES WITH TRANSLATION.pdf"))
            {
                PdfFont font = pdf.AddFont(PdfBuiltInFont.Helvetica);

                for (int i = 0; i < pdf.PageCount; ++i)
                {
                    PdfPage page = pdf.Pages[i];
                    drawHeader(page, font);
                    drawFooter(i, page, font);
                }

                pdf.Save(PathToFile);
            }

            Process.Start(PathToFile);
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "DrawTextFromBaseline.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;
                canvas.FontSize = 30;
                canvas.Font     = pdf.AddFont(PdfBuiltInFont.TimesItalic);

                // draw straight line across the page
                const double baselinePosition = 100;
                canvas.CurrentPosition = new PdfPoint(0, baselinePosition);
                canvas.DrawLineTo(new PdfPoint(pdf.Pages[0].Width, baselinePosition));

                // calculate distance from the baseline to the top of the font bounding box
                double distanceToBaseLine = getDistanceToBaseline(canvas.Font, canvas.FontSize);

                // draw text so that baseline of the text placed exactly over the straight line
                canvas.DrawString(10, baselinePosition - distanceToBaseLine, "gyQW");

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "ErrorHandling.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage page = pdf.Pages[0];

                try
                {
                    // tries to draw Russian string with built-in Helvetica font which doesn't
                    // define glyphs for Russian characters. So, we expect that a PdfException will be thrown.
                    page.Canvas.DrawString(10, 50, "Привет, мир!");
                }
                catch (CannotShowTextException ex)
                {
                    page.Canvas.Font = pdf.AddFont("Arial");
                    page.Canvas.DrawString(10, 50, "Expected exception occurred:");
                    page.Canvas.DrawString(10, 65, ex.Message);
                }

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
        public ActionResult Create(FullcalendarModel fullcalendarModel)
        {
            if (ModelState.IsValid)
            {
                // create a new pdf document
                PdfDocument doc = new PdfDocument();

                // add a new page to the document
                PdfPage page = doc.AddPage();

                // create a new pdf font
                PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
                font.Size = 15;

                // create a new text element and add it to the page
                PdfTextElement text = new PdfTextElement(50, 50, fullcalendarModel.title.ToString() + "\n" + fullcalendarModel.address.ToString() + "\n" + fullcalendarModel.description.ToString() + "\n" + fullcalendarModel.date.ToString() + "\n" + "Signature:_________________________________" + "\n" + "Total:______________________" + "\n" + "Tax:______________________" + "\n" + "Subtotal:______________________", font);
                page.Add(text);
                doc.Save("C:/Users/Charles/Documents/Visual Studio 2015/Projects/CiezkiCapStone/CCiezkiCapstone/CCiezkiCapstone/Invoices/" + fullcalendarModel.title.ToString() + ".pdf");
                // save pdf document
                //doc.Save("~/Sample.pdf");

                // close pdf document
                doc.Close();

                db.FullcalendarModel.Add(fullcalendarModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fullcalendarModel));
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;
                canvas.FontSize = 12;

                canvas.Font = pdf.AddFont(PdfBuiltInFont.CourierBold);
                canvas.DrawString(10, 50, "Chinese(traditional): ");
                canvas.DrawString(10, 70, "Russian: ");
                canvas.DrawString(10, 90, "Portugal: ");
                canvas.DrawString(10, 110, "Bidirectional: ");

                canvas.Font = pdf.AddFont("NSimSun");
                canvas.DrawString(180, 50, "世界您好");
                canvas.Font.RemoveUnusedGlyphs();

                canvas.Font = pdf.AddFont("Times New Roman");
                canvas.DrawString(180, 70, "Привет, мир");
                canvas.DrawString(180, 90, "Olá mundo");

                var options = new PdfStringDrawingOptions {
                    ReadingDirection = PdfReadingDirection.Rtl
                };
                canvas.DrawString(180, 110, "bidi בינלאומי", options);

                canvas.Font.RemoveUnusedGlyphs();

                pdf.Save("Internationalization.pdf");
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Ejemplo n.º 9
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string outputFileName = "SignSignatureFieldUsingCustomStyle.pdf";

            using (PdfDocument pdf = new PdfDocument(@"..\Sample Data\SignatureFields.pdf"))
            {
                // IMPORTANT:
                // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password.
                // Without the change the sample will not work.

                PdfSignatureField field = pdf.GetControl("Control") as PdfSignatureField;
                field.BackgroundColor = new PdfGrayColor(80);

                PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password")
                {
                    DigestAlgorithm = PdfDigestAlgorithm.Sha256,
                    Format          = PdfSignatureFormat.Pkcs7Detached,
                    Field           = field,
                    Reason          = "Testing field styles",
                    Location        = "My workplace",
                    ContactInfo     = "*****@*****.**"
                };

                PdfSignatureAppearanceOptions appearance = options.Appearance;
                appearance.IncludeDate = false;
                appearance.IncludeDistinguishedName = false;

                appearance.Image         = pdf.AddImage(@"..\Sample Data\ammerland.jpg");
                appearance.Font          = pdf.AddFont(PdfBuiltInFont.Courier);
                appearance.FontSize      = 0; // calculate font size automatically
                appearance.FontColor     = new PdfRgbColor(0, 0, 255);
                appearance.TextAlignment = PdfSignatureTextAlignment.Right;

                appearance.NameLabel     = "Digital signiert von";
                appearance.ReasonLabel   = "Grund:";
                appearance.LocationLabel = "Ort:";

                pdf.SignAndSave(options, outputFileName);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Ejemplo n.º 10
0
        private void DoAddStamp(PdfDocument pdfDocument, ConversionProfile profile, string fontPath)
        {
            var font  = PdfFontFactory.CreateFont(fontPath, PdfEncodings.IDENTITY_H, true);
            var color = new DeviceRgb(profile.Stamping.Color);

            pdfDocument.AddFont(font);

            var numberOfPages = pdfDocument.GetNumberOfPages();

            for (int i = 1; i <= numberOfPages; i++)
            {
                var pdfImportedPage = pdfDocument.GetPage(i);

                var   pageSize      = pdfImportedPage.GetPageSize();
                float rotationAngle = (float)(Math.Atan2(pageSize.GetHeight(),
                                                         pageSize.GetWidth()));

                var pdfPage = pdfDocument.GetPage(i);
                var layer   = pdfPage.NewContentStreamAfter();

                var canvas = new PdfCanvas(layer, pdfPage.GetResources(), pdfDocument);
                canvas.SaveState();
                var canvasLayer = new Canvas(canvas, pdfDocument, pdfPage.GetPageSize());

                if (profile.Stamping.FontAsOutline)
                {
                    canvasLayer.SetStrokeWidth(profile.Stamping.FontOutlineWidth);
                    canvasLayer.SetStrokeColor(color);
                    canvasLayer.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
                }

                canvasLayer.SetFontColor(color);
                canvasLayer.SetFont(font);
                canvasLayer.SetFontSize(profile.Stamping.FontSize);

                canvasLayer.ShowTextAligned(
                    profile.Stamping.StampText,
                    pdfPage.GetPageSize().GetWidth() / 2,
                    pdfPage.GetPageSize().GetHeight() / 2,
                    TextAlignment.CENTER,
                    VerticalAlignment.MIDDLE,
                    rotationAngle);

                canvas.RestoreState();
            }
        }
Ejemplo n.º 11
0
        private PdfDocument CreatePdfWithImageFile(string fullName, string name)
        {
            PdfDocument doc  = new PdfDocument();
            PdfPage     page = doc.AddPage();
            PdfFont     font = doc.AddFont(PdfStandardFont.Helvetica);

            font.Size = 12;

            PdfRenderingResult result;

            PdfTextElement text = new PdfTextElement(0, 0, name, font);

            result = page.Add(text);
            PdfImageElement img = new PdfImageElement(0, result.PdfPageLastRectangle.Bottom + 50, fullName);

            result = page.Add(img);

            return(doc);
        }
        public ActionResult SubmitAction(FormCollection collection)
        {
            // the test file
            string filePdf = Server.MapPath("~/files/selectpdf.pdf");
            string imgFile = Server.MapPath("~/files/logo.png");
            // resize the content
            PdfResizeManager resizer = new PdfResizeManager();

            resizer.Load(filePdf);
            // add extra top and bottom margins
            resizer.PageMargins = new PdfMargins(0, 0, 90, 40);
            // add the header and footer to the existing (now resized pdf document)
            PdfDocument doc = resizer.GetDocument();
            // header template (90 points in height) with image element
            PdfTemplate     header = doc.AddTemplate(doc.Pages[0].ClientRectangle.Width, 90);
            PdfImageElement img1   = new PdfImageElement(10, 10, imgFile);

            header.Add(img1);
            // footer template (40 points in height) with text element
            PdfTemplate footer = doc.AddTemplate(new RectangleF(0,
                                                                doc.Pages[0].ClientRectangle.Height - 40,
                                                                doc.Pages[0].ClientRectangle.Width, 40));
            // create a new pdf font
            PdfFont font2 = doc.AddFont(PdfStandardFont.Helvetica);

            font2.Size = 12;
            PdfTextElement text1 = new PdfTextElement(10, 10,
                                                      "Generated by SelectPdf. Page number {page_number} of {total_pages}.",
                                                      font2);

            text1.ForeColor = System.Drawing.Color.Blue;
            footer.Add(text1);
            // save pdf document
            byte[] pdf = doc.Save();
            // close pdf document
            resizer.Close();
            // return resulted pdf document
            FileResult fileResult = new FileContentResult(pdf, "application/pdf");

            fileResult.FileDownloadName = "Document.pdf";
            return(fileResult);
        }
Ejemplo n.º 13
0
        public virtual void EgsTest1()
        {
            String      destinationDocument = destinationFolder + "egsTest1.pdf";
            PdfDocument document            = new PdfDocument(new PdfWriter(destinationDocument));
            //Create page and canvas
            PdfPage   page   = document.AddNewPage();
            PdfCanvas canvas = new PdfCanvas(page);
            //Create ExtGState and fill it with line width and font
            PdfExtGState egs = new PdfExtGState();

            egs.GetPdfObject().Put(PdfName.LW, new PdfNumber(5));
            PdfArray font    = new PdfArray();
            PdfFont  pdfFont = PdfFontFactory.CreateFont(StandardFonts.COURIER);

            document.AddFont(pdfFont);
            font.Add(pdfFont.GetPdfObject());
            font.Add(new PdfNumber(24));
            egs.GetPdfObject().Put(PdfName.Font, font);
            //Write ExtGState
            canvas.SetExtGState(egs);
            //Write text to check that font from ExtGState is applied
            canvas.BeginText();
            canvas.MoveText(50, 600);
            canvas.ShowText("Courier, 24pt");
            canvas.EndText();
            //Draw line to check if ine width is applied
            canvas.MoveTo(50, 500);
            canvas.LineTo(300, 500);
            canvas.Stroke();
            //Write text again to check that font from page resources and font from ExtGState is the same.
            canvas.BeginText();
            canvas.SetFontAndSize(pdfFont, 36);
            canvas.MoveText(50, 400);
            canvas.ShowText("Courier, 36pt");
            canvas.EndText();
            canvas.Release();
            page.Flush();
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationDocument, sourceFolder + "cmp_egsTest1.pdf"
                                                                             , destinationFolder, "diff_"));
        }
Ejemplo n.º 14
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "OpenDocument.pdf";

            using (PdfDocument pdf = new PdfDocument(@"..\Sample data\jfif3.pdf"))
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;
                canvas.Font     = pdf.AddFont(PdfBuiltInFont.Helvetica);
                canvas.FontSize = 20;
                canvas.DrawString(10, 80, "This text was added by Docotic.Pdf");

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Ejemplo n.º 15
0
        private static void buildTestDocument(PdfDocument pdf)
        {
            PdfFont times     = pdf.AddFont(PdfBuiltInFont.HelveticaBoldOblique);
            double  pageWidth = pdf.GetPage(0).Width;

            PdfPage page = pdf.GetPage(0);

            for (int i = 0; i < 10; i++)
            {
                if (i > 0)
                {
                    page = pdf.AddPage();
                }

                page.Canvas.Font     = times;
                page.Canvas.FontSize = 16;

                string titleFormat = string.Format("Page {0}", i + 1);

                double textWidth = page.Canvas.GetTextWidth(titleFormat);
                page.Canvas.DrawString(new PdfPoint((pageWidth - textWidth) / 2, 100), titleFormat);
            }
        }
Ejemplo n.º 16
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "OpenDocument.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                pdf.Open("Sample data/jfif3.pdf");

                PdfCanvas canvas = pdf.Pages[0].Canvas;
                canvas.Font     = pdf.AddFont(PdfBuiltInFont.Helvetica);
                canvas.FontSize = 20;
                canvas.DrawString(10, 80, "This text added by Docotic.Pdf Sample Browser");

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
Ejemplo n.º 17
0
        private static void BuildTestOutline(PdfDocument pdf)
        {
            PdfOutlineItem root       = pdf.OutlineRoot;
            PdfOutlineItem lastParent = null;

            PdfFont times     = pdf.AddFont(PdfBuiltInFont.TimesItalic);
            double  pageWidth = pdf.GetPage(0).Width;

            PdfPage page = pdf.GetPage(pdf.PageCount - 1);

            for (int i = 1; i < 30; i++)
            {
                if (i > 1)
                {
                    page = pdf.AddPage();
                }

                page.Canvas.Font     = times;
                page.Canvas.FontSize = 16;

                string titleFormat = string.Format("Page {0}", i);

                double textWidth = page.Canvas.GetTextWidth(titleFormat);
                page.Canvas.DrawString(new PdfPoint((pageWidth - textWidth) / 2, 100), titleFormat);

                PdfGoToAction action = pdf.CreateGoToPageAction(i - 1, 0);

                if (i == 1 || i == 10 || i == 20)
                {
                    lastParent = root.AddChild(titleFormat, action);
                }
                else
                {
                    lastParent.AddChild(titleFormat, action);
                }
            }
        }
Ejemplo n.º 18
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Patterns.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas    = pdf.Pages[0].Canvas;
                PdfFont   helvetica = pdf.AddFont(PdfBuiltInFont.HelveticaBoldOblique, false, false);
                canvas.Font     = helvetica;
                canvas.FontSize = 28;

                drawColoredPattern(pdf);
                drawUncoloredPattern(pdf);

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
Ejemplo n.º 19
0
        public ActionResult Pay(OrderViewModel order)
        {
            // create a new pdf document
            PdfDocument doc = new PdfDocument();

            // add a new page to the document
            PdfPage page = doc.AddPage();

            // create a new pdf font
            PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
            font.Size = 20;

            // create a new text element and add it to the page
            PdfTextElement text = new PdfTextElement(50, 50, "Date: " + order.OrderDate.ToString(), font);
            page.Add(text);
            page.Add(new PdfTextElement(50, 100, "CustomerId:" + order.CustomerId.ToString(), font));

            // save pdf document
            var bytes = doc.Save();

            // close pdf document
            doc.Close();
            return new FileContentResult(bytes, "application/pdf");
        }
Ejemplo n.º 20
0
        private void PDF()
        {
            // create a new pdf document
            PdfDocument doc = new PdfDocument();

            // add a new page to the document
            PdfPage page = doc.AddPage();

            // create a new pdf font
            PdfFont font1 = doc.AddFont(PdfStandardFont.Helvetica);
            PdfFont font2 = doc.AddFont(PdfStandardFont.Helvetica);
            PdfFont font3 = doc.AddFont(PdfStandardFont.Helvetica);

            font1.Size = 20;
            font2.Size = 16;
            font3.Size = 12;

            // create a new text element and add it to the page

            PdfTextElement klant    = new PdfTextElement(50, 50, "Klant: " + txtKlant.Text.ToLower(), font1);
            PdfTextElement code     = new PdfTextElement(320, 50, "Code machine: " + txtMachineCode.Text, font1);
            PdfTextElement ordernr1 = new PdfTextElement(50, 80, "Ordernr: " + txtOrdernr.Text, font1);

            PdfTextElement lengteDoos2  = new PdfTextElement(50, 170, "" + txtLengte.Text, font2);
            PdfTextElement breedteDoos2 = new PdfTextElement(150, 170, "" + txtBreedte.Text, font2);
            PdfTextElement hoogteDoos2  = new PdfTextElement(250, 170, "" + txtHoogte.Text, font2);
            PdfTextElement modelDoos2   = new PdfTextElement(350, 170, "" + txtFefco.Text, font2);
            PdfTextElement aantal       = new PdfTextElement(450, 170, "" + txtTeProduceren.Text, font2);

            PdfTextElement kwaliteit2    = new PdfTextElement(50, 250, "Kwaliteit: " + kwaliteit, font1);
            PdfTextElement plaatformaat1 = new PdfTextElement(50, 290, "Plaatformaat: " + plaatformaat, font1);
            PdfTextElement aantalPlaten  = new PdfTextElement(50, 330, "Aantal platen: " + txtPlatenFabrikant.Text, font1);

            PdfTextElement page1 = new PdfTextElement(50, 130, "Lengte           Breedte          Hoogte           Model            Aantal", font2);

            //extra toegifte flappen
            int            toegifte = toegifteFlappen(kwaliteit1.ToString().ToUpper());
            PdfTextElement page2    = new PdfTextElement(130, 425, (lengtedoos + toegifte) + "         " + (breedtedoos + toegifte) + "     " + (lengtedoos + toegifte) + "         " + (breedtedoos + toegifte), font2);
            PdfTextElement rillen1  = new PdfTextElement(65, 460, "" + txtRillen1.Text, font2);
            PdfTextElement rillen2  = new PdfTextElement(65, 495, "" + txtRillen2.Text, font2);
            PdfTextElement rillen3  = new PdfTextElement(65, 535, "" + txtRillen3.Text, font2);

            PdfTextElement text1 = new PdfTextElement(65, 580, "Aantal paletten: ..........", font2);
            PdfTextElement text2 = new PdfTextElement(65, 610, "Aantal wwp: ..........   Aantal europal: ..........", font2);
            PdfTextElement text3 = new PdfTextElement(65, 640, "Aantal per pallet: ..........", font2);
            PdfTextElement text4 = new PdfTextElement(65, 670, "AANTAL GEPRODUCEERD: ..........", font1);
            PdfTextElement text5 = new PdfTextElement(65, 710, "Extra commentaar: " + txtCommentaar.Text + " " + commentaarproductie, font3);

            System.Drawing.Bitmap bitmap1 = ProspectieFiche.Properties.Resources.doos;
            //string imgFile = Path.Combine(Environment.CurrentDirectory, @"Data\", "doos.png");
            //"C:/Users/alexander/Documents/Visual Studio 2015/Projects/Productiefiche2/Productiefiche2/doos.png";
            PdfRenderingResult result;

            // create image element from file path with real image size
            PdfImageElement img1 = new PdfImageElement(100, 450, bitmap1);

            result = page.Add(img1);

            page.Add(klant);
            page.Add(code);
            page.Add(ordernr1);
            page.Add(lengteDoos2);
            page.Add(breedteDoos2);
            page.Add(hoogteDoos2);
            page.Add(modelDoos2);
            page.Add(aantal);
            page.Add(page1);
            page.Add(kwaliteit2);
            page.Add(plaatformaat1);
            page.Add(aantalPlaten);

            page.Add(rillen1);
            page.Add(rillen2);
            page.Add(rillen3);

            page.Add(page2);
            page.Add(text1);
            page.Add(text2);
            page.Add(text3);
            page.Add(text4);
            page.Add(text5);

            // save pdf document
            string path = @"c:/willbox/Orders/" + txtKlant.Text.ToLower() + "/" + "Ordernr " + ordernr + "/";

            /*
             * try
             * {
             *  // Determine whether the directory exists.
             *  if (Directory.Exists(path))
             *  {
             *
             *  }
             *  else
             *  {
             *      // Try to create the directory.
             *      DirectoryInfo di = Directory.CreateDirectory(path);
             *  }
             *
             * }
             * catch (Exception e)
             * {
             *  Console.WriteLine("The process failed: {0}", e.ToString());
             * }*/

            String padname = "ProductieFiche " + txtKlant.Text.ToLower();

            doc.Save(path + padname + ".pdf");

            // close pdf document
            doc.Close();

            MessageBox.Show("Het PDF-document is aangemaakt met als naam " + padname + ".pdf");

            this.Close();
        }
Ejemplo n.º 21
0
 /// <summary>Adds font to resources and register PdfFont in the document for further flushing.</summary>
 /// <returns>added font resource name.</returns>
 public virtual PdfName AddFont(PdfDocument pdfDocument, PdfFont font)
 {
     pdfDocument.AddFont(font);
     return(AddResource(font, fontNamesGen));
 }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            using (var pdf = new PdfDocument(@"..\Sample data\Freedman Scora.pdf"))
            {
                // This font is used to draw all recognized text chunks in PDF.
                // Make sure that the font defines all glyphs for the target language.
                PdfFont universalFont = pdf.AddFont("Arial");

                var location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var tessData = Path.Combine(location, @"tessdata");
                using (var engine = new TesseractEngine(tessData, "eng", EngineMode.LstmOnly))
                {
                    for (int i = 0; i < pdf.PageCount; ++i)
                    {
                        PdfPage page = pdf.Pages[i];

                        // Simple check if the page contains searchable text.
                        // We do not need to do OCR in that case.
                        if (!string.IsNullOrEmpty(page.GetText().Trim()))
                        {
                            continue;
                        }

                        var canvas = page.Canvas;
                        canvas.Font = universalFont;

                        // Produce invisible, but searchable text
                        canvas.TextRenderingMode = PdfTextRenderingMode.NeitherFillNorStroke;

                        const int    Dpi = 200;
                        const double ImageToPdfScaleFactor = 72.0 / Dpi;
                        foreach (RecognizedTextChunk word in recognizeWords(page, engine, Dpi, $"page_{i}.png"))
                        {
                            if (word.Confidence < 80)
                            {
                                Console.WriteLine($"Possible recognition error: low confidence {word.Confidence} for word '{word.Text}'");
                            }

                            Rect         bounds    = word.Bounds;
                            PdfRectangle pdfBounds = new PdfRectangle(
                                bounds.X1 * ImageToPdfScaleFactor,
                                bounds.Y1 * ImageToPdfScaleFactor,
                                bounds.Width * ImageToPdfScaleFactor,
                                bounds.Height * ImageToPdfScaleFactor
                                );

                            tuneFontSize(canvas, pdfBounds.Width, word.Text);

                            double distanceToBaseLine = getDistanceToBaseline(canvas.Font, canvas.FontSize);
                            var    position           = new PdfPoint(pdfBounds.Left, pdfBounds.Bottom - distanceToBaseLine);
                            showTextAtRotatedPage(word.Text, position, page, page.MediaBox);
                        }
                    }
                }

                universalFont.RemoveUnusedGlyphs();

                const string Result = "OcrAndMakeSearchable.pdf";
                pdf.Save(Result);

                Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
            }
        }
Ejemplo n.º 23
0
        //Encargado de juntar todos los documentos PDF generados en uno solo.
        public void FinalGroup(int Level)
        {
            const String FONT      = @"C:\Windows\Fonts\STKAITI.TTF";
            PdfFont      fontKaiti = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED, true);

            //D:\Portada\HSKBooklets

            PdfWriter writer = new PdfWriter(@"D:\\HSKBooklet\Final_HSK_" + this.pathLevel + ".pdf");

            PdfDocument pdf    = new PdfDocument(new PdfWriter(writer));
            PdfMerger   merger = new PdfMerger(pdf);


            pdf.AddFont(fontKaiti);

            //Interior Cover

            //Add pages from the first document
            PdfDocument InteriorCoverPdf = new PdfDocument(new PdfReader(@"D:\\Portada\HSKBooklets\Interior Cover Level " + this.pathLevel + ".pdf"));

            //From to
            merger.Merge(InteriorCoverPdf, 1, InteriorCoverPdf.GetNumberOfPages());



            //White White Page A4.pdf
            PdfDocument IWhitePdf = new PdfDocument(new PdfReader(@"D:\\Portada\HSKBooklets\White Page A4.pdf"));

            //From to
            merger.Merge(IWhitePdf, 1, IWhitePdf.GetNumberOfPages());

            //HSK Booklets D:\HSKBooklet 1_HSK
            PdfDocument bookletHSK = new PdfDocument(new PdfReader(@"D:\HSKBooklet\" + this.pathLevel + "_HSK.pdf"));

            //From to
            merger.Merge(bookletHSK, 1, bookletHSK.GetNumberOfPages());


            //Word Index Cover "Word Index Level 3.pdf"
            PdfDocument wordIndexCover = new PdfDocument(new PdfReader(@"D:\\Portada\\HSKBooklets\Word Index Level " + this.pathLevel + ".pdf"));

            //From to
            merger.Merge(wordIndexCover, 1, wordIndexCover.GetNumberOfPages());

            merger.Merge(IWhitePdf, 1, IWhitePdf.GetNumberOfPages());

            //Word Index

            PdfDocument wordIndex = new PdfDocument(new PdfReader(@"D:\\HSKBooklet\" + this.pathLevel + "WordIndex.pdf"));

            //From to
            merger.Merge(wordIndex, 1, wordIndex.GetNumberOfPages());


            //Char Cover "Character Index Level 1.pdf"
            PdfDocument CharacterIndexCover = new PdfDocument(new PdfReader(@"D:\\Portada\HSKBooklets\Character Index Level " + this.pathLevel + ".pdf"));

            //From to
            merger.Merge(CharacterIndexCover, 1, CharacterIndexCover.GetNumberOfPages());

            merger.Merge(IWhitePdf, 1, IWhitePdf.GetNumberOfPages());

            //Char Index

            PdfDocument caracterIndex = new PdfDocument(new PdfReader(@"D:\\HSKBooklet\" + this.pathLevel + "CaracterIndex.pdf"));

            //From to
            merger.Merge(caracterIndex, 1, caracterIndex.GetNumberOfPages());


            PdfDocument FinalCover = new PdfDocument(new PdfReader(@"D:\Portada\HSKBooklets\End Cover.pdf"));

            merger.Merge(FinalCover, 1, FinalCover.GetNumberOfPages());

            InteriorCoverPdf.Close();
            IWhitePdf.Close();

            bookletHSK.Close();
            wordIndexCover.Close();

            InteriorCoverPdf.Close();
            wordIndex.Close();
            CharacterIndexCover.Close();
            caracterIndex.Close();
            FinalCover.Close();
            pdf.Close();
        }
Ejemplo n.º 24
0
        private void PageNumbering(int pageIndex)
        {
            FontFamily fontFamily = new FontFamily("Arial");
            Font       font       = new Font(
                fontFamily,
                8,
                FontStyle.Regular,
                GraphicsUnit.Pixel);

            Doc.Footer            = Doc.AddTemplate(Doc.Pages[pageIndex].ClientRectangle.Width, 100);
            Doc.Footer.Foreground = false;
            PdfElement textFooter = new PdfTextElement(converter.Options.MarginLeft, 80, "Página: {page_number} de {total_pages}", Doc.AddFont(font));

            textFooter.ForeColor = System.Drawing.Color.Black;
            Doc.Footer.Add(textFooter);
        }