I'm having problems with a file that I've converted myself from VBscript to Jscript - using my rather simple algorithm "Chuck brackets round it". If someone could have a look at the two versions below and post any errors, I'd be very grateful.
VBscript version:
Code:
Option Explicit
Dim form, page, font
Dim oPDF
Dim InFileMapped
Dim lWidth, lHeight
Dim col1, col2
Dim buf
col1= 70
col2= 335
Set oPDF = Server.CreateObject("PDFlib_com.PDF")
' Open new PDF file
oPDF.open_file ""
oPDF.set_info "Creator", "personalize.vbs.asp"
oPDF.set_info "Author", "Thomas Merz"
oPDF.set_info "Title", "PDFlib personalization demo (Active X/VBS)"
InFileMapped = Server.MapPath("PDFlib-purchase-order.pdf")
form = oPDF.open_pdi(InFileMapped, "", 0)
if (form = -1) then
Response.write "Couldn't open input file!"
Response.end
end if
page = oPDF.open_pdi_page(form, 1, "")
if (page = -1) then
Response.write "Couldn't open page 1 in input file!"
Response.end
end if
font = oPDF.findfont("Helvetica-Bold", "winansi", 0)
' get the dimensions of the imported form
lWidth = oPDF.get_pdi_value("width", form, page, 0)
lHeight = oPDF.get_pdi_value("height", form, page, 0)
' start a new page
oPDF.begin_page lWidth, lHeight
oPDF.place_pdi_page page, 0, 0, 1, 1
oPDF.close_pdi_page page
oPDF.setfont font, 18
oPDF.set_value "leading", 24
oPDF.set_text_pos col1, 486
oPDF.show "Doublecheck, Inc."
oPDF.continue_text "Petra Porst"
oPDF.continue_text "500, Market St."
oPDF.set_text_pos col2, 104
oPDF.continue_text DATE
oPDF.end_page
oPDF.close
oPDF.close_pdi form
buf = oPDF.get_buffer()
Response.Expires = 0
Response.Buffer = true
Response.ContentType = "application/pdf"
Response.Addheader "Content-Disposition", "inline; filename=" & "personalize.vbs.asp.pdf"
Response.Addheader "Content-Length", LenB(buf)
Response.BinaryWrite(buf)
Response.End()
Set oPDF = Nothing
JSCRIPT version:
Code:
var form;
var page;
var font;
var oPDF;
var InFileMapped;
var lWidth;
var lHeight;
var col1;
var col2;
var buf;
col1=70;
col2=335;
oPDF = Server.CreateObject("PDFlib_com.PDF");
oPDF.open_file("");
oPDF.set_info("Creator", "personalize.vbs.asp");
oPDF.set_info("Author", "Thomas Merz");
oPDF.set_info("Title", "PDFlib personalization demo (Active X/VBS)");
InFileMapped = Server.MapPath("PDFlib-purchase-order.pdf");
form = oPDF.open_pdi(InFileMapped, "", 0);
if(form = -1){
Response.write("Couldn't open input file!");
Response.end();
}
page = oPDF.open_pdi_page(form, 1, "");
if(page = -1){
Response.write("Couldn't open page 1 in input file!");
Response.end();
}
font = oPDF.findfont("Helvetica-Bold", "winansi", 0);
lWidth = oPDF.get_pdi_value("width", form, page, 0);
lHeight = oPDF.get_pdi_value("height", form, page, 0);
oPDF.begin_page(lWidth, lHeight);
oPDF.place_pdi_page(page, 0, 0, 1, 1);
oPDF.close_pdi_page(page);
oPDF.setfont(font, 18);
oPDF.set_value("leading", 24);
oPDF.set_text_pos(col1, 486);
oPDF.show("Doublecheck, Inc.");
oPDF.continue_text("Petra Porst");
oPDF.continue_text("500, Market St.")
oPDF.set_text_pos(col2, 104);
oPDF.continue_text(now())
oPDF.end_page;
oPDF.close;
oPDF.close_pdi(form);
buf = oPDF.get_buffer()
Response.Expires = 0
Response.Buffer = true
Response.ContentType = "application/pdf"
Response.Addheader("Content-Disposition", "inline; filename=" & "personalize.vbs.asp.pdf");
Response.Addheader("Content-Length", LenB(buf));
Response.BinaryWrite(buf);
Response.End();
delete oPDF;
IMHO, dealing with fewer computer languages is always better. Especially if YOU are the maintenance programmer. I want to eventually address this same issue for the web site I have recently been assigned to maintain. With multiple languages, one is less likely to become a true master of any one. Why do you think some of these books on Web development technologies have 2, 4, even 8 (!) authors?
So far I've seen no compelling reason to use both VBScipt and JavaScript; but from a code management point of view, plenty of reason not to.
All the books one buys on ASP "teach" utilizing VBScript on the server side. Except for bending to the will of Microsoft, why do this? If I have to pay for all the training, books, tools, etc. necessary for using both languages in my coding shop you better have excellent reasons. So what are they; anyone?
Specifically, because this bit of VBscript I'm trying to convert has got to sit in amongst a HUGE page of Jscript. If someone tells me how to use two different server-side languages safely on the same page, passing variables between them and the rest of it, then I guess I don't have a problem - can anyone help me there? More generally, because I started off in Javascript, and know very little VB, so Jscript is a more comfortable language for me to write in.
ASP has no problem running two languages on the same page... I haven't tried it SPECIFICALLY like above, but I use javascripts on VBScript pages, just because sometimes they are easier/shorter, when usually VBScript is easier.
I personally don't care if there is more than one scripting language on a page - as long as it works!!!
__________________
Former ASP Forum Moderator - I'm back!
If you can teach yourself how to learn, you can learn anything. ;)
SH;
It's interesting that you define the variable in one language, and try to use it in another. I don't see how the Javascript compiler(?) can know about the results/object code/whatever of the VBScript compiler(?).
Maybe use a function to pass the value as a parameter?
Oh, I think I see. RESPONSE is an ASP object, not a Javascript object. By completely surrounding the statement w/ the ASP tag, ASP will evaluate it, not Javascript.
I guess ASP objects simply have access to variables declared in VBScript and Javascript.
That's a good assumption (it seems to ring true to me, at any rate);
I didn't see any ASP tags surrounding the javascript or have a chance to test it though, since I usually only use javascript in functions on VBScript pages.
__________________
Former ASP Forum Moderator - I'm back!
If you can teach yourself how to learn, you can learn anything. ;)
IMHO, dealing with fewer computer languages is always better. Especially if YOU are the maintenance programmer. I want to eventually address this same issue for the web site I have recently been assigned to maintain. With multiple languages, one is less likely to become a true master of any one. Why do you think some of these books on Web development technologies have 2, 4, even 8 (!) authors?
So far I've seen no compelling reason to use both VBScipt and JavaScript; but from a code management point of view, plenty of reason not to.
All the books one buys on ASP "teach" utilizing VBScript on the server side. Except for bending to the will of Microsoft, why do this? If I have to pay for all the training, books, tools, etc. necessary for using both languages in my coding shop you better have excellent reasons. So what are they; anyone?
One good reason I use mostly JScript in my server pages is that as a web developer I already know JavaScript. Client-side JavaScript is supported in browsers on many, many platforms so learning it is a good investment, while Basic and VBScript are mostly supported by Microsoft. How many web pages have you seen or even wrote that use client-side VB scripts ? And all books teach VBScript just to go with the flow given by Microsoft. But even the Script Developer guide from MSDN teaches both anyway ...
And then there is also the issue of each language having its advantages and disadvantages. JavaScript is more formal and technical for me, and as a C++ programmer I want that from the language I choose to script with.
Now I can work with both of them anyway. Even though you are right that I do not master any one of them, I think I should learn them both, and then if I want I can specialise into one.
Is this a record for the deepest thread-digging ever??
I do not know, it might well be, as I did not look at the date when I replied.
I found the thread yesterday.
I was searching for a way to create data of the COM (ActiveX) data type VT_ARRAY | VT_UI1 with JScript, as I want to output an Excel workbook from one of my web scripts, with Response.BinaryWrite, and BinaryWrite needs an object of that data type. Unfortunately JScript knows little about data types...
I did not even look at the year.
Anyway both VBScript and JScript are in use today, as ASP is, so the question is still up-to-date.