Gossamer Forum
Home : Products : DBMan : Customization :

PDF Output File MOD

Quote Reply
PDF Output File MOD
[moved down for complete code]

--Lee

[This message has been edited by leisurelee (edited April 18, 2000).]
Quote Reply
Re: PDF Output File MOD In reply to
Gee, I'm glad I was looking for whatever I was looking for the other night. You seem to have taken off with this!

I'm not sure what you want to do with the results. Do you want to have it end up in a textarea?


------------------
JPD






Quote Reply
Re: PDF Output File MOD In reply to
No. The PDF writer takes only pure text and converts it to PDF. It doesn't take HTML code. (it prints it like UBB. WYSIWYG. heh.) No colors, no nothing but pure text. Which is okay.

What I need is, a routine that, instead of sending the matched records to the browser, puts them into a variable instead, like this:

Code:
$output .= "RECORD $in{'ID'}: $in{'Title'}\n\n$in{'Description'}\n\n-------------------------------\n";

Somthin' simple like that, so that every record is appended to this variable. Then, when it's complete, the data is sent to sub export_to_pdf and the pdf is parsed.

Actually, even that won't work; the \n character isn't an ASCII escape code for a line break. But you get the idea. Smile
--Lee

[This message has been edited by leisurelee (edited April 17, 2000).]
Quote Reply
Re: PDF Output File MOD In reply to
Won't this work?

Code:
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);

$linefeed=chr(13);

$output = qq|Insert anything you want as introductory text here. You can just put
carriage returns within the text for new lines. Be sure to end with $linefeed$linefeed
in order to get a double space before the start of the record printout.
|;

for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
$output .= "$rec{'Title'}$linefeed$rec{'Author'}$linefeed$rec{'Publisher'}$linefeed$linefeed";
}

Naturally it would have to be changed to match an individual's database.



------------------
JPD








[This message has been edited by JPDeni (edited April 17, 2000).]
Quote Reply
Re: PDF Output File MOD In reply to
Naturally. I believe it may; would this have to be called pre- or post-searching?
Quote Reply
Re: PDF Output File MOD In reply to
This would be post-searching. You would have to have values in the %in hash to do the search.


------------------
JPD






Quote Reply
Re: PDF Output File MOD In reply to
Sometimes, the blond moments are overwhealming. Smile
Quote Reply
Re: PDF Output File MOD In reply to
Okay, question. Is there a quick 'n dirty reg exp string I could use to remove all HTML codes from the $output?

--Lee
Quote Reply
Re: PDF Output File MOD In reply to
I stand corrected. It's been a long time since I worked with ASCII codes. Smile

To remove all HTML codes from the output, I think this will work:

$output =~ s/<.+>//g;

That should look for
< whatever >
and remove it from the string. I think. Smile


------------------
JPD






Quote Reply
Re: PDF Output File MOD In reply to
One problem with that code, JPD. It is taking out EVERYTHING between the opening and closing brackets.

For example, I have a little bit of code, <B><CENTER>This is a test</CENTER></B>. When I push it through s/<.+>//g;, it takes out the entire line. Nothing else is effected.
Quote Reply
Re: PDF Output File MOD In reply to
Well, then, I was wrong. Smile

You might go ask in the Perl/CGI forum. Those folks know more about this kind of thing than I do.


------------------
JPD






Quote Reply
Re: PDF Output File MOD In reply to
Okay. I think we've got it.

This MOD utilizes PerlStudio's PDFever script, located at www.perlstudio.de/pdfintro.html .

You can download the script for 30-day evaluation. Registration is $10/$20 for continued use.

The modifications listed here are all made in the html.pl file of DBMan 2.04.
1) Install PDFever as instructed; it is very easy to install.

2) Create a sub export_to_pdf at the bottom of the html.pl file, before the 1 at the bottom:

Code:
sub export_to_pdf {
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
$linefeed=chr(10); # Assigns ASCII code for Line Feed
for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
$rec{'Description'} =~ tr/"/''/; # Replaces Quotes (") with two apostrophe (''), otherwise it'll crash your DB
$output .= "RECORD $rec{'ID'} -- $rec{'Title'}: $linefeed $rec{'Description'} $linefeed $linefeed $rec{'Phone'} $linefeed
-------------------------------------------------------------------------------------------------------------------------------------------- -------------- $linefeed";
}
$output =~ s/<([^>]|\n)*>/ /g; # strips all HTML codes
$output .= " "; # Adds a space at the end (PDFever bug)

print qq^
<form action="/path/to/pdfever.cgi" method="POST" enctype="application/x-www-form-urlencoded" target="output">
<input type="HIDDEN" name="measUnit" value="1">
</-- UNIT OF MEASURE - 1=inch, 2.54=cm, 25.4=mm -->
<input type="HIDDEN" name="paper" value="A4">
</-- PAPER SIZE - Letter,Legal,A4,B5,Index Card,Postcard -->
<input type="HIDDEN" name="pageOrient" value="portrait" checked>
</-- ORIENTATION - portrait or landscape -->
<input type="HIDDEN" name="usePageBorder" checked>
</-- PAGE BORDER - remove "checked" to disable page borders -->
<input type="HIDDEN" name="pageBorderWidth" value="0.5">
</-- BORDER WIDTH - Width of borders, if borders used -->
<input type="HIDDEN" name="marginTop" value="1">
<input type="HIDDEN" name="marginLeft" value="1">
<input type="HIDDEN" name="marginRight" value="1">
<input type="HIDDEN" name="marginBottom" value="1">
</-- MARGINS - Top,Left,Right,and Bottom margin widths in inches -->
<input type="HIDDEN" name="columnNum" value="1">
</-- NUMBER OF COLUMNS - value 1 up to 5 -->
<input type="HIDDEN" name="useColumnDivider">
</-- COLUMN DIVIDER - remove this line to disable vertical line between columns -->
<input type="HIDDEN" name="columnDef" value="byWidth" checked>
<input type="HIDDEN" name="columnWidth" value="4">
<input type="HIDDEN" name="columnDef" value="bySpacing">
<input type="HIDDEN" name="columnSpacing" value="1">
</-- DEFINE COLUMN - move "checked" to either bySpacing or byWidth -->
<input type="HIDDEN" name="fontFace" value="Arial">
</-- FONT FACE - Times, Arial, or Verdana -->
<input type="HIDDEN" name="fontStyle" value="">
</-- FONT STYLE - "" (normal), Bold, Italic, or BoldItalic -->
<input type="HIDDEN" name="fontSize" value="8">
</-- Font size in points -->
<input type="HIDDEN" name="textAlign" value="left">
</-- TEXT ALIGNMENT - left or justify -->
<input type="HIDDEN" name="lineDef" value="byHeight" checked>
<input type="HIDDEN" name="lineHeight" value="14">
<input type="HIDDEN" name="lineDef" value="byNumber">
<input type="HIDDEN" name="lineNumbers" value="66">
</-- LINE DEFINITION - move "checked" to either byHeight or byNumber -->
<input type="HIDDEN" name="customHeader" value="PDF Search Export">
</-- CUSTOM HEADER - The text used in the document header -->
</-- *NOTE* - For header and footer (below), these variables are identical to those listed above. -->
<input type="HIDDEN" name="headerFontFace" value="Verdana">
<input type="HIDDEN" name="headerFontStyle" value="BoldItalic">
<input type="HIDDEN" name="headerFontSize" value="10">
<input type="HIDDEN" name="headerTextAlign" value="center">
<input type="HIDDEN" name="customFooter" value="Page <page> / <time>">
</-- CUSTOM FOOTER - The text used in the document footer -->
<input type="HIDDEN" name="footerFontFace" value="Verdana">
<input type="HIDDEN" name="footerFontStyle" value="">
<input type="HIDDEN" name="footerFontSize" value="9">
<input type="HIDDEN" name="footerTextAlign" value="center">
<input type="HIDDEN" name="text" value="$output">
</-- TEXT - This is the main body text. -->
<input type="Submit" value="Export to PDF">
</form>
^;
}

In this code, I use four fields: ID, Title, Description, and Phone. You should customize this line to match your database.

NOTE: For a line break (essentially a <BR> ) use one $line feed. for a Paragraph (essentially a <P> ) use two $linefeed $linefeed.

NOTE: PDFever is a great script, but has a few bugs. One of them is that you have to put at least one blank space at the end of every field and every line, or the last word of that line will wordwrap:

Code:
|;
&export_to_pdf;
print qq|

If you want to put this in the bottom of each page, and usable only by authors, insert:

Code:
if($per_add) { &export_to_pdf };

after:

Code:
print qq!| <A HREF="$db_script_link_url&admin_display=1">Admin</A>| ! if ($per_admin);
print qq!| <A HREF="$db_script_link_url&delete_search=1">Delete</A> ! if ($per_del);
print qq!| <A HREF="$db_script_link_url&modify_search=1">Modify</A> ! if ($per_mod);

and before:

Code:
print qq!|!;
print qq!</font></p>!;

There may be multiple instances of this code in your database, or it may be in sub html_footer, depending on how you've modified your script. (I have it in many places, and have totally forgotten how it was originally!)

Or, if you want everyone to see this button, insert this code instead:

Code:
{ &export_to_pdf };

4) Lastly, go through the settings of the sub export_to_pdf. ALL THESE FIELDS ARE REQUIRED, AND ARE VERY CASE- AND CONTENT-SENSITIVE! If you remove any, do so ONLY if the comment line says you'd need to remove it, or you will get weird, unexpected errors. The comments are always below the line they are referencing.

5) Test the script. You may have to do a bit of work on the $output = "..."; line to make it look the way you want to.

[This message has been edited by leisurelee (edited April 18, 2000).]

[This message has been edited by leisurelee (edited April 18, 2000).]
Quote Reply
Re: PDF Output File MOD In reply to
JPD,

I don't know if this would qualify as a "DBMan Mod" because it uses another author's script, but if you can find a place for it in your script archive, you're welcome to include it. Smile

--Lee
Quote Reply
Re: PDF Output File MOD In reply to
You could always write up the mod and submit it to the resource center. Smile


------------------
JPD






Quote Reply
Re: PDF Output File MOD In reply to
ACK You mean I have to write it again??

*grin* kidding. I'll do that. Smile

--Lee