begin process at 2010 02 10 03:59:12
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Astuces

 > ITEXTSHARP - PDF PERMISION EDIT

ITEXTSHARP - PDF PERMISION EDIT


 Information sur la source

Note :
Aucune note
Catégorie :Astuces Source .NET ( DotNet ) Classé sous :ITextSharp, PDF, Permission, Crypter PDF, Encrypter PDF Niveau :Débutant Date de création :12/10/2008 Date de mise à jour :14/10/2008 14:29:30 Vu / téléchargé :3 978 / 274

Auteur : Zaltez

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note


 Description

Cliquez pour voir la capture en taille normale
je cherchais comment modifier les Permissions sur un PDF. C'est chose faite. Voila ce que j'ai pu trouver comme réponse en parcourant la toile.

Ce petit bout de code permet d'illustrer comment modifier les permissions des utilisateurs sur un pdf avec l'assembly ITextSharp.

En réaliter avec ITextSharp on ne peut éditer un PDF mais seulement faire une copie a l'identique avec les nouvelles permissions.

Dans le Zip vous trouverez un petit programme pour tester la  toute petite classe PDFEdit

Ne pas oublier de télécharger la DLL ITextSharp a cette adresse : http://sourceforge.net/projects/itextsharp/








Source

  • class PdfEdit
  • {
  • public PdfEdit()
  • {
  • }
  • public enum permission
  • {
  • Assembly = PdfWriter.ALLOW_ASSEMBLY,
  • Copy = PdfWriter.ALLOW_COPY,
  • DegradedPrinting = PdfWriter.ALLOW_DEGRADED_PRINTING,
  • FillIn = PdfWriter.ALLOW_FILL_IN,
  • ModifyAnnotation = PdfWriter.ALLOW_MODIFY_ANNOTATIONS,
  • ModifyContent = PdfWriter.ALLOW_MODIFY_CONTENTS,
  • Printing = PdfWriter.ALLOW_PRINTING,
  • ScreenReaders = PdfWriter.ALLOW_SCREENREADERS
  • };
  • public enum encryption
  • {
  • Standart_128 = PdfWriter.STANDARD_ENCRYPTION_128,
  • Standart_40 = PdfWriter.STANDARD_ENCRYPTION_40
  • };
  • public static void PdfEditPermission(string SourcePdfFile, string TargetPdfFile, string Login, string Password, int[] Permission, int Encryption)
  • {
  • PdfReader _Reader = new PdfReader(SourcePdfFile);
  • int pageNumber = _Reader.NumberOfPages;
  • Document _Document = new Document(_Reader.GetPageSizeWithRotation(1));
  • PdfWriter writer = PdfWriter.GetInstance(_Document, new FileStream(TargetPdfFile, FileMode.Create));
  • PdfEncryption(writer, Login, Password, Permission, Encryption);
  • _Document.Open();
  • PdfContentByte _ContentPDF = writer.DirectContent;
  • PdfImportedPage _Page;
  • int rotation = 0;
  • for (int i = 1; i <= pageNumber; i++)
  • {
  • _Document.SetPageSize(_Reader.GetPageSizeWithRotation(i));
  • _Document.NewPage();
  • _Page = writer.GetImportedPage(_Reader, i);
  • rotation = _Reader.GetPageRotation(i);
  • if (rotation == 90 || rotation == 270)
  • _ContentPDF.AddTemplate(_Page, 0, -1f, 1f, 0, 0, _Reader.GetPageSizeWithRotation(i).Height);
  • else
  • _ContentPDF.AddTemplate(_Page, 1f, 0, 0, 1f, 0, 0);
  • }
  • _Document.Close();
  • }
  • private static void PdfEncryption(PdfWriter writer, string Login, string Password, int[] bufferPermission, int Encryption)
  • {
  • int permission = 0;
  • foreach (int i in bufferPermission)
  • {
  • permission |= (int)i;
  • }
  • writer.SetEncryption(Encryption, Login, Password, permission);
  • }
  • }
class PdfEdit
    {
        public PdfEdit()
        {

        }

        public enum permission
        {
            Assembly = PdfWriter.ALLOW_ASSEMBLY,
            Copy = PdfWriter.ALLOW_COPY,
            DegradedPrinting = PdfWriter.ALLOW_DEGRADED_PRINTING,
            FillIn = PdfWriter.ALLOW_FILL_IN,
            ModifyAnnotation = PdfWriter.ALLOW_MODIFY_ANNOTATIONS,
            ModifyContent = PdfWriter.ALLOW_MODIFY_CONTENTS,
            Printing = PdfWriter.ALLOW_PRINTING,
            ScreenReaders = PdfWriter.ALLOW_SCREENREADERS
        };

        public enum encryption
        {
            Standart_128 = PdfWriter.STANDARD_ENCRYPTION_128,
            Standart_40 = PdfWriter.STANDARD_ENCRYPTION_40
        };

        public static void PdfEditPermission(string SourcePdfFile, string TargetPdfFile, string Login, string Password, int[] Permission, int Encryption)
        {
            PdfReader _Reader = new PdfReader(SourcePdfFile); 

            int pageNumber = _Reader.NumberOfPages;

            Document _Document = new Document(_Reader.GetPageSizeWithRotation(1));
            PdfWriter writer = PdfWriter.GetInstance(_Document, new FileStream(TargetPdfFile, FileMode.Create));

            PdfEncryption(writer, Login, Password, Permission, Encryption);

            _Document.Open();

            PdfContentByte _ContentPDF = writer.DirectContent;
            PdfImportedPage _Page;
            int rotation = 0;

            for (int i = 1; i <= pageNumber; i++)
            {
                _Document.SetPageSize(_Reader.GetPageSizeWithRotation(i));

                _Document.NewPage();

                _Page = writer.GetImportedPage(_Reader, i);

                rotation = _Reader.GetPageRotation(i);

                if (rotation == 90 || rotation == 270)
                    _ContentPDF.AddTemplate(_Page, 0, -1f, 1f, 0, 0, _Reader.GetPageSizeWithRotation(i).Height);
                else
                    _ContentPDF.AddTemplate(_Page, 1f, 0, 0, 1f, 0, 0);
            }

            _Document.Close();
        }

        private static void PdfEncryption(PdfWriter writer, string Login, string Password, int[] bufferPermission, int Encryption)
        {
            int permission = 0;

            foreach (int i in bufferPermission)
            {
                permission |= (int)i;
            }

            writer.SetEncryption(Encryption, Login, Password, permission);
        }

    }

 Conclusion

Voici quelques liens qui m'ont été utiles :

* http://itextsharp.sourceforge.net/tutorial/ch01.ht ml

* http://itextsharp.sourceforge.net/examples/Chap011 0.cs


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) SUBTITLE REVERSE .SRT
Source avec Zip Source avec une capture Source .NET (Dotnet) MEDIA-COVER
Source avec Zip Source avec une capture Source .NET (Dotnet) QUIZZ VERBES IRREGULIERS D'ANGLAIS

 Sources de la même categorie

Source avec une capture Source .NET (Dotnet) AJOUTER DES BYTES À UN EXECUTABLE par t0fx
Source .NET (Dotnet) COPIER/ COLLER DATAGRID (COPY/PASTE) par jamesbidon
Source avec Zip Source .NET (Dotnet) MECANISME DE SYNCHRONISATION DE THREAD - MONITOR, MUTEX, SEM... par jesusonline
Source .NET (Dotnet) EVENTHANDLERS GÉNÉRIQUES par ricklekebekoi
Source avec Zip Source .NET (Dotnet) TRAITER UN FOREACH EN PARALLÈLE par maitredede

 Sources en rapport avec celle ci

Source avec Zip Source .NET (Dotnet) CONVERTISSEUR PDF par crack_xp
Source avec Zip Source .NET (Dotnet) UTILISATION DES FICHIERS FDF EN C# (SORTE DE PUBLIPOSTAGE PO... par rabbiwan

Commentaires et avis

Commentaire de petifa le 12/10/2008 22:36:10

slt Zaltez, merci pour les site,
ta source m'a l'air classe et très utile
même sans commentaires ça se comprend,

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

utilisation de itextsharp [ par sachie ] Bonjour à tous!J'ai besoin par programme pdf de désigner un pdf et de le transformer en jpeg, une page= un jpeg en gros!Après recherche j'ai lu  que l itextsharp - pdf [ par atro17 ] Bonjour,je suis débutant en programmation et je dois, dans le cadre d'un projet, convertir les données d'un formulaire en un document PDF. Après quelq Générer des pdf avec itextsharp [ par nadibb ] Bonjour, Je voudrais savoir si c'est possible de lire un pdf sur l'invite de commande en utilisant itextsharp, ou bien lire un pdf déjà existant!! Mer fichier pdf avec iTextsharp [ par laymouna98 ] salut à tous j'utilise iTextsharp pour générer des fichier pdf, ca va ca marche, mais mon problème lorsque j'ajoute des page au document pdf le conten erreur file does not begin with '%PDF-' avec utilisation AxAcroPDF [ par wodan ] Afin de visualiser un fichier PDF dans mon application winform j'utilise l'ActiveX AxAcroPDF fourni par Abode.Or lorsque je veux visualiser mon PDF à Crystal report [ par nnfabrizio ] Bonjour, j'ai une application qui génére 400 PDF , le soucis est le suivant , le temps de génération de  ces fichiers mettent énormement de temps pour faire la traduction d'un pdf anglais vers francais, puis son édition [ par magnesy1 ] bonjour ,je suis nouveau sur le siteje ne suis pas développeur ,je suis  inculque en la matière je suis ingénieur du son , voila j'ai besoin d'aide,je Ouverture d'un fichier PDF [ par kdior ] Bonjour, J'ai une application développée en Csharp qui fait appel à un pdf (ici Help.pdf) avec la fonction suivante : System.Diagnostics.ProcessSt Cute pdf Writer [ par T103 ] Bonjour,J'ai une application en c# sur laquelle je voudrais imprimer un fichier doc en pdf sans avoir la boite de dialogue "Enregistrer sous" de CuteP


Nos sponsors


Sondage...

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,967 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales