PdfUtility 1.0.5

.NET Framework 4.5.2
NuGet\Install-Package PdfUtility -Version 1.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package PdfUtility --version 1.0.5
<PackageReference Include="PdfUtility" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PdfUtility --version 1.0.5
#r "nuget: PdfUtility, 1.0.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install PdfUtility as a Cake Addin
#addin nuget:?package=PdfUtility&version=1.0.5

// Install PdfUtility as a Cake Tool
#tool nuget:?package=PdfUtility&version=1.0.5
internal partial class PdfUtilityTester : Form
{
    public PdfUtilityTester()
    {
        Button buttonCreate = new Button() { Parent = this, Text = "Create a pdf", Dock = DockStyle.Top, };
        buttonCreate.Click += (sender, e) =>
        {
            using (var pdfcreator = new PdfUtility.PdfCreator(System.IO.Path.Combine(Application.StartupPath,"test.pdf")))
            {
                /** Use VL Gothic */
                // pdfcreator.ResetBasefont("C:\\Windows\\Fonts\\VL-Gothic-Regular.ttf");
                float ypos = 0;

                /** Draw a text */
                pdfcreator.DrawText("Red", 10, 10, Color.Red);
                /** Draw a line */
                pdfcreator.DrawLine(new[] { new Point(10, 40), new Point(200, 40) }, Color.Red);

                pdfcreator.DrawText("Black", 10, 50);
                pdfcreator.DrawLine(new[] { new Point(10, 80), new Point(200, 80) });

                /** Draw grid */
                var cells = pdfcreator.DrawGrid(new Point(10, 85), 100, 50, 4, 3, Color.Green);
                foreach (var c in cells)
                {
                    /** Draw a text inside rectangle */
                    pdfcreator.DrawText(c.ToString(), c);
                }

                /** Add a new page */
                pdfcreator.NewPage();
                /** Draw a rectangle */
                pdfcreator.DrawRectangle(new Rectangle[] { new Rectangle(100, 100, 150, 150), }, Color.Lime);

                var pagesize = pdfcreator.Size;
                /** Draw a rectangle */
                var rect = new Rectangle(5, 400, pagesize.Width - (5 * 2), 150);
                pdfcreator.DrawText(rect.ToString(), 5, 400 - pdfcreator.FontSize);
                pdfcreator.DrawRectangle(rect, Color.LightBlue, true);

                /** Draw lines */
                pdfcreator.DrawLine(new[] {
                    new Point(5,5),
                    new Point(5,100),
                    new Point(100,100),
                    new Point(100,10),
                    new Point(15,10),
                    new Point(15,95),
                    new Point(95,95),

                }, Color.Blue);

                try
                {
                    var ofd = new OpenFileDialog()
                    {
                        InitialDirectory = Application.StartupPath,
                        Filter = "Image Files (*.bmp, *.jpg)|*.bmp;*.jpg",
                    };
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        var img = iTextSharp.text.Image.GetInstance(ofd.FileName);
                        /** Add a new page */
                        pdfcreator.NewPage();

                        /** Draw a image */
                        pdfcreator.DrawImage(img, 10, ypos, 50);
                    }
                }
                catch
                {
                }

                pdfcreator.Close();
                pdfcreator.Save();
            }
        };

        Button buttonExtractImages = new Button() { Text = "Extract images from a pdf", Parent = this, Dock = DockStyle.Top, };
        buttonExtractImages.Click += (sender, e) =>
        {
            var ofd = new OpenFileDialog()
            {
                InitialDirectory =  Application.StartupPath,
                Filter = "Pdf File (*.pdf)|*.pdf",
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var dicimage = PdfUtility.PdfImageCollector.GetAllImages(ofd.FileName);
                var fn = System.IO.Path.GetFileNameWithoutExtension(ofd.FileName);

                foreach (var kv in dicimage)
                {
                    var idx = 0;
                    foreach (var image in kv.Value)
                    {
                        var dst = System.IO.Path.Combine(Application.StartupPath, string.Format("{0}_p{1}_{2}.jpg", fn, kv.Key, idx++));
                        using (System.IO.FileStream fs = new System.IO.FileStream(dst, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                        {
                            fs.Write(image, 0, image.Length);
                        }
                    }
                }
            }
        };

        Button buttonExtractText = new Button() { Text = "Extract text from a pdf", Parent = this, Dock = DockStyle.Top, };
        buttonExtractText.Click += (sender, e) =>
        {
            var ofd = new OpenFileDialog()
            {
                InitialDirectory = Application.StartupPath,
                Filter = "Pdf File (*.pdf)|*.pdf",
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var dictext = PdfUtility.PdfTextCollector.GetText(ofd.FileName);
                foreach (var kv in dictext)
                {
                    var max = Math.Min(10, kv.Value.Count);
                    var ret = MessageBox.Show(string.Join(Environment.NewLine, kv.Value.Take(max)), "Text", MessageBoxButtons.OKCancel);
                    if (ret == DialogResult.Cancel)
                    {
                        break;
                    }
                }
            }
        };

        Text = "PdfUtilityTester";
        ClientSize = new Size(400, 400);
        StartPosition = FormStartPosition.CenterScreen;

    }
}
Product Versions
.NET Framework net452 net46 net461 net462 net463 net47 net471 net472 net48
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 114 4/2/2022
1.0.4 89 3/1/2022
1.0.3 81 2/20/2022
1.0.2 85 2/13/2022
1.0.1 126 12/7/2021