Results 1 to 3 of 3

Thread: Using ASPPDF via COM with C#.net

  1. #1
    Join Date
    Jun 2009
    Posts
    35

    Post Using ASPPDF via COM with C#.net

    Hostek currently supports many COM components that have been used for years with classic ASP, ASPPDF being one of them. For sites using ASP.Net, you can easily leverage the power of these libraries thanks to many of the improvements to COM Interop in .Net version 4.

    Below is an example taken from the ASPPDF documents:

    VScript Version (for comparison)
    ---------------------------
    Code:
    Set Pdf = Server.CreateObject("Persits.Pdf")
    Set Doc = Pdf.CreateDocument
    
    Doc.Title = "AspPDF Chapter 3 Hello World Sample"
    Doc.Creator = "John Smith"
    
    Set Page = Doc.Pages.Add
    
    Set Font = Doc.Fonts("Helvetica")
    
    Params = "x=0; y=650; width=612; alignment=center; size=50"
    Page.Canvas.DrawText "Hello World!", Params, Font
    
    Filename = Doc.Save( Server.MapPath("hello.pdf"), False )
    
    Response.Write "Success! Download your PDF file <A HREF=" & Filename & ">here</A>"
    ---------------------------

    Below is the same example, converted from VBScript to C# with comments on each line explaining the changes that were needed.

    C# Version (converted from above)
    ---------------------------
    Code:
    // For the C# version, a semi-colon is added to the end of every line to complete the statement.
    // All variables must be declared with their data-type.
    // For COM objects, the keyword 'dynamic' is used to allow the types to be determined at runtime.
    
    // VBScript keyword 'Set' removed.  Variable 'Pdf' declared as dynamic.
    dynamic Pdf = Server.CreateObject("Persits.Pdf");
    
    // VBScript keyword 'Set' removed.  Variable 'Pdf' declared as dynamic.
    dynamic Doc = Pdf.CreateDocument();
    
    Doc.Title = "AspPDF Chapter 3 Hello World Sample";
    Doc.Creator = "John Smith";
    
    // VBScript keyword 'Set' removed.  Variable 'Pdf' declared as dynamic.
    // Parentheses added to indicate that 'Add' is a method, not a property.
    dynamic Page = Doc.Pages.Add();
    
    // VBScript keyword 'Set' removed.  Variable 'Pdf' declared as dynamic.
    dynamic Font = Doc.Fonts("Helvetica");
    
    // variable 'Params' declared as 'string'.
    string Params = "x=0; y=650; width=612; alignment=center; size=50";
    
    // Parentheses added to indicate that 'DrawText' is a method.
    Page.Canvas.DrawText("Hello World!", Params, Font);
    
    // Variable 'Filename' declared as 'string'.
    // VBScript keyword 'False'(case-insensitive) changed to C# keyword 'false' (lower-case).
    string Filename = Doc.Save(Server.MapPath("hello.pdf"), false);
    
    // Parentheses added since 'Write' is a method.
    // VBScript string concatenation operator '&' replaced with C# string concatenation operator '+'.
    Response.Write("Success! Download your PDF file <A HREF=" + Filename + ">here</A>");
    ---------------------------

    Using similar conversions, it should be possible to convert just about any of the VBScript(classic ASP) examples for use in C#. Not only for ASPPDF, but also for many other COM components that are available.

  2. #2

    Default

    These look like a little difficult, can I generate an image in asp .net?

  3. #3
    Join Date
    Dec 2010
    Posts
    25

    Default

    Yes, simple images can be generated using the System.Drawing and System.Drawing.Imaging namespaces.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •