PDF X-1a:2001 format in PHP - php

I need generate a PDF file in format X-1a:2001 using Photoshop or InDesign, and write over it using PHP (or other language).. using a specific font (inside pdf file).. and export it as X-1a:2001 also..
It's possible? I googled but found nothing about it.
Anyone already did something like that?
Thanks.
I tried open x-1a:2001 pdf in FPDF as sourcefile.. but, when i exported, it loses x-1a:2001 format

To answer your question as literally as possible: yes, it's possible.
PDF/X-1a is not magic, it's just a very well defined subset of PDF. So, as long as the objects you add to the PDF/X-1a file are compliant to the specification (which, for example, says that all objects must be in a few well-defined color spaces such as CMYK, gray or spot color), you won't break compliancy.
Of course the second requirement is that your PDF engine (the library you end up using) does the right thing as well. It shouldn't throw away the PDF/X-1a identification in the file and it shouldn't add content that makes the file non-compliant.
By the way, don't rely on simply looking at the file's metadata to determine whether it is PDF/X-1a compliant. That metadata only says the file claims to be compliant; which has nothing to do with the file actually being compliant.

Related

Best way available to convert a PDF of any version into a scanned / flatten PDF file

I would like to know is there a way which will help me convert a PDF which is not scanned (can be modified in Acrobat Pro) into a file which is scanned / flatted (cant be edited in Acrobat Pro).
I have been using FPDF library but it seems that it is not able to recognize if the PDF is flatten / not in 1st place and depending on this it is triggering some different actions.
I have tried my best to study the FPDF library and I think it checks for the 'xref' position and decides to take which steps should be taken.
But in my case I have 2 files, one is flatted and one not and FPDF cant determine the difference itself. Both these files are of version 1.4. I have also read that FPDF has a limitation of processing pdfs which are only 1.4 version.
You could use Ghostscript's pdfimage device which will render the entire content to an image, and then wrap that up as a PDF file. There's absolutely no possibility of extracting anything from that without running it through OCR software. That 'sounds lie' what you want, though its hard to be certain.
I'm afraid that I don't think your understanding of 'flattened' can be correct. All PDF files will have an xref, so the presence or absence of such a keyword doesn't tell you if the PDF is 'flattened', whatever your user/manager means by that rather vague term.
The absence of a 'xref' could mean that the file is a PDF 1.5 or better version, and is using a compressed xref. Nothing to do with it being flattened, but any PDF consumer will have to treat such a file differently to a PDF 1.4 or below file.

saving PDFs for later manipulation in PHP

I have a PDF with some text in it that I would like to modify dynamically using PHP. This is being done already with another PDF, and what happens is that PHP simply replaces a token in the form %token% with another value pulled from a database. If you open that PDF in a text editor, you can find the %token% in plain text. But with this other PDF that I want to do the same thing with, if you open it in a text editor, there are no tokens in plaintext (even though I explicitly created one using Adobe Acrobat Pro). Obviously, the PDF's string content in this PDF is either encrypted, compressed, or both. What I want to know is how can I save a PDF so that the string content remains as plaintext such that PHP can manipulate it.
Please note, I do not want to dynamically create the whole PDF from scratch using some PHP library. I know that is something that can be done, but the PDF I am working with already exists and I just want to modify it slightly in the manner described.
For things like that I like to use the free command line tool PDFtk, which can compress / decompress PDFs and some nice thinks more. You may have a look at: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
PS: I edit a special pdf calendar form from the internet. I decompress it and replace the awful pink color for the weekend with gray (Saturday) and blue for Sunday. Violet I use as small bar to mark vacation days.

Embed code in video file

I'm sorry if the question is ambiguous, I'll try to explain.
I'm working on an existing PHP download script for videos and some parts of it are broken. There's code in there that's supposed to place a specific member code inside the video file before download, but it doesn't work. Here's the code:
//embed user's code in video file
$fpTarget = fopen($filename, "a");
fwrite($fpTarget, $member_code);
fclose($fpTarget);
$member_code is a random 6-character code.
Now, this would make sense to me if it were a text file, but since it's a video file, how could this possibly work and what is it supposed to do? If the member code is somehow added to the video, how can I see it after download it? I have no experience with video files, so any help is appreciated (a modification of the available code or new code would be equally welcome).
I'm sorry I can't give a more precise description of what the code is supposed to do, I'm trying to figure that out myself.
It may work, depending on the format/type of the video. MPG files are fairly tolerant of "noise" in a file and players would skip over your code because it doesn't look like valid video frame data.
Other formats/players may puke, because the format requires certain data be at specific offsets relative to the end of the file, which you've now shifted by 6 characters.
Your best bet is to figure see if whatever format you're serving up has provisions for metadata in its specifications. e.g. there might be support for a comment field somewhere that you can simply slap the code into.
However, if you're doing all this for 'security' or tracking unauthorized sharing of the video, then simply writing the number into a header is fairly easy to bypass. A better bet would be to watermark the video somehow so that the code is embedded in the actual video data, so that "This video belongs to member XYZ only" is displayed while playing.
You don't write to the content of the file directly, not like you would with a text file. As you've noticed, this effectively corrupts the video and you have no way of reasonably reading the information.
For audio/video files, you write to meta-data that's packaged with the file. How this is packaged and what you can do with it generally depends heavily on the container format used for the file. (Remember that container and codec are two different things. The codec is the format used to encode the audio/video, the container is the file format in which that data stream is stored.)
A library like getID3 might be a good place to start. I've never used it, but it seems to be what you're looking for. What you would essentially do is write a value to the meta-data in the container (either a pre-defined value for that container or maybe a custom key/value pair, etc.) which would be part of the file. Then, when reading the file, you can get that data. (Now, that last part depends heavily on what's reading the file. The data is there, but not every player cares about it. You'll want to match up what you're writing to with what you usually see/read from the file's internal meta-data.)

Is there a way with PHP to access a file on a server and save only the first half of the file?

I want to give users a preview of certain files on my site and will be using scribd API. Does anyone know how I can access the full file from my server and save the file under a different name , which I will then show to users..Can't think of a way to do this with PHP for .docx and image files...Help is much appreciated.
For "splitting" images, use an image processing library like gd to crop the image (lots of examples to be found on how to do that all over the place). For Word documents, use a library like PHPWord (or one of the other myriad such libraries) to open the document, remove/extract as much text as you need, then save that into a new Word file.
For other file types, find the appropriate method that allows you to manipulate that format, then do whatever you need to do with it.

PHP to edit PDF

I have some random PDF that I need to edit. And by edit, to replace an image and some text.
All of the PHP PDF libraries that I saw, create a PDF from scratch.
Is there a way to edit a page of the PDF by replacing images and text ?
There was another recent discussion on this: PHP PDF template library with PDF output? - There is no ready-made library for that.
While technically it's doable (PDF is actually a simple text based registry format, looked through specification once); the internal structure and encoding of text make it awfully difficult to locate and replace text. If you hardcode the object ids, and just create a new 25 1 obj revision for example, then a simple programmatic update might work. But neither FPDF nor TCPDF can do that AFAIK. (Look into FPDI import however.) And if you say you have some "random pdf" it's even less likely.
Try one of the format conversion methods (openoffice to pdf). You could manually convert PDF to OpenDraw probably, and after PHP-based editing convert it back. I'm very unsure if it brings usable results though.

Categories