Esempio n. 1
0
 /// <summary>
 /// Update values in PDFPage. Returns an object of type PDFPage.
 /// </summary>
 /// <param name="sqlConnection">Sql connection or null.</param>
 /// <param name="sqlTransaction">Sql transaction or null.</param>
 /// <param name="value">Object of type PDFPage.</param>
 /// <returns>Object of type PDFPage.</returns>
 public PDFPage PDFPageUpdateAuto(
     SqlConnection sqlConnection,
     SqlTransaction sqlTransaction,
     PDFPage value)
 {
     return(PDFPageUpdateAuto(sqlConnection, sqlTransaction, "BHL", value));
 }
Esempio n. 2
0
 /// <summary>
 /// Manage PDFPage object.
 /// If the object is of type CustomObjectBase,
 /// then either insert values into, delete values from, or update values in PDFPage.
 /// </summary>
 /// <param name="sqlConnection">Sql connection or null.</param>
 /// <param name="sqlTransaction">Sql transaction or null.</param>
 /// <param name="value">Object of type PDFPage.</param>
 /// <returns>Object of type CustomDataAccessStatus<PDFPage>.</returns>
 public CustomDataAccessStatus <PDFPage> PDFPageManageAuto(
     SqlConnection sqlConnection,
     SqlTransaction sqlTransaction,
     PDFPage value)
 {
     return(PDFPageManageAuto(sqlConnection, sqlTransaction, "BHL", value));
 }
Esempio n. 3
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream s1, Stream s2)
        {
            PDFFixedDocument document = new PDFFixedDocument();

            document.DisplayMode = PDFDisplayMode.UseAttachments;

            PDFStandardFont helvetica  = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);
            PDFBrush        blackBrush = new PDFBrush();
            PDFPage         page       = document.Pages.Add();

            page.Canvas.DrawString("This document contains 2 file attachments:", helvetica, blackBrush, 50, 50);
            page.Canvas.DrawString("1. fileattachments.cs.html", helvetica, blackBrush, 50, 70);
            page.Canvas.DrawString("2. fileattachments.vb.html", helvetica, blackBrush, 50, 90);

            byte[] fileData1 = new byte[s1.Length];
            s1.Read(fileData1, 0, fileData1.Length);
            PDFDocumentFileAttachment fileAttachment1 = new PDFDocumentFileAttachment();

            fileAttachment1.Payload     = fileData1;
            fileAttachment1.FileName    = "fileattachments.cs.html";
            fileAttachment1.Description = "C# Source Code for FileAttachments sample";
            document.FileAttachments.Add(fileAttachment1);

            byte[] fileData2 = new byte[s2.Length];
            s2.Read(fileData2, 0, fileData2.Length);
            PDFDocumentFileAttachment fileAttachment2 = new PDFDocumentFileAttachment();

            fileAttachment2.Payload     = fileData1;
            fileAttachment2.FileName    = "fileattachments.vb.html";
            fileAttachment2.Description = "VB.NET Source Code for FileAttachments sample";
            document.FileAttachments.Add(fileAttachment2);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "fileattachments.pdf") };
            return(output);
        }
Esempio n. 4
0
        PDFPage CreateNewPage(PDFFont font, string serialNumber)
        {
            var headerPen       = new PDFPen(Color.DarkSlateBlue, 120);
            var serialfont      = new PDFFont(FontType.Helvetica, 16, PDF.Drawing.FontStyle.Regular);
            var companyNameFont = new PDFFont(FontType.Helvetica, 30, PDF.Drawing.FontStyle.Bold);

            pageNumber++;

            PDFPage page = pdfDocument.AddPage();

            page.Height = 1000;
            page.Width  = 700;

            page.DrawLine(headerPen, 0, 0, 700, 0);
            page.DrawString(LabelConstant.Title, serialfont, Color.White, 10, 50);
            page.DrawString(LabelConstant.SerialNumber + serialNumber, serialfont, Color.White, 550, 50);
            page.DrawString(LabelConstant.CompanyName, companyNameFont, Color.White, 230, 40);
            page.DrawString(LabelConstant.TradeMark, font, Color.White, 450, 20);
            page.DrawString(LabelConstant.Page + pageNumber, font, Color.Black, 600, 980);
            page.DrawString(LabelConstant.Website, font, Color.Black, PDFcoordinates.siteX, PDFcoordinates.siteY);
            page.DrawString(DateTime.UtcNow.ToString("dd/MM/yyy HH:mm:sss UTC"), font, Color.White, PDFcoordinates.dateX, PDFcoordinates.dateY);
            page.DrawString("0.1.9.1", font, Color.Black, PDFcoordinates.versionX, PDFcoordinates.versionY);

            return(page);
        }
Esempio n. 5
0
        private static void CreateTextMarkupAnnotations(PDFFixedDocument document, PDFFont font)
        {
            PDFBrush blackBrush = new PDFBrush();

            PDFPage page = document.Pages.Add();

            page.Canvas.DrawString("Text markup annotations", font, blackBrush, 50, 50);

            PDFTextMarkupAnnotationType[] tmat = new PDFTextMarkupAnnotationType[]
            {
                PDFTextMarkupAnnotationType.Highlight, PDFTextMarkupAnnotationType.Squiggly, PDFTextMarkupAnnotationType.StrikeOut, PDFTextMarkupAnnotationType.Underline
            };

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;

            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            for (int i = 0; i < tmat.Length; i++)
            {
                PDFTextMarkupAnnotation tma = new PDFTextMarkupAnnotation();
                page.Annotations.Add(tma);
                tma.DisplayRectangle = new PDFDisplayRectangle(50, 100 + 50 * i, 200, font.Size + 2);
                tma.TextMarkupType   = tmat[i];

                slo.X = 150;
                slo.Y = 100 + 50 * i + font.Size;

                page.Canvas.DrawString(tmat[i].ToString() + " annotation.", sao, slo);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Select values from PDFPage by primary key(s).
        /// </summary>
        /// <param name="sqlConnection">Sql connection or null.</param>
        /// <param name="sqlTransaction">Sql transaction or null.</param>
        /// <param name="connectionKeyName">Connection key name located in config file.</param>
        /// <param name="pdfPageID"></param>
        /// <returns>Object of type PDFPage.</returns>
        public PDFPage PDFPageSelectAuto(
            SqlConnection sqlConnection,
            SqlTransaction sqlTransaction,
            string connectionKeyName,
            int pdfPageID)
        {
            SqlConnection  connection  = CustomSqlHelper.CreateConnection(CustomSqlHelper.GetConnectionStringFromConnectionStrings(connectionKeyName), sqlConnection);
            SqlTransaction transaction = sqlTransaction;

            using (SqlCommand command = CustomSqlHelper.CreateCommand("PDFPageSelectAuto", connection, transaction,
                                                                      CustomSqlHelper.CreateInputParameter("PdfPageID", SqlDbType.Int, null, false, pdfPageID)))
            {
                using (CustomSqlHelper <PDFPage> helper = new CustomSqlHelper <PDFPage>())
                {
                    CustomGenericList <PDFPage> list = helper.ExecuteReader(command);
                    if (list.Count > 0)
                    {
                        PDFPage o = list[0];
                        list = null;
                        return(o);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Draws content on a page using colors created from a calibrated Lab colorspace.
        /// </summary>
        /// <param name="page">The page to draw to.</param>
        private static void DrawLabColorSpace(PDFPage page)
        {
            PDFRgbColor black      = new PDFRgbColor(0, 0, 0);
            PDFBrush    blackBrush = new PDFBrush(black);
            //PDF4NET v5: PDFFont font = new PDFFont(PDFFontFace.Helvetica, 16);
            PDFStandardFont font = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);

            //PDF4NET v5: page.Canvas.DrawText("L*a*b* colorspace", font, null, blackBrush, 50, 50);
            page.Canvas.DrawString("L*a*b* colorspace", font, blackBrush, 50, 50);

            PDFLabColorSpace labCS   = new PDFLabColorSpace();
            PDFLabColor      labClr1 = new PDFLabColor(labCS);

            labClr1.L = 90;
            labClr1.A = 20;
            labClr1.B = -10;
            PDFLabColor labClr2 = new PDFLabColor(labCS);

            labClr2.L = 10;
            labClr2.A = 70;
            labClr2.B = -50;
            PDFBrush brush = new PDFBrush(labClr1);
            PDFPen   pen   = new PDFPen(labClr2, 5);

            page.Canvas.DrawRoundRectangle(pen, brush, 50, 100, 400, 150, 20, 20);
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            // Extract the page content from the source file.
            FileStream     stream      = File.OpenRead("input.pdf");
            PDFFile        source      = new PDFFile(stream);
            PDFPageContent pageContent = source.ExtractPageContent(0);

            stream.Close();

            PDFFixedDocument document = new PDFFixedDocument();

            document.OptionalContentProperties = new PDFOptionalContentProperties();
            PDFPage page = document.Pages.Add();

            // Create an optional content group (layer) for the extracted page content.
            PDFOptionalContentGroup ocg = new PDFOptionalContentGroup();

            ocg.Name            = "Embedded page";
            ocg.VisibilityState = PDFOptionalContentGroupVisibilityState.AlwaysVisible;
            ocg.PrintState      = PDFOptionalContentGroupPrintState.NeverPrint;
            // Draw the extracted page content in the layer
            page.Canvas.BeginOptionalContentGroup(ocg);
            page.Canvas.DrawFormXObject(pageContent, 0, 0, page.Width, page.Height);
            page.Canvas.EndOptionalContentGroup();

            // Build the display tree for the optional content
            PDFOptionalContentDisplayTreeNode ocgNode = new PDFOptionalContentDisplayTreeNode(ocg);

            document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgNode);

            using (FileStream output = File.Create("EmbedPageAsLayer.pdf"))
            {
                document.Save(output);
            }
        }
            /// <summary>
            /// Initializes a new instance of FormSelector from a PDFPage.
            /// </summary>
            public Selector(PDFPage page)
            {
                PDFDocument owner = page.Owner;

                Path = "*" + owner.Guid.ToString("B");
                Path = Path.ToLowerInvariant();
            }
Esempio n. 10
0
    void TextPageAPI(PDFDocument document)
    {
        Debug.Log("TEXTPAGE API-------------------------");

        PDFPage page = document.GetPage(1);

        Debug.Log("Page size: " + page.GetPageSize());

        PDFTextPage textPage   = page.GetTextPage();
        int         countChars = textPage.CountChars();

        Debug.Log("Page chars count: " + countChars);

        string str = textPage.GetText(0, countChars);

        Debug.Log("Page text: " + str);

        int rectCount = textPage.CountRects(0, countChars);

        Debug.Log("Rect count: " + rectCount);

        string boundedText = textPage.GetBoundedText(0, 0, page.GetPageSize().x, page.GetPageSize().y * 0.5f, 2000);

        Debug.Log("Bounded text: " + boundedText);
    }
Esempio n. 11
0
        /// <summary>
        /// A really basic example to show the new, in-development functionality that will allow PDFs to be edited.
        /// </summary>
        /// <param name="bitmapFilename"></param>
        public static void AddImageToPDF(string bitmapFilename)
        {
            Console.WriteLine("Add image to PDF...");

            Bitmap bmp;

            if (string.IsNullOrEmpty(bitmapFilename))
            {
                bmp = new Bitmap(500, 500);
                for (int x = 0; x < 500; x++)
                {
                    for (int y = 0; y < 500; y++)
                    {
                        bmp.SetPixel(x, y, Color.Black);
                    }
                }
            }
            else
            {
                bmp = new Bitmap(bitmapFilename);
            }
            PDFDocument pDoc = new PDFDocument();

            Console.WriteLine("Loading for editing...");
            pDoc.LoadPDF("compressed.tracemonkey-pldi-09.pdf");
            PDFPage pPage = pDoc.GetPage(0);

            Console.WriteLine("Inserting image...");
            pDoc.InsertImage("testimage", bmp, 0, (pPage.Width / 2) - 75, (pPage.Height / 2) - 50, 150, 100);
            Console.WriteLine("Saving...");
            pDoc.SavePDF("pdfoutput.pdf");
            Console.WriteLine("Done...");
        }
Esempio n. 12
0
        // For this sample to work, the following file
        // needs to exist: multicolumntextandimages.pdf.
        // Compile the corresponding sample to get this file
        public static void MultiPage()
        {
            //PDF4NET v5: PDFFile mctiFile = PDFFile.FromFile("Sample_MultiColumnTextAndImages-Secure.pdf", Encoding.ASCII.GetBytes("userpass"));
            FileStream stm  = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\content.pdf");
            PDFFile    file = new PDFFile(stm);

            // extract the content of first 4 pages
            //PDF4NET v5: PDFImportedContent[] ic = mctiFile.ExtractPagesContent("0-3");
            PDFPageContent[] pc = file.ExtractPageContent(0, 3);

            // create the new document
            //PDF4NET v5: PDFDocument doc = new PDFDocument();
            PDFFixedDocument doc = new PDFFixedDocument();
            // add a page to it
            //PDF4NET v5: PDFPage page = doc.AddPage();
            PDFPage page = doc.Pages.Add();

            // draw the imported content (4 pages) on the new page
            //PDF4NET v5: page.Canvas.DrawImportedContent(ic[0], 0, 0, page.Width / 2, page.Height / 2);
            page.Canvas.DrawFormXObject(pc[0], 0, 0, page.Width / 2, page.Height / 2);
            //PDF4NET v5: page.Canvas.DrawImportedContent(ic[1], page.Width / 2, 0, page.Width / 2, page.Height / 2);
            page.Canvas.DrawFormXObject(pc[1], page.Width / 2, 0, page.Width / 2, page.Height / 2);
            //PDF4NET v5: page.Canvas.DrawImportedContent(ic[2], 0, page.Height / 2, page.Width / 2, page.Height / 2);
            page.Canvas.DrawFormXObject(pc[2], 0, page.Height / 2, page.Width / 2, page.Height / 2);
            //PDF4NET v5: page.Canvas.DrawImportedContent(ic[3], page.Width / 2, page.Height / 2, page.Width / 2, page.Height / 2);
            page.Canvas.DrawFormXObject(pc[3], page.Width / 2, page.Height / 2, page.Width / 2, page.Height / 2);

            // save the mixed document
            doc.Save("Sample_Imposition.pdf");

            //PDF4NET v5: mctiFile.Close();
            stm.Close();
        }
Esempio n. 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkWithTransparency(PDFPage page)
        {
            PDFBrush        redBrush  = new PDFBrush(new PDFRgbColor(192, 0, 0));
            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 36);

            // The page graphics is located by default on top of existing page content.
            //page.SetGraphicsPosition(PDFPageGraphicsPosition.OverExistingPageContent);

            page.Canvas.SaveGraphicsState();

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = redBrush;
            sao.Font  = helvetica;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X        = 130;
            slo.Y        = 670;
            slo.Rotation = 60;

            // Draw the watermark over page content but setting the transparency to a value lower than 1.
            // The page content will be partially visible through the watermark.
            PDFExtendedGraphicState gs1 = new PDFExtendedGraphicState();

            gs1.FillAlpha = 0.3;
            page.Canvas.SetExtendedGraphicState(gs1);
            page.Canvas.DrawString("Sample watermark over page content", sao, slo);

            page.Canvas.RestoreGraphicsState();
        }
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PDFDocumentFeatures df = new PDFDocumentFeatures();

            // Do not load file attachments, new file attachments cannot be added.
            df.EnableDocumentFileAttachments = false;
            // Do not load form fields, form fields cannot be filled and new form fields cannot be added.
            df.EnableDocumentFormFields = false;
            // Do not load embedded JavaScript code, new JavaScript code at document level cannot be added.
            df.EnableDocumentJavaScriptFragments = false;
            // Do not load the named destinations, new named destinations cannot be created.
            df.EnableDocumentNamedDestinations = false;
            // Do not load the document outlines, new outlines cannot be created.
            df.EnableDocumentOutline = false;
            // Do not load annotations, new annotations cannot be added to existing pages.
            df.EnablePageAnnotations = false;
            // Do not load the page graphics, new graphics cannot be added to existing pages.
            df.EnablePageGraphics = false;
            PDFFixedDocument document = new PDFFixedDocument(input, df);

            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 24);
            PDFBrush        brush     = new PDFBrush();

            // Add a new page with some content on it.
            PDFPage page = document.Pages.Add();

            page.Canvas.DrawString("New page added to an existing document.", helvetica, brush, 20, 50);

            // When document features have been specified at load time the document is automatically saved in incremental update mode.
            document.Save(input);

            return(null);
        }
Esempio n. 15
0
        private static void CreateLineAnnotations(PDFFixedDocument document, PDFFont font)
        {
            PDFBrush blackBrush = new PDFBrush();

            PDFPage page = document.Pages.Add();

            page.Canvas.DrawString("Line annotations", font, blackBrush, 50, 50);

            PDFLineEndSymbol[] les = new PDFLineEndSymbol[]
            {
                PDFLineEndSymbol.Circle, PDFLineEndSymbol.ClosedArrow, PDFLineEndSymbol.None, PDFLineEndSymbol.OpenArrow
            };

            for (int i = 0; i < les.Length; i++)
            {
                PDFLineAnnotation la = new PDFLineAnnotation();
                page.Annotations.Add(la);
                la.Author        = "O2S.Components.PDF4NET";
                la.Contents      = "I am a line annotation with " + les[i].ToString() + " ending.";
                la.StartPoint    = new PDFPoint(50, 100 + 40 * i);
                la.EndPoint      = new PDFPoint(250, 100 + 40 * i);
                la.EndLineSymbol = les[i];
                page.Canvas.DrawString("Line end symbol: " + les[i].ToString(), font, blackBrush, 270, 100 + 40 * i);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Reads the content stream(s) of the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        static public CSequence ReadContent(PDFPage page)
        {
            CParser   parser   = new CParser(page);
            CSequence sequence = parser.ReadContent();

            return(sequence);
        }
Esempio n. 17
0
        /// <summary>
        /// Draws content on a page using colors created from an indexed colorspace.
        /// </summary>
        /// <param name="page">The page to draw to.</param>
        private static void DrawIndexedColorSpace(PDFPage page)
        {
            PDFRgbColor black      = new PDFRgbColor(0, 0, 0);
            PDFBrush    blackBrush = new PDFBrush(black);
            //PDF4NET v5: PDFFont font = new PDFFont(PDFFontFace.Helvetica, 16);
            PDFStandardFont font = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);

            //PDF4NET v5: page.Canvas.DrawText("Indexed colorspace with 2 colors", font, null, blackBrush, 50, 50);
            page.Canvas.DrawString("Indexed colorspace with 2 colors", font, blackBrush, 50, 50);

            // Create an indexed colorspace with 2 RGB colors, 24bits (3*8bytes) per color.
            PDFIndexedColorSpace ixCS = new PDFIndexedColorSpace();

            //PDF4NET v5: ixCS.MaxIndex = 1;
            ixCS.ColorCount = 2;
            ixCS.ColorTable = new byte[] { 255, 0, 0, 192, 0, 255 };
            PDFIndexedColor red = new PDFIndexedColor(ixCS);

            red.ColorIndex = 0;
            PDFIndexedColor violet = new PDFIndexedColor(ixCS);

            violet.ColorIndex = 1;
            PDFBrush redBrush  = new PDFBrush(red);
            PDFPen   violetPen = new PDFPen(violet, 5);

            page.Canvas.DrawRoundRectangle(violetPen, redBrush, 50, 100, 400, 150, 20, 20);
        }
Esempio n. 18
0
        /// <summary>
        /// Draws content on a page using colors created from a calibrated RGB colorspace.
        /// </summary>
        /// <param name="page">The page to draw to.</param>
        private static void DrawCalRgbColorSpace(PDFPage page)
        {
            PDFRgbColor black      = new PDFRgbColor(0, 0, 0);
            PDFBrush    blackBrush = new PDFBrush(black);
            //PDF4NET v5: PDFFont font = new PDFFont(PDFFontFace.Helvetica, 16);
            PDFStandardFont font = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);

            //PDF4NET v5: page.Canvas.DrawText("CalRGB colorspace", font, null, blackBrush, 50, 50);
            page.Canvas.DrawString("CalRGB colorspace", font, blackBrush, 50, 50);

            PDFCalRgbColorSpace calRgbCS = new PDFCalRgbColorSpace();
            PDFCalRgbColor      red      = new PDFCalRgbColor(calRgbCS);

            red.Red   = 1;
            red.Green = 0;
            red.Blue  = 0;
            PDFCalRgbColor blue = new PDFCalRgbColor(calRgbCS);

            blue.Red   = 0;
            blue.Green = 0;
            blue.Blue  = 1;
            PDFBrush blueBrush = new PDFBrush(blue);
            PDFPen   redPen    = new PDFPen(red, 5);

            page.Canvas.DrawRoundRectangle(redPen, blueBrush, 50, 100, 400, 150, 20, 20);
        }
Esempio n. 19
0
    IEnumerator Start()
    {
#if UNITY_WEBGL
        yield break;
#else
        Debug.Log(Application.persistentDataPath);

        m_Viewer.gameObject.SetActive(true);

        m_Viewer.LoadDocumentFromWeb("http://www.pdf995.com/samples/pdf.pdf", "");

        // Wait until the pdf document is loaded.
        while (!m_Viewer.IsLoaded)
        {
            yield return(null);
        }

        PDFDocument document = m_Viewer.Document;
        Debug.Log("Page count: " + document.GetPageCount());

        PDFPage firstPage = document.GetPage(0);
        Debug.Log("First Page Size: " + firstPage.GetPageSize());

        PDFTextPage firstTextPage = firstPage.GetTextPage();
        Debug.Log("First Page Chars Count: " + firstTextPage.CountChars());

        IList <PDFSearchResult> searchResults = firstTextPage.Search("the", PDFSearchHandle.MatchOption.NONE, 0);
        Debug.Log("Search Results Count: " + searchResults.Count);

        // Wait 2 seconds and then load another document
        yield return(new WaitForSeconds(2.0f));

        m_Viewer.LoadDocumentFromAsset(m_PDFAsset);
#endif
    }
Esempio n. 20
0
        private static PDFOutlineItem CreateOutline(string title, PDFPage page)
        {
            PDFPageDirectDestination pageDestination = new PDFPageDirectDestination();

            pageDestination.Page = page;
            pageDestination.Top  = 0;
            pageDestination.Left = 0;
            // Inherit current zoom
            pageDestination.Zoom = 0;

            // Create a go to action to be executed when the outline is clicked,
            // the go to action goes to specified destination.
            PDFGoToAction gotoPage = new PDFGoToAction();

            gotoPage.Destination = pageDestination;

            // Create the outline in the table of contents
            PDFOutlineItem outline = new PDFOutlineItem();

            outline.Title       = title;
            outline.VisualStyle = PDFOutlineItemVisualStyle.Italic;
            outline.Action      = gotoPage;

            return(outline);
        }
Esempio n. 21
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream file1Input, Stream file2Input)
        {
            PDFFixedDocument document = new PDFFixedDocument();

            // The documents are merged by creating an empty PDF document and appending the file to it.
            // The outlines from the source file are also included in the merged file.
            document.AppendFile(file1Input);
            int count = document.Pages.Count;

            document.AppendFile(file2Input);

            // Create outlines that point to each merged file.
            PDFOutlineItem file1Outline = CreateOutline("First file", document.Pages[0]);

            document.Outline.Add(file1Outline);
            PDFOutlineItem file2Outline = CreateOutline("Second file", document.Pages[count]);

            document.Outline.Add(file2Outline);

            // Optionally we can add a new page at the beginning of the merged document.
            PDFPage page = new PDFPage();

            document.Pages.Insert(0, page);

            PDFOutlineItem blankPageOutline = CreateOutline("Blank page", page);

            document.Outline.Insert(0, blankPageOutline);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "documentappend.pdf") };
            return(output);
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            // Create the pdf document
            //PDF4NET v5: PDFDocument doc = new PDFDocument();
            PDFFixedDocument doc = new PDFFixedDocument();

            // Create a blank page
            //PDF4NET v5: PDFPage page = doc.AddPage();
            PDFPage page = doc.Pages.Add();

            // Create the signature field.
            PDFSignatureField sign = new PDFSignatureField("Signature");

            //PDF4NET v5: sign.Widgets[0].DisplayRectangle = new DisplayRectangle(50, 100, 200, 40);
            sign.Widgets[0].DisplayRectangle = new PDFDisplayRectangle(50, 100, 200, 40);
            // Create the digital signature.
            //PDF4NET v5: sign.Signature = new PDFDigitalSignature();
            PDFCmsDigitalSignature ds = new PDFCmsDigitalSignature();

            // The certificate is loaded from disk, but it also can be loaded from a certificate store.
            ds.Certificate = new X509Certificate2("..\\..\\..\\..\\..\\SupportFiles\\O2SolutionsDemoCertificate.pfx", "P@ssw0rd!", X509KeyStorageFlags.Exportable);
            ds.Location    = "Romania";
            ds.Reason      = "For demo";
            ds.ContactInfo = "*****@*****.**";
            sign.Signature = ds;
            page.Fields.Add(sign);

            doc.Save("Sample_DigitalSign.pdf");
        }
Esempio n. 23
0
        /// <summary>
        /// Draws content on a page using colors created from a calibrated ICC colorspace.
        /// </summary>
        /// <param name="page">The page to draw to.</param>
        private static void DrawICCColorSpace(PDFPage page)
        {
            PDFRgbColor black      = new PDFRgbColor(0, 0, 0);
            PDFBrush    blackBrush = new PDFBrush(black);
            //PDF4NET v5: PDFFont font = new PDFFont(PDFFontFace.Helvetica, 16);
            PDFStandardFont font = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);

            //PDF4NET v5: page.Canvas.DrawText("ICC colorspace", font, null, blackBrush, 50, 50);
            page.Canvas.DrawString("ICC colorspace", font, blackBrush, 50, 50);

            // Read the ICC profile from disk.
            FileStream fs = new FileStream("..\\..\\..\\..\\..\\SupportFiles\\rgb.icc", FileMode.Open, FileAccess.Read);

            byte[] profileData = new byte[fs.Length];
            fs.Read(profileData, 0, profileData.Length);
            fs.Close();

            //PDF4NET v5: PDFICCColorSpace iccCS = new PDFICCColorSpace();
            PDFIccColorSpace iccCS = new PDFIccColorSpace();

            iccCS.IccProfile = profileData;
            //PDF4NET v5: PDFICCColor red = new PDFICCColor(iccCS);
            PDFIccColor red = new PDFIccColor(iccCS);

            red.ColorComponents = new double[] { 192, 0, 0 };
            //PDF4NET v5: PDFICCColor blue = new PDFICCColor(iccCS);
            PDFIccColor blue = new PDFIccColor(iccCS);

            blue.ColorComponents = new double[] { 0, 0, 192 };
            PDFBrush blueBrush = new PDFBrush(blue);
            PDFPen   redPen    = new PDFPen(red, 5);

            page.Canvas.DrawRoundRectangle(redPen, blueBrush, 50, 100, 400, 150, 20, 20);
        }
Esempio n. 24
0
        public static void Main(string[] args)
        {
            PDFFixedDocument document  = new PDFFixedDocument();
            PDFPage          page      = document.Pages.Add();
            PDFPen           pen       = new PDFPen(PDFRgbColor.Black, 1);
            PDFStandardFont  helvetica = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);

            PDFPoint[] points = new PDFPoint[] {
                new PDFPoint(50, 150), new PDFPoint(100, 200), new PDFPoint(150, 50), new PDFPoint(200, 150), new PDFPoint(250, 50)
            };
            DrawBezierConnectedLines(page, points, pen, 0, helvetica);

            page.Canvas.TranslateTransform(0, 200);
            DrawBezierConnectedLines(page, points, pen, 0.1, helvetica);

            page.Canvas.TranslateTransform(0, 200);
            DrawBezierConnectedLines(page, points, pen, 0.3, helvetica);

            page.Canvas.TranslateTransform(0, 200);
            DrawBezierConnectedLines(page, points, pen, 0.5, helvetica);

            using (FileStream output = File.Create("BezierConnectedLines.pdf"))
            {
                document.Save(output);
            }
        }
Esempio n. 25
0
        public IList <MonthRow> GetRowsObjects(PDFPage page)
        {
            if (page.RowObs == null)
            {
                var n1 = GetElementsByTagName(page.Node, "row");
                if (n1 != null && n1.Count > 0)
                {
                    page.RowObs = new List <MonthRow>(7);
                    for (var i = 0; i < n1.Count; i++)
                    {
                        var r = new MonthRow();
                        page.RowObs.Add(r);

                        var node = n1[i];

                        double height;
                        var    hght = node.Attributes["height"].Value;

                        if (double.TryParse(hght, out height))
                        {
                            r.Height = height;
                        }
                        else
                        {
                            r.Height = default(double);
                        }

                        var week = node.FirstChild.Value;
                        r.Cells = week.Split(new[] { "|" }, StringSplitOptions.None);
                    }
                }
            }
            return(page.RowObs);
        }
Esempio n. 26
0
        /// <summary>
        /// Generates a PDF document that is encrypted using AES method.
        /// </summary>
        /// <param name="keySize">The encryption key size.</param>
        /// <param name="aes"></param>
        /// <returns></returns>
        private static PDFFixedDocument EncryptAES(int keySize, PDFAesSecurityHandler aes)
        {
            PDFFixedDocument doc = new PDFFixedDocument();

            aes.EnableContentExtractionForAccessibility = false;
            aes.EnableDocumentAssembly         = false;
            aes.EnableDocumentChange           = false;
            aes.EnableContentExtraction        = false;
            aes.EnableFormsFill                = false;
            aes.EnableAnnotationsAndFieldsEdit = false;
            aes.EnablePrint     = false;
            aes.EncryptMetadata = true;
            aes.KeySize         = keySize;
            aes.UserPassword    = "******";
            aes.OwnerPassword   = "******";

            PDFPage         page       = doc.Pages.Add();
            PDFStandardFont helvetica  = new PDFStandardFont(PDFStandardFontFace.HelveticaBoldItalic, 16);
            PDFBrush        blackBrush = new PDFBrush();

            string text = string.Format("Encryption: AES {0} bit", keySize);

            if ((aes.KeySize == 256) && aes.UseEnhancedPasswordValidation)
            {
                text = text + " with enhanced password validation (Acrobat X or later)";
            }
            page.Canvas.DrawString(text, helvetica, blackBrush, 50, 100);

            return(doc);
        }
Esempio n. 27
0
 public void ParsePages(XmlNode root)
 {
     if (root.Name == "pages")
     {
         var n1 = GetElementsByTagName(root, "page");
         if (n1 != null && n1.Count > 0)
         {
             for (var i = 0; i < n1.Count; i++)
             {
                 var page = new PDFPage {
                     Node = n1[i]
                 };
                 Pages.Add(page);
                 ParseConfig(page);
                 EventsParsing(page);
             }
         }
     }
     else
     {
         var page = new PDFPage {
             Node = root
         };
         Pages.Add(page);
         ParseConfig(page);
         EventsParsing(page);
     }
 }
Esempio n. 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkOverPageContent(PDFPage page)
        {
            PDFBrush        redBrush  = new PDFBrush(new PDFRgbColor(192, 0, 0));
            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 32);

            // The page canvas is located by default on top of existing page content.
            //page.SetCanvasPosition(PDFPageCanvasPosition.OverExistingPageContent);

            // Draw the watermark over page content.
            // Page content under the watermark will be masked.
            page.Canvas.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 335);

            page.Canvas.SaveGraphicsState();

            // Draw the watermark over page content but using the Multiply blend mode.
            // The watermak will appear as if drawn under the page content, useful when watermarking scanned documents.
            // If the watermark is drawn under page content for scanned documents, it will not be visible because the scanned image will block it.
            PDFExtendedGraphicState gs1 = new PDFExtendedGraphicState();

            gs1.BlendMode = PDFBlendMode.Multiply;
            page.Canvas.SetExtendedGraphicState(gs1);
            page.Canvas.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 385);

            // Draw the watermark over page content but using the Luminosity blend mode.
            // Both the page content and the watermark will be visible.
            PDFExtendedGraphicState gs2 = new PDFExtendedGraphicState();

            gs2.BlendMode = PDFBlendMode.Luminosity;
            page.Canvas.SetExtendedGraphicState(gs2);
            page.Canvas.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 435);

            page.Canvas.RestoreGraphicsState();
        }
Esempio n. 29
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PDFFixedDocument document    = new PDFFixedDocument();
            PDFStandardFont  titleFont   = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 16);
            PDFStandardFont  barcodeFont = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12);

            PDFPage page = document.Pages.Add();

            DrawGenericBarcodes(page, titleFont, barcodeFont);

            page = document.Pages.Add();
            DrawPharmaBarcodes(page, titleFont, barcodeFont);

            page = document.Pages.Add();
            DrawEanUpcBarcodes(page, titleFont, barcodeFont);

            page = document.Pages.Add();
            DrawPostAndTransportantionBarcodes(page, titleFont, barcodeFont);

            page = document.Pages.Add();
            Draw2DBarcodes(page, titleFont, barcodeFont);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "barcodes.pdf") };
            return(output);
        }
Esempio n. 30
0
        private static void CreateInkAnnotations(PDFFixedDocument document, PDFFont font)
        {
            PDFBrush blackBrush = new PDFBrush();
            Random   rnd        = new Random();

            PDFPage page = document.Pages.Add();

            page.Canvas.DrawString("Ink annotations", font, blackBrush, 50, 50);

            // The ink annotation will contain 3 lines, each one with 10 points.
            PDFPoint[][] points = new PDFPoint[3][];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = new PDFPoint[10];
                for (int j = 0; j < points[i].Length; j++)
                {
                    points[i][j] = new PDFPoint(rnd.NextDouble() * page.Width, rnd.NextDouble() * page.Height);
                }
            }

            PDFInkAnnotation ia = new PDFInkAnnotation();

            page.Annotations.Add(ia);
            ia.Contents = "I am an ink annotation.";
            ia.InkColor = new PDFRgbColor(255, 0, 255);
            ia.InkWidth = 5;
            ia.Points   = points;
        }
        PageLayout DetectLayout(DW<PDFWrapper> doc, PDFPage page)
        {
            Size pageSize = new Size(doc.o.PageWidth, doc.o.PageHeight);
            PageLayout layout = new PageLayout(pageSize);

            // Get text
            // TODO: check how text is split in multicolumn case -- is this the method with correct options (flow, not physical)
            layout.Text = page.Text;

            var words = new List<LayoutElement>();
            var nonEmptyWords = page.WordList
                .Where(x => !x.Bounds.IsEmpty && !x.Word.IsEmpty())
                .Select(x => LayoutElement.NewWord(pageSize, x.Bounds, x.Word));

            words.AddRange(nonEmptyWords);

            // Detect rows and columns
            var rows = words.Split(StartsNewRow).Select(ws => LayoutElement.NewRow(ws, LayoutElementType.Row));
            var cols = rows.Split(StartsNewColumn).Select(rs => LayoutElement.NewRow(rs, LayoutElementType.Column));

            // TODO: detect header/footer
            layout.Children.AddRange(cols);

            // Strange bug -- if doing the following, first word is missing and last word is blank.
            // However, with LINQ query above it's fine

            //List<PDFTextWord> ws = new List<PDFTextWord>();
            //ws.AddRange(page.WordList);

            if (layout.Children.Count > 0)
            {
                layout.SetBoundsFromNodes(true);

                /*
                // expand by width a bit (to prevent cutting off words which
                // may not be recognized properly.
                int expandWidth = (0.05 * layout.Bounds.Width).Round();

                RectangleF expBounds = layout.UnitBounds;
                expBounds.X -= expandWidth / 2;
                expBounds.Width += expandWidth;

                if (expBounds.X <= 1 && expBounds.Width <= 1)
                {
                    layout.UnitBounds = expBounds;
                }
                 */
            }

            // error checking
            if (layout.Bounds.X < 0 || layout.Bounds.Y < 0 ||
                layout.Bounds.Width <= 0 || layout.Bounds.Height <= 0)
            {
                logger.Error("Wrong bounds: " + layout.Bounds + " images: " + page.ImagesCount);

                float height = page.ImagesCount > 0 ? 1 : 0.1f;

                layout.UnitBounds = new RectangleF(0,0, 1, height);
            }

            // TODO: detect rows

            // TODO: detect header/footer (if any)

            return layout;
        }