Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/07/2010, 21:27
Avatar de gakutaru
gakutaru
 
Fecha de Ingreso: agosto-2005
Ubicación: frente a mi NtbK
Mensajes: 239
Antigüedad: 18 años, 7 meses
Puntos: 6
Respuesta: [Aporte] Crear PDF usando PDFsharp, VBScript

Código:
                
        'Show how to get text metric information
        Const style As XFontStyle = XFontStyle.Regular
        Dim font3 As New XFont("Times New Roman", 95, style)

        Const text As String = "Desert"
        Const x As Double = 300, y As Double = 100 'posicion del texto
        Dim size As XSize = gfx.MeasureString(text, font3)

        Dim lineSpace As Double = font3.GetHeight(gfx)
        Dim cellSpace As Integer = font3.FontFamily.GetLineSpacing(style)
        Dim cellAscent As Integer = font3.FontFamily.GetCellAscent(style)
        Dim cellDescent As Integer = font3.FontFamily.GetCellDescent(style)
        Dim cellLeading As Integer = cellSpace - cellAscent - cellDescent

        ' Get effective ascent
        Dim ascent As Double = lineSpace * cellAscent / cellSpace
        gfx2.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent)

        ' Get effective descent
        Dim descent As Double = lineSpace * cellDescent / cellSpace
        gfx2.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent)

        ' Get effective leading
        Dim leading As Double = lineSpace * cellLeading / cellSpace
        gfx2.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading)


        ' Draw text half transparent
        Dim color As XColor = XColors.DarkSlateBlue
        color.A = 1.2
        gfx2.DrawString(text, font3, New XSolidBrush(color), x, y)
        
        'ingresar textos
       Dim text2 As String = "El latín es una lengua de la rama itálica que fue hablada en la antigua"
        text2 &= " República Romana y el Imperio romano desde el siglo IX a. C. "
        text2 &= "Su nombre deriva de la existencia de una zona geográfica de la península itálica"
        text2 &= " denominada Vetus Latium o 'Antiguo llano' (hoy llamado Lacio)."
        text2 &= "Ganó gran importancia con la expansión del estado romano, siendo lengua oficial del imperio"
        text2 &= " en gran parte de Europa y África septentrional, junto con el griego. Como las demás lenguas indoeuropeas en general, "
        text2 &= " el latín era una lengua flexiva de tipo fusional con un mayor grado de síntesis nominal que las actuales lenguas romances,"
        text2 &= " en la cual dominaba la flexión mediante sufijos, combinada en determinadas veces con el"
        text2 &= "uso de las preposiciones; mientras que en las lenguas modernas derivadas dominan las construcciones analíticas con preposiciones, habiéndose reducido"
        text2 &= "la flexión nominal a marcar sólo el género y el plural, conservando los casos de declinación"
        text2 &= " sólo en los pronombres personales (teniendo estos un orden fijo en los sintagmas verbales).1"

        Dim tf As New XTextFormatter(gfx2)

        Dim rect2 As New XRect(40, 200, 250, 220)
        font = New XFont("Times New Roman", 10, XFontStyle.Bold)
        gfx2.DrawRectangle(XBrushes.SeaShell, rect)
        'tf.Alignment = ParagraphAlignment.Left
        tf.DrawString(text2, font, XBrushes.Black, rect2, XStringFormats.TopLeft)

        rect2 = New XRect(310, 200, 250, 220)
        gfx2.DrawRectangle(XBrushes.SeaShell, rect)
        tf.Alignment = XParagraphAlignment.Right
        tf.DrawString(text2, font, XBrushes.Black, rect2, XStringFormats.TopLeft)

        rect2 = New XRect(40, 500, 250, 220)
        gfx2.DrawRectangle(XBrushes.SeaShell, rect)
        tf.Alignment = XParagraphAlignment.Center
        tf.DrawString(text2, font, XBrushes.Black, rect2, XStringFormats.TopLeft)

        rect2 = New XRect(310, 500, 250, 220)
        gfx2.DrawRectangle(XBrushes.SeaShell, rect)
        tf.Alignment = XParagraphAlignment.Justify
        tf.DrawString(text2, font, XBrushes.Black, rect2, XStringFormats.TopLeft)
 
        'pie de pagina
        Dim rect3 As New XRect(New XPoint(), gfx.PageSize)
        rect3.Inflate(-10, -15)
        Dim font4 As New XFont("Verdana", 14, XFontStyle.Bold)
        gfx.DrawString(Title, font4, XBrushes.MidnightBlue, rect3, XStringFormats.TopCenter)

        rect3.Offset(0, 5)
        font4 = New XFont("Verdana", 8, XFontStyle.Italic)
        Dim format2 As New XStringFormat()
        format2.Alignment = XStringAlignment.Near
        format2.LineAlignment = XLineAlignment.Far
        gfx.DrawString("creado por " & PdfSharp.ProductVersionInfo.Producer, font4, XBrushes.Blue, rect3, format2)
        gfx2.DrawString("creado por " & PdfSharp.ProductVersionInfo.Producer, font4, XBrushes.Blue, rect3, format2)
       
        font4 = New XFont("Verdana", 8)
        format2.Alignment = XStringAlignment.Center
        gfx.DrawString(document.PageCount.ToString(), font4, XBrushes.DarkOrchid, rect3, format2)
        gfx2.DrawString(document.PageCount.ToString(), font4, XBrushes.DarkOrchid, rect3, format2)
       
        document.Outlines.Add(Title, page, True)
        
        ' guardar el documento en un directorio especifico
        'Dim filename As String = "C:\Inetpub\wwwroot\PDF\funciona1\HelloWorld.pdf"
        ' document.Save(filename)
        
        ' mostrar el pdf en el explorador
        Dim stream As New MemoryStream()
        document.Save(stream, False)
        Response.Clear()
        Response.ContentType = "application/pdf"
        Response.AddHeader("content-length", stream.Length.ToString())
        Response.BinaryWrite(stream.ToArray())
        Response.Flush()
        stream.Close()
        Response.[End]()
 
    
    End Sub
</script>
</head>
<body>
</body>
</html>
Algunos errores...

necesitan tener la libreria, pueden descargarla de la pagina del autor, el archivo de nombre: "PdfSharp-WPF.dll" y recuerden ubicarla en su directorio BIN, recuerden que si es directorio virtual la carpeta BIN va en la raiz del servidor
(.../wwwroot/BIN/PdfSharp-WPF.dll)

pueden descargar el archivo adjunto, que incluye el ejemplo con todo lo que se puede utilizar y la libreria PDFsharp hasta esta fecha (16-julio del 2010)
http://www.megaupload.com/?d=O3D72B59

Última edición por gakutaru; 16/07/2010 a las 22:05