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:
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:
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.
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?
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
Asad this is excellent. (Is this your first name?) I am setting up my work environment now. A few questions.
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:
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:
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?
dim doc
Set doc = Server.CreateObject("Aspose.Pdf.Document")
dim lic
Set lic = CreateObject("Aspose.PDF.License")
Dim pdfHelper
Set pdfHelper = CreateObject("AsposePdfComWrapper")
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.
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.
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:
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
{
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.
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.
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.