I'm generating PDF files using DOMPDF and it generates files with version 1.3 which causes issues in printer. So I tried to use Ghostscript through PHP exec() which works fine but my main PDF parameters like Author, Optimized etc are reset. So how do we set these info through Ghostscript?
Ghostscript doesn't 'reset' the contents of the Info dictionary, these are normally preserved (assuming you are using a reasonably recent version of Ghostscript, you don't actually say which version you are using, nor on which operating system.
If for some reason they are being overwritten, then you can use pdfmark operations to set these contents of the Info dictionary.
I don't know what you mean by 'Optimized'. If you mean 'Linearized' which Distiller often refers to as 'optimized for web viewing' then don't worry about it, its essentially pointless. Effectively this just makes the file bigger.
If you are convinced that you can genuinely use it then you can have Ghostscript produce linearized files too, see Section 6.4
Related
I am using SSRS version 15.0.1102.897. When I generate PDF files using this version the PDF gets set to version 1.7.
I have another instance of SSRS running version 13.0.2216.0 and when I generate PDF files using this version, the PDF gets set to version 1.3.
The issue I'm running into is that I'm using a FPDI PDF-Parser Library to merge the generated files together but this library only supports up to PDF version 1.4 for merging.
Is there a way to force the generated PDF in the v15 SSRS instance to be PDF version 1.3 or 1.4 instead of 1.7?
Thanks in advance
Looking through RSReportServer.Config description that value seems not to be accessible (pun) to configurators.
SSRS as you note is now designed for features found in version 1.7 upwards but may work primarily using 1.3 compatible objects.
The simplest solution may be to use a binary/hex patchier to replace the 8 bytes %PDF-1.7 header string with %PDF-1.3 (do NOT use an ascii string find and replace such as sed/grep), if you want to try the dirty way you need either https://sourceforge.net/projects/bbe- or other equivalent to hexdump then modify then hex2bin and verify no byte change in file size (not even one byte +/- since the trailer would be corrupted)
However there is no guarantee that any 1.5 or above objects will not break FPDI so for best compatibility you could parse through Ghostscript to "down-level"
for more details see related question and old link here https://stackoverflow.com/a/51002675/10802527
Do follow the link to iconic blog but the modern command line can be shorter so try the traditional
<?php
exec('gs -sDEVICE=pdfwrite -o="'.$srcfile_new.'" "'.$srcfile.'"');
?>
and also try for comparison using 9.55 additional -dNEWPDF
If I would like to distribute PHP application with installer(package system of OS) how should I proceed? I don't want PHP files to be there, just working application, so when I type 'app' into console, it ends up being launching application, without need to install PHP on system(no php installation on host required). I would also like the application to have patch-able byte-code, so it's in parts, loaded when needed and only part needs to be replaced on update.
What I would do now is following:
->Compile PHP with extensions for specific platform.
->Make binary application which launches '/full/php app' when app is launched.
->Pack it in installer in a way, that there would be binary added to path when added, launching specific installation of PHP which is alongside the app with argument of start point->App would be running.
Problem is:
Maybe I don't want my PHP files to be exposed(in application, there will be available source anyway) is there some ready made stuff to do this? Is there some better way than I proposed?
Alternative: Modifying OP Cache to work with "packing" application to deliver byte codes to modified OP Cache which just reads the cache.
My suggestion would be a tiny tool I just finished, for almost exactly the same problem. (Oh yes I tried all the others but they're old and rusty, sometimes they're stuck with 4.x syntax, have no support, have no proper documentation, etc)
So here's RapidEXE:
http://deneskellner.com/sw/rapidexe
In the classical way, it's not a really-real compiler, just a glorified packer, but does exactly what you need: the output exe will be standalone, carrying everything with it and transparently building an ad-hoc runtime environment. Don't worry, it all happens very fast.
It uses PHP 7.2 / Win64 by default but has 5.x too, for XP compatibility.
It's freeware, obviously. (MIT License.)
(Just telling this because I don't want anyone to think I'm advertising or something. I just took a few minutes to read the guidelines about own-product answers and I'm trying to stay within the Code of the Jedi here.)
However...
I would also like the application to have patch-able byte-code, so it's in parts, loaded when needed and only part needs to be replaced on update.
It's easier to recompile the exe. You can extract the payload pieces of course but the source pack is one big zip; there seems to be no real advantage of handling it separately. Recompiling a project is just one command.
Maybe I don't want my PHP files to be exposed(in application, there will be available source anyway)
In this case, the exe contains your source compressed but eventually they get extracted into a temp folder. They're deleted immediately after run but, well, this is no protection whatsoever. Obfuscation seems to be the only viable option.
If something goes wrong, feel free to comment or drop me a line on developer-at-deneskellner-dot-com. (I mean, I just finished it, it's brand new, it may misbehave so consider it something like a beta for now.)
Happy compiling!
PHP doesn't do that natively, but here are a few ideas:
Self-extracting archive
Many archival programs allow you to create a self-extracting archive and some even allow to run a program after extraction. Configure it so that it extracts php.exe and all your code to a temp folder and then runs ir from there; deleting after the script has complete.
Transpilers/compilers
There's the old HPHC which translates PHP code to C++, and its wikipedia age also contains links to other, similar projects. Perhaps you can take advantage of those.
Modified PHP
PHP itself is opensource. You should be able to modify it withot too much difficulty to take the source code from another location, like some resource compiled directly inside the php.exe.
Use Zend Guard tool that compiles and converts the plain-text PHP scripts into a platform-independent binary format known as a 'Zend Intermediate Code' file. These encoded binary files can then be distributed instead of the plain text PHP. Zend Guard loaders are available for Windows and Linux platform that enables PHP to run the scripts encoded by Zend Guard.
Refer to http://www.zend.com/en/products/zend-guard
I would like to add another answer for anyone who might be Googling for answers.
Peach Pie compiler/runtime
There is an alternative method to run (and build apps from) .php source codes, without using the standard php.exe runtime. The solution is based on C#/.NET and is actually able to compile php source files to .NET bytecode.
This allows you to distribute your program without exposing its source code.
You can learn more about the project at:
https://www.peachpie.io/
You've got 3 overlapping questions.
1. Can I create a stand-alone executable from a PHP application?
Answered in this question. TL;DR: yes, but it's tricky, and many of the tools you might use are semi-abandoned.
2. Can I package my executable for distribution on client machines?
Yes, though it depends on how you answer question 1. If you use the .Net compiler, your options are different to the C++ option.
3. Can I protect my source code once I've created the application?
Again, depends on how you answer question 1. Many compilers include an "obfuscator" option which makes it hard to make sense of any information you get from decompiling the app. However, a determined attacker can probably get through that (this is why software piracy is possible).
Is there any printer extension for php 7 ? Or can someone provide working solution how to print form php? Or I should use sockets for that ? I tried dll from 5.6 but it doesnt work(
There's a lot of stuff to be done to make its source code available for build into an usable extension besides the common tasks. There are some replacements that can be done and other issues involve finding what to do with no longer used variables and currently invalid syntax. It's a a very outdated, yet usefull extension. I've also tried to do it myself with no success (it builds but it doesn't work).
The easiest way I found and still use in POS (receipt) Printers is just a
system("(echo ".$TextToBePrinted.") >\\\\MachineNameOrPreferablyFixedIp\\PrinterNetworkName");
Every time a new line is needed. Null and newLine characters are indeed possible to send in a single command containing whole custom text, but it's very fastidious. For the same kind of printers there is esc-pos php library available.
Note: No matter if it is a local printer, it has to be shared and better if used as "\\127.0.0.1\PrinterNetworkName". PrinterNetworkName avoids invalid characters as same as in files, so "Generic / Text Only" has to be accessed as "\\127.0.0.1\Generic Text Only".
Simmilar alternatives for common use printers include using dosprn and fwrite or, again,system("echo ...");ing to COMn/LPTn faked or real ports or, if you don't care: create, write and system("print ..."); file having correctly associated extension for the filename you gave.
And for the hardcord-ers, you can build a binary (.exe) to listen to a custom port or calling binary with system(...); directly and print. It's no so hard on c++ using boost. The real hardcore decision would be building a dll extension (By the way: C++ windows api contains simmilar functionality for printing like php does in its extension for managing paper and font size, style and so on).
PHP and dll's with different fisrt two numbers in version won't work. So stop trying to make it happen.
I wish to create SWF (Flash) files with PHP but what is the best option for that nowadays? When I use Google I find all kinds of old pages about this subject, but not much is happening in this field lately, it seems....
Ming is no longer part of PHP 5.3, and I can't figure out how to install it with PECL.
('pecl install ming' doesn't work... but neither does any pecl package I try, so I guess I do it all wrong...)
On http://pecl.php.net/package/ming it says the package has been superseded. My broken english tells me that means another package is now a better solution? But which package then?
Is anybody actually using PHP to create SWF's or is this a bad idea anyway?
Depending on what what the final swf should contain there are a few options:
get libming running with your php installation
swfmill - if you need fonts or simple images embedded into a swf (xml -> swf)
mxmlc - official free compiler from Adobe, takes ActionScript3 or Flex Input if you need more complex stuff (as3 / mxml -> swf)
Haxe - similar approach as mxmlc, uses Haxe instead of ActionScript, very fast (hx -> swf)
Sam Haxe - similar to swfmill, written in Haxe (xml -> swf)
There are number of utilities that can create SWFs from various source formats: flex, haxe, laszlo etc. You could generate such a source (e.g. xml) in php on the fly and invoke a compiler via exec to produce an swf.
You just want to invoke the mxmlc compiler on the server, there's a command line for it. We did this recently for a project where we dynamically create a .swf file every time a user uploads a font, the .swf embeds that font and then the web service returns a path to the generated .swf which our parent .swf then loads in.
I want to write multiple image files to a odt file. I will be specifying a dir and the script will take it from there thru a loop. But where do i start? I have never done anything like this before!
I found this python code, which can convert html 2 python... so we can parse an html first and then call this one. But there is no reference on how to use this.
html2odt code
Atlast I found a PHP way to write odt direct! Its well documented.
http://www.odtphp.com/
I have also written a complete practical solution in php. You can upload multiple images and get the odt document generated.
The code is hosted at http://code.google.com/p/images2odt/
The first post is done here.
For anyone wanting to use the Python code will need a Python interpreter version 2.6. It might also work with version 2.7. It's mainly used in Linux but there are Windows and Mac versions as well. You will also need the files listed in the from and import statements. These files are in some of the other folders. It looks like it is a part of a much bigger Linux package. One last thing, Python scripts usually takes their arguments from a command line.
Additional info:
I looked over the setup.py file and it told me that this is an API library for open documents called odfpy. The version is 0.9.2. The link it has for the documentation is broken. A google search for odfpy came up with a place to download a more recent version (0.9.4) in a tarbell here:
http://pypi.python.org/pypi/odfpy
The documentation can be found here in an Open Office document:
https://joinup.ec.europa.eu/software/odfpy/document/api-odfpyodt