Ver Mensaje Individual
  #4 (permalink)  
Antiguo 08/05/2013, 03:21
cbr20
 
Fecha de Ingreso: abril-2013
Mensajes: 37
Antigüedad: 11 años
Puntos: 1
Respuesta: Introducir dos pdf en otro usando itextsahrp

Hola de nuevo. Utilice el enlace que me enviaste, pero esta en C#.


He traducido a vb.net pero me da error en un metodo que al parecer no exsiste, y hay discrepancia de tipos etc.

Aqui les dejo el codigo de C# haver si alguien me lo puede traducir a vb.net, yo lo intente, pero algo falla por que me da error.


internal static bool Merge(string strFileTarget, string [] arrStrFilesSource)
{ bool blnMerged = false;

// Crea el PDF de salida
try
{ using (System.IO.FileStream stmFile = new System.IO.FileStream(strFileTarget, System.IO.FileMode.Create))
{ Document objDocument = null;
PdfWriter objWriter = null;

// Recorre los archivos
for (int intIndexFile = 0; intIndexFile < arrStrFilesSource.Length; intIndexFile++)
{ PdfReader objReader = new PdfReader(arrStrFilesSource[intIndexFile]);
int intNumberOfPages = objReader.NumberOfPages;

// La primera vez, inicializa el documento y el escritor
if (intIndexFile == 0)
{ // Asigna el documento y el generador
objDocument = new Document(objReader.GetPageSizeWithRotation(1));
objWriter = PdfWriter.GetInstance(objDocument, stmFile);
// Abre el documento
objDocument.Open();
}
// Añade las páginas
for (int intPage = 0; intPage < intNumberOfPages; intPage++)
{ int intRotation = objReader.GetPageRotation(intPage + 1);
PdfImportedPage objPage = objWriter.GetImportedPage(objReader, intPage + 1);

// Asigna el tamaño de la página
objDocument.SetPageSize(objReader.GetPageSizeWithR otation(intPage + 1));
// Crea una nueva página
objDocument.NewPage();
// Añade la página leída
if (intRotation == 90 || intRotation == 270)
objWriter.DirectContent.AddTemplate(objPage, 0, -1f, 1f, 0, 0,
objReader.GetPageSizeWithRotation(intPage + 1).Height);
else
objWriter.DirectContent.AddTemplate(objPage, 1f, 0, 0, 1f, 0, 0);
}
}
// Cierra el documento
if (objDocument != null)
objDocument.Close();
// Cierra el stream del archivo
stmFile.Close();
}
// Indica que se ha creado el documento
blnMerged = true;
}
catch(Exception objException)
{ System.Diagnostics.Debug.WriteLine(objException.Me ssage);
}
// Devuelve el valor que indica si se han mezclado los archivos
return blnMerged;
}



Este codigo se consiguio gracias a la aportacion de drako_darpan, el enlace esta en la respuesta de arriba (una vez en el enlace id al segundo enlace, el que dice que une dos pdf) y al final llegais a este link:
http://www.elguille.info/NET/WebServices/deCSaVB_web.aspx

en el cual esta este codigo de C#. En fin, que lo traduje con un programa pero algo no se traudjo bien o algo falla en el metodo.

Asi que aqui les dejo mi traduccion comentada en las lineas que dan error y que error dan.




Friend Shared Function Merge(ByVal strFileTarget As String, ByVal arrStrFilesSource() As String) As Boolean
Dim blnMerged As Boolean = False

' Crea el PDF de salida
Try
Using stmFile As System.IO.FileStream = New System.IO.FileStream(strFileTarget, System.IO.FileMode.Create)
Dim objDocument As Document = Nothing
Dim objWriter As PdfWriter = Nothing
' Recorre los archivos

For intIndexFile As Integer = 0 To arrStrFilesSource.Length - 1
Dim IntegerIndexFile As Integer
Dim objReader(0 To IntegerIndexFile - 1) As PdfReader

Dim intNumberOfPages As Integer = objReader(0 To IntegerIndexFile - 1).NumberOfPages
' La primera vez, inicializa el documento y el escritor
If IntegerIndexFile = 0 Then
' Asigna el documento y el generador

''LINEA ERROR: objDocument = New Document(objReader.GetPageSizeWithRotation(1))
''vale, el error que me sale es: GetPageSizeWithRotation(1) is not a member of System.Array
objDocument = New Document(objReader.GetPageSizeWithRotation(1))


objWriter = PdfWriter.GetInstance(objDocument, stmFile)
' Abre el documento
objDocument.Open()

End If
' Añade las páginas
For IntegerPage As Integer = 0 To intNumberOfPages - 1

''LINEA ERROR: Dim intRotation As Integer = objReader.GetPageRotation(IntegerPage + 1)
''Error: GetPageRotation is not a member of System.Array
Dim intRotation As Integer = objReader.GetPageRotation(IntegerPage + 1)

''LINEA ERROR: Dim objPage As PdfImportedPage = objWriter.GetImportedPage(objReader, IntegerPage + 1)
''Error: Value of type '1-dimensional array of iTextSharp.text.pdf.PdfReader' cannot be converted to 'iTextSharp.text.pdf.PdfReader'
Dim objPage As PdfImportedPage = objWriter.GetImportedPage(objReader, IntegerPage + 1)

' Asigna el tamaño de la página

''LINEA ERROR: objDocument.SetPageSize(objReader.GetPageSizeWithR otation(IntegerPage + 1))
''Error: GetPageSizeWithRotation(1) is not a member of System.Array
objDocument.SetPageSize(objReader.GetPageSizeWithR otation(IntegerPage + 1))

' Crea una nueva página
objDocument.NewPage()
' Añade la página leída
Dim IntegerRotation As Integer
If IntegerRotation = 90 OrElse IntegerRotation = 270 Then

''LINEA ERROR: esta de abajo tan sumuamente larga
''Error: GetPageSizeWithRotation(1) is not a member of System.Array
objWriter.DirectContent.AddTemplate(objPage, 0, -1.0F, 1.0F, 0, 0, objReader.GetPageSizeWithRotation(IntegerPage + 1).Height)

Else
objWriter.DirectContent.AddTemplate(objPage, 1.0F, 0, 0, 1.0F, 0, 0)

End If

Next
' Cierra el documento
If objDocument IsNot Nothing Then
objDocument.Close()
End If
' Cierra el stream del archivo
stmFile.Close()

Next
' Indica que se ha creado el documento
blnMerged = True

End Using
Catch objException As Exception
System.Diagnostics.Debug.WriteLine(objException.Me ssage)

End Try

' Devuelve el valor que indica si se han mezclado los archivos
Return blnMerged



End Function




Bueno, espero que os sirvan estos codigos.

Repito, agradeceria cualquier ayuda con las lineas de error, por si estan mal traducidas, si se dev¡ben poner de otra manera, si hay que usar otra forma de hacerlas ....... Cualquier aportacion sera bienvenida.

Gracias por ayudar