Evaluating Aspose.PDF for Dummies


#1

I downloaded the msi for aspose.pdf and ran install. I have VS 2017 Community. I would like to learn and review Aspose.PDF. How do I do that? Step by Step. Please include menu selections on VS. This is for a dummy. Thank you for any help help.

Oh ya, does the MSI register the DLL?


COM object calls from a business basic language
#2

@Toberville

Thanks for contacting support.

In case you have installed Aspose.PDF for .NET via MSI installer, you may find DLLs over path like ‘C:\Program Files (x86)\Aspose’ and include reference in your Visual Studio project. Furthermore, please note that you can also install Aspose.PDF for .NET via NuGet Package Manager. By following the instructions given over shared documentation article, you can easily install and use API in your environment.

In case you are asking about registering assembly in Global Assembly Cache (GAC), we would like to share with you that MSI Installer does not do that. You can register assembly manually in case you want to by following the instructions over How to install the assembly into GAC article. In case of any further assistance, please feel free to let us know.


#3

I used the msi. How do I use the examples you have. I mean, how do I setup a project in VS and get your examples in there for my to start playing.


#4

@Toberville

You may please download example project of Aspose.PDF for .NET from GitHub which includes every example showcased in API documentation. For further information, please visit ‘How to Run Examples’ article(s) in API documentation. In case you need further assistance, please feel free to let us know.


#5

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?


#6

@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.


#7

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.


#8

@Toberville

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


#9

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.


#10

@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.


#11

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,


#12

@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:


#13

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() { }

}

}


#14

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,


#15

@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.


#16

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.


#17

@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.


#18

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)


#19

@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:


#20

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 );
    }

}

}