0

Some years ago I came across a Classic ASP page somebody had put together that was not much more than some basic label dimensions sent to the browser under a Microsoft Word MIME Type.

It was a pretty neat trick, and oh how I wish today that I'd saved it way back then! (Hindsight being 20/20 and all...)

About twenty minutes of searching just now didn't turn up anything—not even a sniff. I tried using Word to save a page of mailing labels as a web page, thinking that might produce a lead, but it generated only regular HTML markup. I distinctly remember this trick using the label dimensions, gutters, margins, etc., along with placeholders for the data merge.

Has anyone seen this done before? What would be the correct syntax for the response?

--EDIT--

To clarify a little better: The Classic ASP page contained text-based layout instructions for the label template (dimensions, gutters, margins, etc.), along with the standard <% ... %> processing instructions for the server-side logic of Classic ASP. That it opened in Microsoft Word was merely a function of the MIME type that was sent to the browser. The same could be effected on the desktop, I imagine, by saving the text file using the older .doc extension. I'm looking for the correct syntax for that text file.

InteXX
  • 6,135
  • 6
  • 43
  • 80

1 Answers1

0

I don't understand. You have described the way yourself, why do you need to ask?

You produce a label sheet with the specified requirements (there are several tutorials for that, one is here). This is a document, so you can save it as a document. Send it with the application/vnd.openxmlformats-officedocument.wordprocessingml.document MIME type (here the complete list) and you're good to go.

If you want to customize the DOCX server side, that can be done too (but in what language and with which tools? You need to specify that). There are several libraries to do that, or you can even do that by manipulating the XML inside the Zip container that's what a DOCX actually is.

Text only?

This is definitely not possibile with any binary format, so no DOCX or DOC.

But I very strongly suspect that it might be done by saving the file in RTF (Rich Text Format). Almost all of the MailMerge extensions are available (example) that are not available in HTML, and RTF files can be produced from plain text ASP pages.

So, I think that's your answer.

Pseudo-implementation

I did this by creating a Labels sheet and saving it in RTF format. Then, visually inspecting the file told me what needed to be done.

This is pseudo code, not ASP.

PRINTLN {\rtf1\ansi\deff3\adeflang1025
PRINTLN {\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\froman\fprq2\fcharset0 Liberation Serif{\*\falt Times New Roman};}{\f4\fswiss\fprq2\fcharset0 Liberation Sans{\*\falt Arial};}{\f5\fnil\fprq2\fcharset0 Microsoft YaHei;}{\f6\fswiss\fprq0\fcharset128 Lucida Sans;}{\f7\fnil\fprq2\fcharset0 Lucida Sans;}}
PRINTLN {\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}
PRINTLN {\stylesheet{\s0\snext0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1 Normal;}
PRINTLN {\s15\sbasedon0\snext16\dbch\af5\dbch\af7\afs28\sb240\sa120\keepn\loch\f4\fs28 Heading;}
PRINTLN {\s16\sbasedon0\snext16\sl276\slmult1\sb0\sa140 Text Body;}
PRINTLN {\s17\sbasedon16\snext17\dbch\af6\sl276\slmult1\sb0\sa140 List;}
PRINTLN {\s18\sbasedon0\snext18\dbch\af6\afs24\ai\sb120\sa120\noline\fs24\i Caption;}
PRINTLN {\s19\sbasedon0\snext19\dbch\af6\noline Index;}
PRINTLN {\s20\sbasedon0\snext20 Frame Contents;}
PRINTLN }{\*\userprops}\deftab709
PRINTLN \hyphauto1\viewscale100

PRINTLN {\*\pgdsctbl
PRINTLN {\pgdsc0\pgdscuse259\pgwsxn11906\pghsxn16838\marglsxn408\margtsxn859\pgdscnxt0 Default Style;}}\formshade\paperh16838\paperw11906\margl408\margr0\margt859\margb0\sectd\sbknone\sectunlocked1\pgwsxn11906\pghsxn16838\marglsxn408\margtsxn859\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc
PRINTLN {\*\ftnsep\chftnsep}\pard\plain \s0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1\ql\ltrpar\loch

Now the table begins. Margin is 408, width is 3600. By changing the values of the parameters \shptop, \shpbottom, \shpleft and \shpright, the cell is moved through the table.

PRINTLN {\shp{\*\shpinst\shpwr1\shptop859\shpbottom3019\shpleft408\shpright4008\shpz0{\sp{\sn shapeType}{\sv 202}}{\sp{\sn dxWrapDistLeft}{\sv 0}}{\sp{\sn dxWrapDistRight}{\sv 0}}{\sp{\sn dyWrapDistTop}{\sv 0}}{\sp{\sn dyWrapDistBottom}{\sv 0}}{\sp{\sn posrelv}{\sv 1}}{\sp{\sn posrelh}{\sv 1}}{\shptxt\s0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1\ql{
PRINTLN {\field{\*\fldinst  MERGEFIELD Author }{\fldrslt <Author>}}}
PRINTLN \par \s0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1\ql{
PRINTLN {\field{\*\fldinst  MERGEFIELD Address }{\fldrslt <Address>}}}{
PRINTLN  }
PRINTLN \par \s0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1\ql\loch
PRINTLN \par \s0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1\ql{
PRINTLN   }
PRINTLN \par \s0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1\ql\loch
PRINTLN \par \s0\hich\af3\dbch\af8\langfe2052\dbch\af7\afs24\alang1081\widctlpar\hyphpar0\ltrpar\cf0\loch\f3\fs24\lang1040\kerning1\ql{
PRINTLN }
PRINTLN \par \pard}}}

The end of the document is just

PRINTLN \par }

Tests in other formats

I have tested the other text formats that Word can turn out, and none of them can store a MailMerge label template. HTML appears to do it, but it doesn't actually work. XML might have done it, but it seems to be broken (the XML generated isn't read back properly. That might have been just me, though).

The other formats, as noted, are binary formats with a convoluted structure and can't be rendered easily using "two loops".

So, I feel confident that a "MIME document" with labels cannot be generated server side in ASP, because it cannot be generated in any way whatsoever using a text format (with the notable exception of RTF). There isn't any way the file can be formed.

So, how...?

Well, it turns out it is possible to "remote control" Windows Word, at least the old version, and do it from an ASP script using the Javascript OLE automation engine. The whole setup looks very much like what you described (ASP, simple tags, text formats), and I even wonder if any of these might be the basis for file you remember.

LSerni
  • 55,617
  • 10
  • 65
  • 107
  • I probably didn't clarify properly. I'll edit my question to explain a little better. The Classic ASP template I saw at the time was comprised of only text (interspersed with `<% ... %>` of course, for the runtime logic) that was sent to the browser under the Word MIME type. Given that, I suppose that the HTTP response part of the question could be eliminated entirely—what I'm after is the correct syntax for the text file that will open as a Word document label template (most likely saved with the older `.doc` file extension for the association, I imagine). – InteXX Jan 19 '21 at 05:43
  • @InteXX I think I have guessed how the page did it; you can try and see whether it works. – LSerni Jan 19 '21 at 12:29
  • The layout instructions were embedded in the Classic ASP page itself (along with the `<% ... %>` server-side processing instructions), so they had to have been plain text. There was no separate file, such as a `.doc` or `.rtf`. The server-side processing was a pair of nested loops, with the outer loop for the rows and the inner loop for the columns. – InteXX Jan 19 '21 at 16:25
  • 1
    Upon seeing your latest edit—thank you for the effort—I can state confidently and unequivocally that the technique I saw back then did *not* utilize RTF. It was simple and plain text, containing only the labels' dimensions, gutters and margins. As noted, the precise syntax escapes me. I agree, it's a tough one. – InteXX Jan 20 '21 at 04:28
  • @InteXX okay, now you've done it :-) -- you've ruined my next weekend. I'm really curious to see how this could be done! – LSerni Jan 20 '21 at 16:20
  • Oops, didn't mean to do *that* :-) – InteXX Jan 20 '21 at 20:02
  • Just now spotted your edit. Alas, that wasn't it. These were simple layout instructions, comprised of only dimensions, gutters and margins. The large majority of the response contained these instructions, with only the nested looping and embedded data for each label running at server side. I'm almost starting to think it's going to be easier to invent time travel and just go back to have a look. – InteXX Jan 28 '21 at 12:53
  • I should also note that Word itself was never called server-side (via COM, etc.). That approach is strongly discouraged anyway. – InteXX Jan 28 '21 at 13:00