Пример #1
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();
        }
Пример #2
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);
            }
        }
Пример #3
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PDFFile file = new PDFFile(input);

            PDFPageContent[] content = file.ExtractPageContent(0, file.PageCount - 1);
            file = null;

            PDFFixedDocument document = new PDFFixedDocument();
            PDFPage          page1    = document.Pages.Add();

            // Draw the same page content 4 times on the new page, the content is scaled to half and flipped.
            page1.Canvas.DrawFormXObject(content[0],
                                         0, 0, page1.Width / 2, page1.Height / 2);
            page1.Canvas.DrawFormXObject(content[0],
                                         page1.Width / 2, 0, page1.Width / 2, page1.Height / 2, 0, PDFFlipDirection.VerticalFlip);
            page1.Canvas.DrawFormXObject(content[0],
                                         0, page1.Height / 2, page1.Width / 2, page1.Height / 2, 0, PDFFlipDirection.HorizontalFlip);
            page1.Canvas.DrawFormXObject(content[0],
                                         page1.Width / 2, page1.Height / 2, page1.Width / 2, page1.Height / 2,
                                         0, PDFFlipDirection.VerticalFlip | PDFFlipDirection.HorizontalFlip);

            PDFPage page2 = document.Pages.Add();

            // Draw 3 pages on the new page.
            page2.Canvas.DrawFormXObject(content[0],
                                         0, 0, page2.Width / 2, page2.Height / 2);
            page2.Canvas.DrawFormXObject(content[1],
                                         page2.Width / 2, 0, page2.Width / 2, page2.Height / 2);
            page2.Canvas.DrawFormXObject(content[2],
                                         0, page2.Height, page2.Height / 2, page2.Width, 90);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "pageimposition.pdf") };
            return(output);
        }