Aspose.PDF in Classic ASP COM Object

Hi all,

Looking for a little help in creating Classic ASP Com Object using the COM Interop solution.

After a little digging I managed to create the Com object in Classic ASP/VBS using the line:

Set PDF = CreateObject(“Aspose.Pdf.Document”)

The documentation still shows and uses the obsolete “Aspose.Pdf.Generator.Pdf” object. However, when trying to call any of the other methods/functions on this object it seems to fail with the error:

Invalid procedure call or argument

I have tried various different calls such as ‘save’ or even just opening a PDF using this COM Object in ASP.

Would someone be able to give some up-to-date information on how I would instantiate the Aspose.PDF.Document object to:

  1. Open an existing PDF via filepath/URL
  2. Save this PDF to a different location
  3. Merge multiple PDFs
  4. Linearize so when opening the merged PDF we see the first page whilst the other pages are loading.

Many thanks,

NDB1988

@ndb1988

Instead of using the API directly. Please try to create a Class Project in Visual Studio and consume API methods in it for your required functionalities. For example:

using System;
using Aspose.Pdf;

namespace AsposePDFInterop
{
    public class PdfConverter
    {
        public void ConvertTo(string pdfFilePath, string outputFilePath, SaveFormat format)
        {
            Document pdfDocument = new Document(pdfFilePath);
            pdfDocument.Save(outputFilePath, format);
        }
    }
}

You can install Aspose.PDF for .NET using NuGet Package Manager in your project. You can then Register your project for COM interop and register its built assembly in GAC using Ragsm command. Once all setup, you can consume it like below:

<%
Dim pdfConverter
Set pdfConverter = Server.CreateObject("AsposePDFInterop.PdfConverter")

pdfConverter.ConvertTo "input.pdf", "output.docx", Aspose.Pdf.SaveFormat.DocX
%>

Make sure the path to the input PDF file is correct and that the ASP application has permission to write to the output directory. We really hope that the information will help you in achieving your goal. Please feel free to let us know in case you need further assistance.

Thanks Asad. I had actually found this info already and begun the process before you had gotten back to me but thanks for confirming I was down the correct path.

A quick question in regards to PDF Privileges. I have altered a PDF using the privileges method and tried both ‘DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;’ and ‘privilege.AllowPrint = false;’ but it still seems to be printable when viewed via Adobe. Is there something I am missing with this?

Many thanks,

ndb1988

Hi Asad.

I can get the Com Wrapper working successfully within VBScript but when trying on IIS with ASP Classic I receive an object creation failure. Any idea what setting/issue may be causing this?

@ndb1988

Is the exception related Aspose.PDF? Can you please share some more details? Also, about the privilege related case, are you applying the owner password along with setting the privileges?

Hi Asad.

The object creation was to do with Classic Asp needing the /codebase command for the registration of the COM Wrapper. I have sorted this now.

Thanks for the info about the priveleges. I indeed was not setting the ‘owner’ password. Again this is now working.

I have another question. Is there a way for me to organise my COM Wrapper so that I can create a PDF document and then alter it using my created functions? E.g. create a PDF object via:

Dim pdfObject
pdfObject = Server.CreateObject(“Aspose.ComWrapperHelper”)
createdPdfObject = pdfObject.createPdf(“path.to.pdf”)

And then do things like merge this with other files or alter priveleges etc. on this particular object without creating a new one in each method in my COM Wrapper. Hopefully I’ve explained this correctly. Essentially mimicking functionality of the Aspose.PDF object.

@ndb1988

As far as we understand this, you may return Stream from a method that is creating PDF document. Then use same stream to pass to the other method that can merge aur maybe do other operation on it. OR you can simply use the same file path and pass it onto other methods that you write to carry on the functionality.