Ver Mensaje Individual
  #1 (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: 19 años, 2 meses
Puntos: 6
[Aporte] Crear PDF usando PDFsharp, VBScript

Hola a todos, a continuuacion he utilizado mis conocimientos de VB para traducir y utilizar la libreria PDFsharp en paginas web al vuelo (on the fly).

Es un unico ejemplo que incluye todo lo que permite utilizarce desde la Web,
algo que no pude solucionar fue el insertarle imagenes al PDF.
pues me devuelve el error: BC30652: Es necesaria una referencia al ensamblado 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' que contiene el tipo 'System.Windows.Point'. Agregue una al proyecto.
y desconosco la solucion.
si alguien lo soluciona, se agradece que lo reporte.

sin mas, el codigo: (en dos partes pues es muy largo el codigo, pero es un unico archivo y entre ingles y español xq somos bilingues a lo spanglish )

Default.aspx
Código:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="PdfSharp" %>
<%@ Import Namespace="PdfSharp.Pdf" %>
<%@ Import Namespace="PdfSharp.Drawing" %>
<%@ Import Namespace="PdfSharp.Drawing.Layout" %>

<html>
<head runat="server">
<title>Gabriel Diaz</title>
<script runat="server">
    Sub Page_Load()
        ' Create a new PDF document
        Dim document As PdfDocument = New PdfDocument
        document.Info.Title = "Created with PDFsharp"
        document.Info.Author = "Stefan Lange"
        document.Info.Subject = "traducido a vbscript por Gabriel Diaz"
        ' Create an empty page
        Dim page As PdfPage = document.AddPage
 
        ' Get an XGraphics object for drawing
        Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
 
        ' Draw an ellipse
        Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0))
        gfx.DrawEllipse(pen, 3 * page.Width.Point / 10, 3 * page.Height.Point / 10, 2 * page.Width.Point / 5, 2 * page.Height.Point / 5)
 
        'Draw an arc
        Dim pen2 As New XPen(XColors.Red, 1)
        gfx.DrawArc(pen2, 300, 5, 100, 100, 300, 360) 'pen2, x, y , largo x, largo y, ??, grados que son cubiertos
      
        'draw an rectabgle
        Dim pen3 As New XPen(XColors.Navy, Math.PI)
        gfx.DrawRectangle(pen3, 10, 0, 100, 60)
        gfx.DrawRectangle(XBrushes.DarkOrange, 130, 0, 100, 60)
        gfx.DrawRectangle(pen3, XBrushes.DarkOrange, 10, 80, 100, 60)
        gfx.DrawRectangle(pen3, XBrushes.DarkOrange, 150, 80, 60, 60)
        
        'Draw pies
        Dim pen4 As New XPen(XColors.DarkBlue, 2.5)
        gfx.DrawPie(pen4, 10, 160, 100, 90, -120, 75)
        gfx.DrawPie(XBrushes.Gold, 130, 160, 100, 90, -160, 150)
        gfx.DrawPie(pen4, XBrushes.Gold, 10, 210, 100, 90, 80, 70)
        gfx.DrawPie(pen4, XBrushes.Gold, 150, 240, 60, 60, 35, 290)
        
        'Draw text in different styles
        Const facename As String = "Times New Roman"

        Dim options As New XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.[Default])

        Dim fontRegular As New XFont(facename, 10, XFontStyle.Regular, options)
        Dim fontBold As New XFont(facename, 15, XFontStyle.Bold, options)
        Dim fontItalic As New XFont(facename, 20, XFontStyle.Italic, options)
        Dim fontBoldItalic As New XFont(facename, 25, XFontStyle.BoldItalic, options)

        ' The default alignment is baseline left (that differs from GDI+)
        gfx.DrawString("Times (regular, font 10)", fontRegular, XBrushes.DarkSlateGray, 400, 30)
        gfx.DrawString("Times (bold, font 15)", fontBold, XBrushes.DarkSlateGray, 400, 65)
        gfx.DrawString("Times (italic, font 20)", fontItalic, XBrushes.DarkSlateGray, 400, 100)
        gfx.DrawString("Times (bold italic, font 25)", fontBoldItalic, XBrushes.DarkSlateGray, 400, 135)
        
        
        ' Create a font
        Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold)
 
        ' Draw the text
        gfx.DrawString("Hola, Mundo!", font, XBrushes.Black, New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center)
      
        
        'pagina nueva
        Dim page2 As PdfPage = document.AddPage
        Dim gfx2 As XGraphics = XGraphics.FromPdfPage(page2)
        
        'Show how to align text in the layout rectangle
        Dim rect As New XRect(10, 10, 250, 140)

        Dim font2 As New XFont("Verdana", 10)
        Dim brush As XBrush = XBrushes.Red
        Dim format As New XStringFormat()

        gfx2.DrawRectangle(XPens.YellowGreen, rect)
     
        gfx2.DrawString("TopLeft", font2, brush, rect, format)

        format.Alignment = XStringAlignment.Center
        gfx2.DrawString("TopCenter", font2, brush, rect, format)

        format.Alignment = XStringAlignment.Far
        gfx2.DrawString("TopRight", font2, brush, rect, format)


        format.LineAlignment = XLineAlignment.Center
        format.Alignment = XStringAlignment.Near
        gfx2.DrawString("CenterLeft", font2, brush, rect, format)

        format.Alignment = XStringAlignment.Center
        gfx2.DrawString("Center", font2, brush, rect, format)

        format.Alignment = XStringAlignment.Far
        gfx2.DrawString("CenterRight", font2, brush, rect, format)

        format.LineAlignment = XLineAlignment.Far
        format.Alignment = XStringAlignment.Near
        gfx2.DrawString("BottomLeft", font2, brush, rect, format)

        format.Alignment = XStringAlignment.Center
        gfx2.DrawString("BottomCenter", font2, brush, rect, format)

        format.Alignment = XStringAlignment.Far
        gfx2.DrawString("BottomRight", font2, brush, rect, format)

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