Results 1 to 5 of 5

Thread: PDF Page Label(iTexSharp).

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    PDF Page Label(iTexSharp).

    When creating a PDF document we can set PDF Page labels using iTexsharp (Sample below),
    SetPageLabel

    But its possible to set Page Label for already created PDF document.
    Visual Studio.net 2010
    If this post is useful, rate it


  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: PDF Page Label(iTexSharp).

    You cannot change the existing pdf file directly. However, what you can do is to create a new pdf file from the existing one using the iTextSharp.text.pdf.PdfStamper class and then access the pdfwriter object of the stamper to set page label. Once finish, you can delete the original and rename the new pdf the same as the original.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: PDF Page Label(iTexSharp).

    Thanks stanav, i did the same only..
    i created a copy using SmartPDF and set the page label. Working fine.

    Is it possible to change the "Producer name" of the PDF?
    Visual Studio.net 2010
    If this post is useful, rate it


  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: PDF Page Label(iTexSharp).

    If you're using iTextSharp, you can try by inheriting the iTextSharp.text.Document class and shadow or overload the AddProducer() method. You may also try to write a method and call it instead of calling the AddProducer method... Something like this:
    Code:
    Public Function AddProducerName(ByVal doc As iTextSharp.text.Document, ByVal name As String) As Boolean
            Return doc.Add(New iTextSharp.text.Meta(iTextSharp.text.Element.PRODUCER, name))
        End Function
    Assume you have a iTextSharp.text.Document object doc, instead of doing this:
    Code:
    Dim success as boolean = doc.AddProducer()
    You do this:
    Code:
    Dim success as boolean = AddProducerName(doc, "whatever name you want to give it here")
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: PDF Page Label(iTexSharp).

    hmmm tried,bur not yet got the OutPut...Could you pls tell where am wrong?

    Pls forgive the code is in c#.

    Code:
                String sPDF = @"...\Desktop\Temp-Delete\From\Temp.pdf";
                String sOutPdf = @"...\Desktop\Temp-Delete\From\Label1.pdf";
                iTextSharp.text.pdf.PdfReader oTemp = new iTextSharp.text.pdf.PdfReader(sPDF);
                Document document = new Document(oTemp.GetPageSizeWithRotation(1));
                PdfImportedPage importedPage = null;
                PdfSmartCopy pdfWriter = null;
                pdfWriter = new PdfSmartCopy(document, new System.IO.FileStream(sOutPdf, FileMode.Create));
                pdfWriter.PdfVersion = oTemp.PdfVersion;
                document.AddTitle("SamplePDF");
                document.AddAuthor("XXXXX");
                document.AddCreator("XXXXXXX");
                document.AddKeywords("First testing program for checking the metada in pdf");
                document.AddSubject("XXXXX");
                document.AddHeader("XXXXXX", "XXXXXX");
                document.Add(new Meta(Element.PRODUCER, "Adobe"));
                document.Open();
                for (int i = 1; i <= oTemp.NumberOfPages; i++)
                {
                    importedPage = pdfWriter.GetImportedPage(oTemp, i);
                    pdfWriter.AddPage(importedPage);
                }
                PdfPageLabels oLabel = new PdfPageLabels();
                oLabel.AddPageLabel(1, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);
                pdfWriter.PageLabels = oLabel;
                
                pdfWriter.Close();
                document.Close();
    Visual Studio.net 2010
    If this post is useful, rate it


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width