PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Sep 27, 2024 9:16 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Jul 17, 2010 5:20 am 
Offline
User avatar

Joined: Sat Jul 17, 2010 4:58 am
Posts: 3
Hello everyone, I have used my knowledge of VB to create PDF in Web pages on the fly.
It is a unique example that includes everything that is allowed to use the web examples.
Unfortunately, I could not get it from entering images in the PDF, as I returned the following error
BC30652: This requires a reference to assembly 'WindowsBase, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' containing the type 'System.Windows.Point'. Add one to the project.
And I do not know the solution
To run the example you must have a file "PdfSharp-WPF.dll" in the BIN directory. Remember that if a virtual directory, the folder BIN going in the server root.
(.../wwwroot/BIN/PdfSharp-WPF.dll)

Without more, the example

Code:
<%@ 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 = "Translated to VBScript"
        ' 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)
       
        '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)
     
       
        'New Page
        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)
                       
        '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
        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)
       
        'Long text
        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)
       
        'Foot Page
        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)
       
        'Save the document in a Specific Folder
        'Dim filename As String = "C:\Inetpub\wwwroot\PDF\funciona1\HelloWorld.pdf"
        'document.Save(filename)
       
        'Open the PDF in the web Browser
        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>


Attachments:
File comment: The attached file contains the example and the DLL "PdfSharp-WPF.dll" ready to use
PDFsharp.zip [240.05 KiB]
Downloaded 640 times
Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 19, 2010 7:22 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3110
Location: Cologne, Germany
The error message "This requires a reference to assembly 'WindowsBase'" means:
This requires a reference to assembly 'WindowsBase'.

Your assembly references another assembly which in turn uses WindowsBase and that uses classes from WindowsBase in its interfaces.
Therefore you must reference WindowsBase to use that assembly.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 20, 2010 2:24 am 
Offline
User avatar

Joined: Sat Jul 17, 2010 4:58 am
Posts: 3
thanks for the reply, I really don't know how to refer to WindowsBase, and I have a little frustrated my inability to solve the problem, it must be possible from WebForms, just not how. think, think ...


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 20, 2010 8:07 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3110
Location: Cologne, Germany
For VB projects: Open the Properties of your project, go to the References tab and click the Add button ...

For other projects: in the Solution Explorer, rightclick the References node and select Add Reference from the menu ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 53 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group