Using the created document trough FPDF with PHP/JAVA - java

I created a PDF document with PHP using FPDF. The next thing I want to do is silently printing the document without downloading the PDF file to the computer.
I've made the following code:
$pdfprintable = $pdf->Output(''.'.pdf','S');
$printcmd = "java -classpath jPDFPrint.jar;pdfprintcli.jar cli.PDFPrintCLI $pdfprintable";
exec($printcmd);
And it returns the following error message:
Warning: exec(): NULL byte detected. Possible attack in C:\Users\Jordy\Desktop\XAMPP\htdocs\php\stickers\pdf.php on line 392
If I echo the $pdfprintable in PHP it shows a lot of weird characters.

Are you sure the java command is supposed to be used with an hexadecimal string represenation of the PDF ?
use option
$pdfprintable = $pdf->Output('USEAFULLPATHTOFILE.pdf','F');
With the above the PDF is generated and then you can try to print it with the java application if that one works.
Also if you are loading the PDF correctly in FPDF you should be able to use the option D in ->Output
$pdfprintable = $pdf->Output('USEAFULLPATHTOFILE.pdf','D');
Use this to verify the that the PDF is loaded and also managed correctly by FPDF.
Also notice your example code is very limited.
If you need more troubleshooting pls show the Java and the full PHP source relevant to printing operation, loading or creation of the PDF in FPDF

Related

decode "compiled Java class data, version 52.0" text from file

I have a file without extension but I used an online site to know the type of this file. It says the file contains "compiled Java class data, version 52.0".
The content of the file that I need to read here
 ˛∫æ4)

<init>()VCodeLineNumberTablemain([Ljava/lang/String;)V
StackMapTable
SourceFileHelloWorld.java
SYNT{SBERAFVPF_101} !"#$%&'(
HelloWorldjava/lang/Objectjava/lang/Stringlength()IcharAt(I)Cjava/lang/SystemoutLjava/io/PrintStream;java/io/PrintStreamprint(C)V!
*∑±
«rL=+∂¢g+∂>a°m£
`í>ß?A°M£
`í>ß*n°z£
dí>ßN°Z£ 
dí>≤∂Ñߡó±*
I just need to make this file readable and get the output from it
What is the encoding type used or is there any online site that can read it.
It's a compiled Java class, not some text with an encoding. Compiling means translating human readable text into instructions a PC can understand. So the file contains such CPU instructions similar to machine code, called "intermediate language" or "byte code".
Use java.exe to run it and see the output. Be aware that running a program of an unknown person is dangerous. It could delete files etc.
You can't get the source code back, but you can use a Java Decompiler to get close to the original.
The comment
SourceFileHelloWorld.java
suggests this is a Java "Hello, World!" program (e.g.). The long line in the middle
HelloWorldjava/lang/Objectjava/lang/Stringlength()IcharAt(I)Cjava/lang/SystemoutLjava/io/PrintStream;java/io/PrintStreamprint(C)V!
suggests the program prints "HelloWorld." That would be the output.

extracting text from using pdfclown function 'textextractor'

i am getting an error while using textextractor of pdfclown library. The code i used is
TextExtractor textExtractor = new TextExtractor(true, true);
for(final Page page : file.getDocument().getPages())
{
System.out.println("\nScanning page " + (page.getIndex()+1) + "...\n");
// Extract the page text!
Map textStrings = textExtractor.extract(page);
a part of the error i got is
exception in thread 'main' java.lang.exceptionininitializer error
at org.pdfclown.document.contents.fonts.encoding.put
at ......
at ......
<about 30 such lines>
caused by java.lang.nullpointerexception
at java.io.reader.<init><Reader.java:78>
at java.io.inputstreamreader
<about 30 lines more>
I also found out that this happens when my pdf contains some bullets for example
item 1
item 2
item 3
Plz help me out to extract the text from such pdfs.
(The following comment turned out to be the solution:)
Using your highlighter.java class (provided on your google drive in a comment) together with the current PDF Clown trunk version as jar, the PDF was processed without incident, especially without NullPointerException (the highlights partially were not at the right position, though).
After looking at your shared google drive contents, though, I assumed you did not use a PDF Clown jar but instead merely compiled the classes from the distribution source folder and used them.
The PDF Clown jar files contain additional ressources, though, which your setup consequentially did not include. Thus:
Your highlighter.java has to be used with pdfclown.jar in the classpath.

reading an html with matlab

I would like to read some html using matlab.
I've already tried urlread but got the url read error
Getting data into MATLAB from HTTPS:
so i tried using java with this:
Handling an invalid security certificate using MATLAB's urlread command.
unfortunately i don't know how to use java with matlab.
so i tried this code and it seems to work
url = 'https://stackoverflow.com/questions/11053664/use-java-in-matlab';
is = java.net.URL([], url ).openConnection().getInputStream();
br = java.io.BufferedReader(java.io.InputStreamReader(is));
str = char(br.readLine());
however i would like to get the whole html page. so i can use regexp.
My kingdom for some help
There is a function in matlab that does that... The name is urlread!
See http://www.mathworks.com/matlabcentral/answers/973

Suppress Print Dialog when printing to Microsoft Document Image Writer from Oracle BPM 10g

We have an Oracle BPM 10g activity that:
Reads a form-fill protected Word document template.
Merges data into the fields.
Saves the merged/filled copy to the filesystem.
Prints the document to a selected, pre-defined printer, OR to the default printer.
All of this works fine when printing to a "real" printer. However, there is now a need to output the Word document to TIFF. Attempting to use "Microsoft Document Image Writer" as one of the printer selections does not work as expected. Normally, when printing to the Microsoft Document Image Writer from Word (or any other application) directly, you're prompted for a location to save the resultant file. This prompting does not occur when attempting to print from this particular activity in BPM 10g.
Ideally, we actually would like to bypass the dialog and output the TIFF directly to the filesystem. However, I have not found a way to control this programmatically. That is, being able to specify the destination filename in code. Right now, I'm just trying to get output to the Microsoft Document Image Writer at all, to make sure it works.
So, the bottom line question(s) is/are:
Can this be done? I.e., printing to Microsoft Document Image Writer
If yes, can the file location dialog be suppressed?
How?
You said nothing about the way you're automating Word.
In Word VBA, you may use this sample to print out the active document immediately without showing the print dialog:
Public Sub PrintToXPS()
'Presume that Microsoft XPS Document Writer was already
'set up as ActivePrinter
Dim strFilePath As String
strFilePath = "C:\temp\helloworld.xps"
ActiveDocument.PrintOut Background:=False, outputfilename:=strFilePath
End Sub
There's no need to use the print dialog instead. However, if you want to operate through the dialog object, that can be done in Word using a variable of type Word.Dialog and providing the necessary parameters, e.g.
Dim dlgFilePrint As Word.Dialog
Set dlgFilePrint = Application.Dialogs(wdDialogFilePrint)
dlgFilePrint.Update
dlgFilePrint.PrToFileName = strFilePath
dlgFilePrint.printtofile = True
'add other parameters as needed ...
'lock up parameter names in Word VBA Online Help using "WdWordDialog-Enumeration"
'as key word
dlgFilePrint.Execute
What I did here with the XPS printer, you may of course do also with any other printer.
Thank you, domke consulting.
After more searching, I found this forum post on MSDN.
Adding these registry entries to suppress the dialog box and suppress post-generation output seemed to do the trick:
In HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\MODI\MDI Writer
PrivateFlags = 17 (Decimal)
OpenInMODI = 0 (Decimal)
For our purposes, this seems to work fine if we call the printOut() method with the following relevant arguments (other arguments omitted here for brevity):
document.printOut(outputFileName : "C:\\temp\\fileName.tif", printToFile : true);

Running a JavaScript command from MATLAB to fetch a PDF file

I'm currently writing some MATLAB code to interact with my company's internal reports database. So far I can access the HTML abstract page using code which looks like this:
import com.mathworks.mde.desk.*;
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.setCurrentLocation(ReportURL(8:end));
pause(1);
s={};
while isempty(s)
s=char(wb.getHtmlText);
pause(.1);
end
desk=MLDesktop.getInstance;
desk.removeClient(wb);
I can extract out various bits of information from the HTML text which ends up in the variable s, however the PDF of the report is accessed via what I believe is a JavaScript command (onClick="gotoFulltext('','[Report Number]')").
Any ideas as to how I execute this JavaScript command and get the contents of the PDF file into a MATLAB variable?
(MATLAB sits on top of Java, so I believe a Java solution would work...)
I think you should take a look at the JavaScript that is being called and see what the final request to the webserver looks like.
You can do this quite easily in Firefox using the FireBug plugin.
https://addons.mozilla.org/en-US/firefox/addon/1843
Once you have found the real server request then you can just request this URL or post to this URL instead of trying to run the JavaScript.
Once you have gotten the correct URL (a la the answer from pjp), your next problem is to "get the contents of the PDF file into a MATLAB variable". Whether or not this is possible may depend on what you mean by "contents"...
If you want to get the raw data in the PDF file, I don't think there is a way currently to do this in MATLAB. The URLREAD function was the first thing I thought of to read content from a URL into a string, but it has this note in the documentation:
s = urlread('url') reads the content
at a URL into the string s. If the
server returns binary data, s will
be unreadable.
Indeed, if you try to read a PDF as in the following example, s contains some text intermingled with mostly garbage:
s = urlread('http://samplepdf.com/sample.pdf');
If you want to get the text from the PDF file, you have some options. First, you can use URLWRITE to save the contents of the URL to a file:
urlwrite('http://samplepdf.com/sample.pdf','temp.pdf');
Then you should be able to use one of two submissions on The MathWorks File Exchange to extract the text from the PDF:
Extract text from a PDF document by Dimitri Shvorob
PDF Reader by Tom Gaudette
If you simply want to view the PDF, you can just open it in Adobe Acrobat with the OPEN function:
open('temp.pdf');
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.executeScript('javascript:alert(''Some code from a link'')');
desk=com.mathworks.mde.desk.MLDesktop.getInstance;
desk.removeClient(wb);

Categories

Resources