PDA

Ver la Versión Completa : Poner contraseña a un pdf


Angel.Matilla
19-05-2014, 17:42:52
Con este código:
TQRPDFDocumentFilter *filtro = new TQRPDFDocumentFilter(cInforme);
filtro->AddFontMap("Arial:Helvetica");
filtro->StartConcat();
Informe->ExportToFilter(filtro);
filtro->EndConcat();
delete filtro;genero un pdf a partir de un QR. Quiero ir un paso más allá: ¿Puedo establecer mediate código un contraseña a la hora de abrir el documento así creado?

Angel.Matilla
19-05-2014, 18:02:42
Evidentemente aunque pido ayuda sigo buscando. San google me ha dado una dirección interesante: iText Sharp (http://itextsharp.sourceforge.net/tutorial/index.html). En uno de los enlaces de este sitio (http://www.svcommunity.org/forum/freeware/itextsharp-%28crea-documentos-pdf-desde-codigo-con-net%29/) viene este código:
1: using System;
2: using System.IO;
3:
4: using iTextSharp.text;
5: using iTextSharp.text.pdf;
6:
7:
8: namespace iTextSharp.tutorial.Chap01
9: {
10: /// <summary>
11: /// Encryption
12: /// </summary>
13: public class Chap0110
14: {
15: public Chap0110()
16: {
17: Console.WriteLine("Chapter 1 example 10: encryption 128 bits");
18:
19: Document document = new Document(PageSize.A4, 50, 50, 50, 50);
20: try
21: {
22: PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0110.pdf", FileMode.Create));
23: writer.SetEncryption(PdfWriter.STRENGTH128BITS, "userpass", "ownerpass", PdfWriter.AllowCopy | PdfWriter.AllowPrinting);
24: document.Open();
25: document.Add(new Paragraph("This document is Top Secret!"));
26: document.Close();
27: }
28: catch (Exception de)
29: {
30: Console.Error.WriteLine(de.StackTrace);
31: }
32:
33: }
34: }
35: }No sé si sería fácil adaptarla a C++.

ecfisa
19-05-2014, 20:29:28
Hola Angel.Matilla.

Sin saber C#, te diría que es muy sencillo adaptar ese código a C++.
El verdadero problema y que hace inútil la traducción, es que aparentemente no existe una versión de iText que trabaje en C++...

Saludos :)

Angel.Matilla
20-05-2014, 09:37:38
Muchas gracias.

Angel.Matilla
20-05-2014, 10:42:41
He seguido buscando y encontré un mensaje (http://clubdelphi.com/foros/showpost.php?p=427305&postcount=22) de un hilo en el que se cita un componente TDFCreator, pero está escrito para Delphi. ¿Alguien lo ha traducido a Borland C++ 5 ó 6 o puede ayudarme a trasladarlo a este último? Lo agradecería infinito.