page vs pdfpage

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v9)  /  page vs pdfpage

DynamicPDF CoreSuite for .NET (v9) Forum

 Feb 14 2018 1:23 PM
What's the difference between the two and where/how would I use each.  PDFpage doesn't seem to have 'elements'.
 Feb 14 2018 2:20 PM
Posted by a ceTe Software moderator
Hello,

Page class is what allows you to add page elements to a page, please take look at the sample code here that shows how to use the Page class.

PdfPage is a read-only object that represents the page of a PdfDocument object. This is typically used when you are importing pages from an existing PDF into a new PDF. PdfDocument.GetPage() used in the second sample here  shows how to import a page from an existing PDF. PdfPage class does not allow for accessing the page elements hence there is no Elements property.

Thanks,
ceTe Software Support Team.
 Feb 14 2018 2:27 PM
Don't see the  examples.
I'm trying to bring in numerous  2 and 3 page PDFs, add barcodes and merge them in to one big PDF for printing.  I think, because I'm importing, I have to bring them in as a PDFdocument.  If I do that I can't add the barcode as you say pdfpage and pdfdocument are read only.  Can I convert them to page and document?

 Feb 15 2018 12:16 PM
Posted by a ceTe Software moderator
Hello,

Yes, the PdfPage object is read-only. You can achieve your requirements by importing a page from the existing PDF using ImportedPage class and add the contents to the page using respective page elements. Add this imported page to the MergeDocument object. Below is the code sample.

           string PdfFolder = @"E:\temp\PDF\";
            string[] fileList = Directory.GetFiles(PdfFolder, "*.pdf");
            MergeDocument finalDocument = new MergeDocument();

            for (int i = 0; i < fileList.Length; i++)
            {
                string filepath = fileList[i];
                PdfDocument pdf = new PdfDocument(fileList[i]);
                for (int j = 0; j < pdf.Pages.Count; j++)
                {
                    ImportedPage page = new ImportedPage(pdf.Pages[0]);
                    Code128 barcodeObj = new Code128("123456789", 100, 100, 300);
                    page.Elements.Add(barcodeObj);
                    finalDocument.Pages.Add(page);
                }
            }
            finalDocument.Draw("C:\\Temp\\MyDocument.pdf");

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 3:32 AM.