We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Evaluating Aspose.PDF for Dummies

I used the MSI and will be using classic ASP. So I installed Aspose.PDF with the .msi. Then I registered the following for COM Interop via a Command Prompt.

regasm “C:\Program Files (x86)\Aspose\Aspose.PDF for .NET\bin\net2.0\Aspose.PDF.dll” /codebase

regasm “C:\Program Files (x86)\Aspose\Aspose.PDF for .NET\bin\net2.0\Aspose.PDF.dll” /tlb: “C:\Program Files (x86)\Aspose\Aspose.PDF for .NET\bin\net2.0\Aspose.PDF.tlb” /codebase

I inserted the following line in my classic ASP page (ran locally via IIS):

Dim pdf
Set pdf = CreateObject(“Aspose.PDF.Generator.Pdf”)

When I launch the page, I get the following error:

ActiveX component can’t create object: ‘Aspose.PDF.Generator.Pdf’

Any ideas? What am I missing?

@Toberville

Thanks for getting back to us.

In case you are using Aspose.PDF in Classic ASP and need to use many of the Aspose.Pdf Classes, you may create a COM Wrapper. For further information in this regard, you may please visit following article:

We hope this will help you to use API without any issue in your environment. In case any other issue occurs, please feel free to let us know.

Do you have an example of a Aspose.PDF ComWrapper Assembly? My needs are simple. Read a one page PDF, place a picture and text inside the PDF. Dave the PDF. All in classic asp.

Thanks,

I really do not understand the ‘Use Aspose.PDF via COM Interop’ … I learn faster by example.

@Toberville

We are looking into your requirement and will share our feedback in a while.

Hello Asad:

I am able to regasm Aspose.PDF but can not make a TLB. I am using Classic ASP. Can you recommend my next steps. How to I make a COM Wrapper for Aspose.PDF?

I am just a beginner so anything will help.

@Toberville

The TLB can be created using following command:

regasm Aspose.PDF.dll \codebase /tlb:ComComponent.tlb

Please note that not all classes of the API can be exported to TLB as they are generic. After running the command, you will also be able to see the list of classes which are not exported.TLB_Errors.png (14.2 KB)

In order to create a COM Wrapper, you may please:

  • Create a Class Library Project in Visual Studio
  • Add reference to latest version of Aspose.PDF for .NET
  • Create methods in your Class which you want to use in ASP Application
  • Sign your assembly with public/private key by following the link or going into Signing Tab in project properties
  • Build the project and register assembly using regasm. For example, regasm SampleWrapperAspose.dll \codebase
  • Once your wrapper is register, you can use it in your ASP Application.

For an instance, the method public void SavePDF(string outputPath) can be used like following:

<%
Dim pdfHelper
Set pdfHelper = CreateObject("SampleWrapperAspose.Test")
pdfHelper.SavePDF "C:\temp\test.pdf" 
%>

We hope this information would help and in case you need further assistance, please feel free to let us know.

Asad this is excellent. (Is this your first name?) I am setting up my work environment now. A few questions.

  1. Am I using the correct regasm? I am developing on my local windows 10, NET 2.0. It looks like Aspose is located in Program Files (x86) on my machine. I was thinking of using this command:

c:\windows\Microsoft.NET\Framework\v2.0.50727\regasm Aspose.PDF.dll \codebase /tlb:ComComponent.tlb

  1. Is there a 64bit and 32bit version of Aspose.PDF. Which one am I using? Which is better?

  2. I read that you can use an XML file to create and PDF file. Can you give me an example.

Thanks a lot,

@Toberville

Thanks for your feedback.

Yes.

You can use any location for registering the assembly where DLL is placed. Looking at your sample location, it seemed that you have added the assembly in GAC (Global Assembly Cache). In case you want to use it from cache location, you can register it from there as well. In case you face any issue, please feel free to let us know.

The Aspose.PDF for .NET supports both 32-bit and 64-bit architectures. However the MSI Installer places the assembly in Program Files (x86) folder and assemblies present there can be used for both architectures. Furthermore, we will be changing the installer logic soon and it will be installing the DLLs in Program Files in near future.

You can create PDF file using XML template and XML template should be based on XML Schema support by the API. You may please find examples given in API documentation over following link:

Hello Asad,

For the Aspose.PDF ComWrapper, I created a C# Class Library (.net) called AsposePdfComWrapper. Listed below.

Can you give me some example code to read a PDF and insert some text at a specific location.

Do I need to add something regarding Aspose under using System.Text?

Thanks for all the help.

=============================================

using System;
using System.Collections.Generic;
using System.Text;

namespace AsposePdfComWrapper
{
public class Methods
{
public Methods() { }

}

}

I have another really simple question. How do I check in my classic asp that Aspose.PDF was registered. Hers is what I did:.

c:\windows\Microsoft.NET\Framework\v2.0.50727\regasm Aspose.PDF.dll /codebase /tlb:ComComponent.tlb

I am using the trial version of Aspose.PDF. What classic ASP code do I need to perform to check if the Aspose.PDF objects exist?

Thanks again,

@Toberville

Thanks for getting back to us.

Please use following code snippet to load an existing PDF document and add text at specific location:

Document document = new Document("input.pdf");
Page page = document.Pages[1];

TextFragment textFragment = new TextFragment();
textFragment.Text = "ABCD";

textFragment.Position.XIndent = 400;
textFragment.Position.YIndent = 700;
        
//create TextParagraph object
TextParagraph par = new TextParagraph();

//set paragraph position
par.Position = new Position(textFragment.Position.XIndent, textFragment.Position.YIndent);

//add new TextFragment to paragraph
par.AppendLine(textFragment);

//add the TextParagraph using TextBuilder
TextBuilder textBuilder = new TextBuilder(page);
textBuilder.AppendParagraph(par);
document.Save("output.pdf"); 

You may add using Aspose.Pdf; statement at the top and in case you are not using other namespaces, you may remove them as well.

In order to check if Aspose.Pdf.Document object exists, you may try running following code snippet in your Classic ASP page:

Dim doc
Set doc = Server.CreateObject("Aspose.Pdf.Document")
Response.Write doc.Pages.Count

Above code should display'0' in the browser.

Hello Asad,

With your help I am making some progress. My Asp Code recognizes the Object.

    Set doc = Server.CreateObject("Aspose.Pdf.Document")

So I built the ComWrapper IN VS, signed it, and copied to the folder. but got an error about the type unavailable when I tried to register the Com Wrapper. Here is what I did?

   c:\windows\Microsoft.NET\Framework\v2.0.50727\regasm AsposePdfComWrapper.dll /codebase 
   c:\windows\Microsoft.NET\Framework\v2.0.50727\regasm AsposePdfComWrapper.dll /tlb:AsposePdfComWrapper.tlb

I get an error after the first line

  Regasm : warning RA0000 : No types were registered

Here is what is in my Program Files (x86)/Aspose/Aspose.PDF for .NET/Bin/net2.0

  Aspose.PDF.dll
  Aspose.PDF.tlb
  Aspose.PDF.XML
  AsposePdfComWrapper.dll
  AsposePdfComWrapper.pdb
  AsposePdfComWrapper.tlb
  ComComponent.tlb

My Asp Code looks like this

  dim doc  
  Set doc = Server.CreateObject("Aspose.Pdf.Document")  
 
  dim lic
  Set lic = CreateObject("Aspose.PDF.License") 

  Dim pdfHelper
 Set pdfHelper = CreateObject("AsposePdfComWrapper")

All is good except I get this error

  Microsoft VBScript runtime error '800a01ad'

  ActiveX component can't create object: 'AsposePdfComWrapper'

I look forward to your valuable feedback.

@Toberville

Thanks for getting back to us.

Would you please make sure that you have signed the assemblies of your COM Wrapper project using public/private key. Also, please make sure to add complete assembly information by going to Project->Properties->Application Tab->Assembly Information (Button).

Furthermore, please remove the unused namespaces from COM Wrapper Class and build your project again. Please note that, after rebuilding the project, you need to register COM Wrapper assemblies again using regasm command. In case of any issue, please feel free to let us know.

Hello Asad,

I hope all is well. I have registered Aspose.PDF and have the following in the C:\Program Files (x86)\Aspose\Aspose.PDF for .NET\bin\net2.0\ folder:

     Aspose.PDF.dll
     Aspose.PDF.pdb
     ComComponent.tlb

Just a reminder that I am using WIndows 10, developing in Classic ASP, and on my local machine. I ran the following code and everything seems to work fine.

     dim doc  
     Set doc = Server.CreateObject("Aspose.Pdf.Document")  
 
     dim lic
     Set lic = CreateObject("Aspose.PDF.License") 

     response.write ( doc.Pages.Count )  

I am curios though, what else can do in classic ASP. I mean, can I read a pdf file and insert a paragraph of text into the PDF. Overall, my needs are simple: (1) read a single page PDF document, (2) insert a paragragh,(3) insert a photo, (4) and save the document.

I noticed there is no Aspose.PDF.tlb. Does ComComponent functionally replace Aspose.PDF.tlb? Please explain.

I also had some errors in the regasm… is this expected? I will attach the output errors.

Thanks so much
apdf-errors.pdf (19.7 KB)

@Toberville

Thanks for writing back.

All Aspose.PDF exportable classes are exported into ComComponent except those which are generic. Which was why, you noticed some errors after running the command.

You may try adding/writing methods in your COM Wrapper project and use them in your Class ASP project. For example, if you need to create a PDF and save it to a location, you can create a method like following:

namespace SampleWrapperAspose
{
    public class Test
    {
        public Test()
        {

        }

        public void SavePDF(string outputPath)
        {
            Document doc = new Document();
            doc.Pages.Add();
            doc.Save(outputPath);
        }
    }
}

And use it in Classic ASP as:

<% 
Dim pdfHelper Set pdfHelper = CreateObject("SampleWrapperAspose.Test") 
pdfHelper.SavePDF "C:\temp\test.pdf" 
%>

For information regarding other functionalities, please visit following useful articles in API Documentation:

Thank You Asad,

I have this working with classic ASP and a COM Wrapper. Can you help me with some basic programming using classic ASP and a COM Wrapper. I am not quite sure how to proceed. Here is what I want to do.

   1. Open a PDF document via a path  ( **this is a one page PDF** )

   2. Overlay some text (centered at row x, between column y1 and y2)  on the opened PDF . 
       I want to pass the coordinates and the text from classic ASP to the COM Wrapper. 

   3. Overlay a picture in  (centered at top x, between column y1 and y2)

   4. Save the PDF to a output file 

=============================================
Here is my attempt at the Classic ASP Code
<%

   Dim pdfHelper
   Set pdfHelper = CreateObject("SampleWrapperAspose.Test")

   pdfHelper.readDocument( "c:\path\to\the_input_file.pdf" )
   pdfHelper.placeCenteredText( 10, 100, 300, "Lorem Ipsom Text" ) 
   pdfHelper.placeCenteredPicture( 14, 100, 400, "c:\path\to\the_input_photo.jpg"  ) 
   pdfHelper.SaveDocument( "c:\path\to\the_output_file.pdf" )

   SET pdfHelper = Nothing

%>

=============================================
Here is my COM WRAPPER template.
How do I open a pdf and keep it open while changing it within classic asp?
Not sure how to pass numbers for the coordinates?

using Aspose.Pdf;

namespace SampleWrapperAspose
{
public class Test
{

    public void readDocument( string inputPath )
    {

    }
  
    public void placeCenteredText( row, col1, col2, string theText  )
    {

    }

    public void placeCenteredPicture( top, col1, col2, string photoPath )
    {

    }

    public void saveDocument(  string  ouputPath ) { 
        doc.Save( outputPath );
    }

}

}

@Toberville

In case you want to add text and images at the center of the PDF Page, you may please achieve this using TextStamp and ImageStamp Classes. Furthermore, you may achieve this requirement by implementing single method as following:

public static void PrepareDocument(string inputDoc, string outputPath, string imageFile)
{
  Document doc = new Document(inputDoc);
  // if new page is needed
  //doc.Pages.Add();
  // select page where you want to add text and image
  Page page = doc.Pages[1];

  TextStamp textStamp = new TextStamp("Dummy text");
  // set text properties
  textStamp.TextState.Font = FontRepository.FindFont("Arial");
  textStamp.TextState.FontSize = Convert.ToSingle(10);
  textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.OrangeRed);
  textStamp.VerticalAlignment = VerticalAlignment.Center;
  textStamp.HorizontalAlignment = HorizontalAlignment.Center;

  page.AddStamp(textStamp);
            
  ImageStamp imageStamp = new ImageStamp(imageFile);
  imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
  imageStamp.VerticalAlignment = VerticalAlignment.Center;
  imageStamp.TopMargin = imageStamp.Height + 10; // 10 points are for margin

  page.AddStamp(imageStamp);

  doc.Save(outputPath);
}

Good Examples Asad… I can use your examples as a good model for my needs.

About text… How would I display a rectangle of formatted text? The text would have a couple paragraphs, bolds, italics, and maybe some sections where the font size is slightly larger. The rectangle size would always be the same but the formatted text would by dynamic; meaning I would pass it as a string from classic asp to the COM Wrapper. Any ideas? Maybe the string could be coded in HTML or some other something where I parse the string.

On another note, is it possible to use one parameter to designate colors (like the hexidecimal numbers used Photoshop)? This would simplify my coding because I can send one parameter to the COM Wrapper to designate a color.

Thanks for all you help? You rock!

@Toberville

Would you please share a sample expected PDF document with us. It would help us understanding the scenario/requirements better. We will surely proceed further to assist you accordingly.

toberville-ouput.pdf (5.1 MB)
toberville-input.pdf (5.0 MB)
toberville-notes.pdf (2.2 MB)

Great! I uploaded 3 files that give a general description of what I am trying today. I look forward to your expertise and thought provoking techniques.