File does not begin with '%PDF-' when including image using FPDF in Classic ASP - image

I've been stuck on this problem for a while, done lots of searches and tried various solutions that others reported to be working, and yet I'm still stuck. So any suggestion is hugely appreciated. Please let me know if I'm being unclear. Many thanks in advance!!
I'm trying to generate a PDF in Classic ASP (I know....) with FPDF v.1.01 (available from http://www.aspxnet.it/public/Default.asp?page=172). But I keep getting a message "File does not begin with '%PDF-'" when the PDF is populated. I've tried this in Firefox 7.0.1, IE9, which are the two browsers we use at work. If I remove this line from the code, then everything works as expected. So all I know is this line is the trouble maker (maybe?)
this.Image('bg_logo_small.jpg',10,8,213,46);
I have a file named report.asp. The organization of the files looks like this:
./rpt/report.asp
./rpt/fpdf.asp
./rpt/bg_logo_small.jpg
./rpt/fpdf/ - this directory contains all the files extracted from fpdf1.01.zip
./rpt/fpdf/extends/
./rpt/fpdf/fonts/
./rpt/fpdf/includes/
./rpt/fpdf/models/
and report.asp looks like this,which is pretty much taken directly from the example on aspxnet.it site, except that I'm using my own jpg:
<%#LANGUAGE="javascript" CODEPAGE="65001"%>
<!--#include file="fpdf.asp" -->
<%
var pdf=new FPDF();
pdf.Header=function Header()
{
this.Image('bg_logo_small.jpg',10,8,213,46);
this.SetFont('Arial','B',15);
this.Cell(80);
this.Cell(30,10,'Title',1,0,'C');
this.Ln(20);
}
pdf.Footer=function Footer()
{
this.SetY(-15);
this.SetFont('Arial','I',8);
this.Cell(0,10,'Page '+ this.PageNo()+ '/{nb}',0,0,'C');
}
pdf.CreatePDF();
pdf.SetPath("fpdf/");
pdf.SetFont("Arial","",16);
pdf.Open();
pdf.AddPage();
pdf.Cell(40,10,"Hello Word!");
pdf.Close();
pdf.Output();
%>
I've tried the same thing in VBScript with
pdf.LoadModels("bgimg")
and function Header() and function Footer() placed in bgimg.mod, which was saved in
./rpt/fpdf/models/
The code above is all report.asp contains - no HTML inside.

I am not sure, if you haven't solved the problem yet, but anyway I answer, because it could help to somebody else.
I had the same problem and I was browsing and looking long long time for solution.
Finally I found the solution.
Go in fpdf.asp file, look for line with code:
xfile=Server.MapPath(lib.fso.GetTempName())
You can change the code e.g. like this:
xfile=Server.MapPath("Temp/"+lib.fso.GetTempName())
where "Temp/" is name of folder where temporary file during PDF file generation will be created and later deleted. The main trick is to assign "Modify" access rights to the folder Temp.
The error "File does not begin with '%PDF-'" appear because there are no access rights to create and then delete temporary files for your final PDF file. So you have an option to assign "Modify" access right to your root folder or transfer temporary files for PDF in folder Temp and assign "Modify" only to folder Temp (this is more secure).

try with <%#LANGUAGE="javascript" %>
insted of <%#LANGUAGE="javascript" CODEPAGE="65001"%>
Just need to remove CODEPAGE="65001"

Related

UFT OTA - Get ID of copied test set folder

I have (after FOREVER) figured out how to copy a test set folder from one location to another and rename it using a explicit folder id. Now, I want to rename the new folder right after pasting, so the id will NOT be known. I have found absolutely NOTHING on how I can do this.
I'm trying my hardest to use the online resource for OTA, but it's really unhelpful unless you already know the language. I can't seem to find what I need, so please don't suggest that.
Thanks in advance. Currently very frustrated and ready to throw out my computer.
Here's what I have to copy, paste, and rename a specific node by id
Set qcConnection = QCutil.QCConnection
copiedTestSet = qcConnection.TestSetTreeManager.CopyToClipboard(3)
QCConnection.TestSetFactory.PasteFromClipboard copiedTestSet,6,2,1
Set renameTest = qcconnection.TestSetTreeManager.NodeByID(30)
print renameTest.Name
renameTest.Name = "Rename Test"
renameTest.Post
Set renameTest = Nothing
Set copiedTestSet = Nothing
You will know the folder name of the pasted folder, because it should be same as the copied folder, you can simple search for the pasted folder with name under the parent folder.
Below page have few functions which can help you
https://github.com/sumeet-kushwah/ALM_OTA_Wrapper/blob/master/ALM_Wrapper/TestLabFolders.cs
There are three functions you should search for
FindChildFolderByName
FindChildFolders
GetTestSetFolder
I was able to find what I needed using sumeet's suggestion above. My exact code is below using variables because I need to be able to run this with any folder. It runs right after the paste command above. I had to insert a wait after pasting for some reason, but it works for now. I'll trouble shoot that later
Set renameTest = qcconnection.TestSetTreeManager.NodeByPath(strPath & "\" & strEventFolder)

How to browse for file (Win7/64bits)

I need to quickly write a simple GUI over a command line application. Two steps are required:
Specify an input file path,
Specify an output file path (non existing)
I found out a previous post, however trying to get the above (1) to work seems like an insane task.
Indeed BrowseForFolder seems to only work in some weird cases, you can use BIF_BROWSEINCLUDEFILES for only *.pdf and/or *.txt (trial and errors). I can get an error if I select a *.dll and/or a *.jpg (don't ask).
So instead, I gave up this approach and followed another one, in this case (objIE.Document.all.FileSelect), only the name of the selected file is returned the path seems to be always set to "c:/fakepath" for some reason. So again I am missing the full path to be able to pass that to the command line app.
Is there any sane way (<10 lines of codes) to get (1) and (2) working on Win7/64bits (VBS, HTA...)?
Don't know if people are still interested in the BrowseForFolder file selection issue, but here's what I've found.
I had the same issue selecting files with BrowseForFolder using &H4000 / BIF_BROWSEINCLUDEFILES. I could get a return with .docx but not .doc files and as you say .pdf files.
For me .txt wouldn't return anything, as didn't WMI Backup .rec files that I needed for a script I'm writing, resulting in this error information:-
Error: Unspecified error
Code: 80004005
Source: (null)
After looking at other solutions I came back to this one as my preferred choice, plus it was doing my head in that it didn't want to work. So at the bitter end it seems to be this easy.
To get my .rec files recognized I add this to the registry:-
[HKEY_CLASSES_ROOT\.rec]
#="WMI.Backup"
[HKEY_CLASSES_ROOT\WMI.Backup]
#="WMI Backup"
"BrowseInPlace"="1"
To get .txt files recognized I add this to the registry:-
[HKEY_CLASSES_ROOT\txtfile]
"BrowseInPlace"="1"
So "BrowseInPlace"="1" seems to be the nugget.
Seems so unbelievably easy that I'm sure this solution is out there somewhere but I never came across it so thought I'd put it online.
I would be interested to find that it works for others as I fear that this issue may of sent me mad, still can't believe it seems to work.
Hope this helps.
Here are 3 different ways to do what you want:
http://www.robvanderwoude.com/vbstech_ui_fileopen.php

ISN AutoIT Studio - creating new form

I created .isf form file in ISN studio. In my main.au3 file I have included this form (#include "Forms\main.isf"). But when i hit run nothing happens. Do I have to add somenthing in my main.au3? (I'm pretty new with AutoIT)
Also when I look into code which form generates there is:
$btn1 = GUICtrlCreateButton("Button",170,70,100,30,-1,-1)
GUICtrlSetOnEvent(-1,"onBtn1Click")
shloudn't be there $btn1 instead of -1 in the second line?
Thanks :)
You need to make it a user defined function (UDF). That won't work because a UDF needs to be a .au3 file. I'm not familiar with ISN studio, however to include a UDF you need to do this.
#include "C:\path\myfunctions.au3"
Also if the UDF is in the same location as the script you can just use the relative path like this.
#include "myfunctions.au3"
Here is are some example UDF's.
http://www.autoitscript.com/wiki/User_Defined_Functions
You have done nothing wrong; just forgot something.
It's correct to include the .isf file in your script. So the GUI is already present, just hidden! You only need to show it using: GuiSetState(#SW_SHOW, $HANDLE_OF_YOUR_GUI).
Then you should see your GUI! As an example see the "Testproject" in ISN AutoIt Studio.

Copying generated files from a Jekyll plugin to a site resource folder

I'm developing a plugin in Jekyll that inserts a new Liquid Tag (a block tag) named latex. It's purpose is to insert a block of LaTeX source code inside a post source file this way:
... post file contents ...
{% latex density=300 usepackages=pstricks-all, %}
\pspicture(5,5)
\psframe(0,0)(5,5) \psline(0,0)(5,5) \psline(0,5)(5,0)
\endpspicture
{% endlatex %}
... post file contents ...
The output post will contain a <img> tag instead of the Liquid Tag block once compiled and the LaTeX source will be compiled by a chained execution of latex, dvips, convert. So it will depend on external programs (TexLive and ImageMagick).
I've not found any issue with the explained so far. I can take the block of LaTeX, put it in a temporary file, and finally compile it to PNG. The rendered files must be put in the same folder of the post.
But just there I'm stuck: I want to put the generated PNG image to this folder inside the destination output folder. No problem defining a site-config variable to define the folder (in fact, I do that), nor put a file there. The problem is simple: I can write to the source folder, but the generated files will not be copied to the destination folder.
I know the reason: Jekyll generates first and renders afterwards. The copy process happens before the render part, so the generated files will not be copied.
I've found this SO entry: "How to generate files from Liquid blocks in Jekyll?", but the answer doesn't feel right: You must make a two-pass build for the files to be copied.
Also found "Generate file inside _site with Jekyll plugin", but this is not applicable because I don't want to render documents by templates.
The solution I've been planning is this:
Keep a folder with all the generated files and some index strategy for their final placement.
Implement a Sitewide method for the final placement procedure, something like:
class Site
def generate_latex_adds
// Code that copies the generated files to destination folders
end
end
Add self.generate_latex_adds calling that method inside the site_process.rb script just before the self.cleanup and self.write calls.
This will probably solve the problem, but I feel wrong to modify the site_process.rb. I'm considering pull this Liquid Tag to the community as a GitHub project, and as such, I must document this manual edit of site_process.rb to the users of this plugin. I know it's probably a common situation and a common solution, but I wonder if there is a better way to pospone the copy of the generated files without modifying core files. I'd like to keep the plugin simple: just copy the plugin file to the _plugins directory.
Any ideas?
EDIT: I'm more interested in the reasoning that on the actual code. I want to learn, not asking for a code solution.
As anyone has answered my question up to now, and I had kept investigating the issue. Finally I've got an elegant solution: use the Jekyll::StaticFile class. I have missed that class (sidenote: Read more carefully the docs).
When you add one object of this class to the site.static_files array, you are marking this file as pending for copy after the render process is completed. In fact, the copy of such files is done in the site.write process. Take a look at the site_process.rb file in your Jekyll installation.
The usage of this class is easy. When you need to mark a file for future copy, you simply execute a code like this:
site.static_files << Jekyll::StaticFile.new(site, site.source, path, filename)
Where path and filename depends on the location of your file in the src folder.
And that's all: You generate the files in the src folder, mark them as pending for copy and let Jekyll do the rest. No modification of site_process.rb at all!
You can take a look at the resulting LaTeX -> PNG liquid tag code at GitHub: https://github.com/fgalindo/jekyll-liquid-latex-plugin
I've also implemented a cleanup method there to eliminate orphaned generated files from posts that have been modified and rebuilt.

Dynamically saving file location

I have an asp.net app and I am trying to save a text file to a folder that changes with each client. How can I write it to save the files to a folder that changes. For example one customer might be C:\inetpub\wwwroot\site1\ another might be C:\inetpub\wwwroot\site2.
Relative paths don't seem to work, and I've tried GetCurrentDirectory but it kept giving me the wrong directory.
Thanks
You should try :
In the *.aspx.cs file :
string currentPath = Server.MapPath("~");
I don't have the tools to test here, but I think the code is right.
Take a look at Path.GetDirectoryName(Request.ServerVariables("SCRIPT_NAME")).
You should add a value to the web.config file which is set to the path where the file is saved.
Then, in you code, retrieve this value from the documentation, and use that path when saving.

Resources