I'm trying to generate PSD file in my application, with some text layers (TySh). Its EngineData format is pretty simple, but unfortunately have no documentation, and i got stuck with FontSet field:
/FontSet [
<<
/Name (ADomIno)
/Script 8
/FontType 1
/Synthetic 3
>>
<<
/Name (ADomIno)
/Script 8
/FontType 1
/Synthetic 0
>>
<<
/Name (AdobeInvisFont)
/Script 0
/FontType 0
/Synthetic 0
>>
<<
/Name (MyriadPro-Regular)
/Script 0
/FontType 0
/Synthetic 0
>>
]
This is Photoshop-generated data, i only omitted UTF-16 for easy-reading.
So... I can't understand, why font a_DomIno written as ADomIno. Why some fonts has "-Regular" suffix, but some has not. What means "Script", "FontType" and "Synthetic" fields. Why some fonts has two records with different fields, but other ones - only one.
There's no info in Adobe PSD format documentation, Photoshop Scripting Reference and Photoshop SDK. Projects like psd.rb or psd.js targets to parse file and has no useful info too.
Maybe someone knows?
Related
With my original question ps2pdf - Unable to open initial device thankfully answered by #KenS, I ran into another problem, where my internal hyperlinks (e.g. "see Figure 1") are lost when converting my PDF using gswin64. This is my command:
gswin64 -dPDFSETTINGS=/ebook -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o output.pdf input.pdf
I uploaded a minimum example of the original PDF here (will be deleted after 2 weeks) and the converted version here. I found this answer, also from #KenS, on the potential possibility to exctract or preserve the links, but it just says "some PostScript programming". Is there another or "simple" way of achieving this? I found online PDF converters which are able to do so, so there must be a way.
The 'some PostScript programming' refers to extracting the Link information, as the answer says the PDF interpreter already does this for the benefit of the pdfwrite device.
Your problem is that the Link annotation uses a Named Destination:
30 0 obj
<<
/Type /Annot
/Subtype /Link
/Border [ 0 0 1 ]
/H /I
/C [ 1 0 0 ]
/Rect [ 387.470001 700.413025 394.916992 713.314026 ]
/A <<
/S /GoTo
/D (figure.caption.1)
>>
>>
endobj
The Names tree contains :
52 0 obj
<<
/Names [ (Doc-Start) 34 0 R (figure.caption.1) 36 0 R (page.1)
33 0 R ]
/Limits [ (Doc-Start) (page.1) ]
>>
endobj
The named destination figure.caption.1 points to object 36:
36 0 obj
<<
/D [ 29 0 R /XYZ 117.828003 696.228027 null ]
>>
endobj
Now that could instead have been written much more simply by putting the content of object 36 in place of the figure.caption.1 in the original Destination, eg:
30 0 obj
<<
/Type /Annot
/Subtype /Link
/Border [ 0 0 1 ]
/H /I
/C [ 1 0 0 ]
/Rect [ 387.470001 700.413025 394.916992 713.314026 ]
/A <<
/S /GoTo
/D [ 29 0 R /XYZ 117.828003 696.228027 null ]
>>
>>
endobj
I think that the latter, simpler construct would work, but indirection through the names tree does not. I think this is because the pdfwrite devcie doesn't preserve the Names tree, so it can't preserve any links which rely on the Names tree.
In fact, I'm not convinced the current code preserves Link annotations at all, which it should, so I'm looking at that now. I'll edit this answer when I know more.
[EDIT]
OK so this is a wrinkle I had forgotten....
The PDF interpreter has to treat annotations in two different ways, depending on whether the PDF is being printed or not. See the PDF 1.7 Reference, section 8.4.2 Annotation Flags, bit position 3.
If the file is being 'Printed' then there is no point in preserving Link annotations (how on earth would you click a link on the printed output ?).
So when Printed is true, which is the default value, then the PDF interpreter doesn't preserve certain kinds of annotations. You can alter this quite easily by setting -dPrinted=false on the command line.
NOTE Some annotations have the 'Print' flag set, which is what this is all about. If you set Printed to 'false' then annotations which have the 'Print' flag set will not be preserved. If you set Printed to true then those annotations will be preserved, but annotations which have the Print flag set to 0 will not be preserved. There is currently no way to have the PDF interpreter preserve both annotations with Print true and ones with Print false. This is likely to be changed in a future release because people do ask for it.
If you set -dPrinted=false, your Link annotation will be preserved. I should note that it will not be the same construction as was in your original PDF file. It will use the simpler construction where the destination is explicitly stated in the Link annotation itself, rather than indirecting through the Names tree.
The effect is the same, but its an example of the kind of thing which is described in the documentation. I presume this won't be a problem for you though.
Given the way the original file is constructed, I'm not surprised that the pdfwrite output is smaller! For some reason this file contains eight Forms, eight shadings and two colour spaces (one of which is empty) none of which appear to actually be used....
I'm looking at the binary of Adobe's PDF Reference document, and I'm wondering encoding is being used in the values of the metadata here:
<<
/Producer <30B9883671A1867F59929DEDF9AF32BC0029CF5414D3744A3273BCA8E7319382EA151980>
/Subject <30BE953B76E0A2306F8F8FFBFCA67E9D1D6A8F17418D200C1B6EEE88E726DAC4CE3E2CC1>
/Creator <37A89B34768D93347889CEAFBEF3>
/Title <219EBC7941A5943A6F9E80FAF5EF7E8D1A60881E04A630452968F38B>
/Author <30BE953B76E0A1266E8F8BF4E3E317B71166880A4B9135583865>
/ModDate <35E0C86923F1C36E2FC2DEA0A1F56BEF5F39C25D14D373>
/CreationDate <35E0C86923F1C36E2CCCDFAEA1F36EE128>
>>
So far, I can't find anything in the documentation or the ISO standard about this, and this is the only PDF I've seen so far with encoded metadata values.
Any ideas?
It is standard encoding but the text strings have been encrypted. See 3.5 Ecryption in that same reference guide.
When inspecting a PDF, you should always start with reading the trailer dictionary (see 3.4.4 File Trailer). In your document this contains an /Encrypt key:
<<
/Size 31667
/ID [<19574527ECBF00E3EC0373879833EEF6> <24EE9EDB7DE40DB862FDB4C5D3493585>]
/Info 7 0 R
/Root 1 0 R
/Encrypt 31666 0 R
>>
which is "required if document is encrypted".
I'm trying to manually write a simple PDF file that contains a title, some text, and an image. I found one example of a manually written "Hello world" and managed to change some things, but I cant get it working for another text object. I have looked for help on the internet but with no luck, I guess not many people write their own PDF files.
This is what I have so far:
%PDF-1.7
1 0 obj % entry point
<<
/Type /Catalog
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/MediaBox [ 0 0 200 200 ]
/Count 1
/Kids [ 3 0 R ]
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources <<
/Font <<
/F1 4 0 R
>>
>>
/Contents 4 0 R
>>
endobj
4 0 obj % page content
<<
/Length 20
>>
stream
BT
80 180 TD
/F1 14 Tf
(PDF) Tj
ET
endstream
endobj
5 0 obj % page content
<<
/Length 20
>>
stream
BT
50 70 TD
/F1 14 Tf
(this is a pdf) Tj
ET
endstream
endobj
trailer
<<
/Size 6
/Root 1 0 R
>>
startxref
492
%%EOF
I have tried adding another text object with "this is a pdf" text but it wont show up, I don't know what could be wrong, I tried changing a few things but with no luck. The image part I don't have it either, so some help with that would be nice.
This is a wiki about the "hello world" pdf I found:
http://www.gnupdf.org/Introduction_to_PDF
Adobe offers some explanation on how the pdf works but I cant find anything that would fix my problem:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
This is not a valid PDF. If Acrobat opens it at all it's because it's given up on the xref table and done a full scan of the file, but your PDF is invalid. 4 0 obj is not a font, as you specified, and 5 0 obj is not accessed from anywhere.
PDF specification requires an xref table which points to the exact position in the file for each object. You can't realistically write this by hand unless you intend to manually update the entire xref table every time you add or remove even 1 byte from the file.
You can write a PDF from scratch like this from code easily enough but it will not work to just open a PDF in notepad and start changing things because the index (xref) immediately becomes corrupt.
I'd also advise against putting comments throughout the file unless the comments start on new lines. Otherwise some PDF parsers will get confused as this is generally not expected. Usually PDF files do not contain comments (with the exception of the second line, which is recommended by Adobe to be a comment of some non-ASCII characters so FTP recognizes the file as binary) seeing as they are virtually impossible to write manually anyway.
http://www.adobe.com/devnet/pdf/pdf_reference.html
A few years ago, I wrote a book which covers exactly this sort of thing:
http://www.amazon.com/PDF-Explained-John-Whitington/dp/1449310028/
No free online version, I'm afraid. You can get all the same information from Adobe's own documentation, which is free, but it's a rather long document!
I've build pdf with pdfbox and by the hand. I have also Visible signature on pdf. everything works, but there is no image and text shown in PDF (but there is visible rectangle, without image and text). what do you think what happens?
can you see the sample?
that's sample
thank you.
I've build pdf with pdfbox and by the hand. [...] there is no image and text shown in PDF (but there is visible rectangle, without image and text).
That is exactly what you built your document and especially the signature related data to do:
3 0 obj
<<
/FT /Sig
/F 132
/T (Signature1)
/Type /Annot
/Subtype /Widget
/V 5 0 R
/P 4 0 R
/Rect [100 574 310 625]
/AP << /N 6 0 R >>
/DR << /XObject << /FRM0 7 0 R >> >>
>>
endobj
6 0 obj
<<
/Type /XObject
/Subtype /Form
/Resources << /XObject << /FRM0 7 0 R >> >>
/BBox [0 0 100 100]
/FormType 1
/Length 8 0 R
>>
stream
endstream
endobj
There is a visible rectangle (actually after selecting the signature in question) because /Rect [100 574 310 625] in your signature field dictionary indicates the rectangular area where you have your signature.
There is no image and text shown in PDF because the normal appearance stream (which according to /AP << /N 6 0 R >> in your signature field dictionary is defined in object 6) is defined as an empty stream (there is nothing but white space between stream and endstream).
Most likely you wanted to place the xobject /FRM0 defined in the resources of the appearance stream. In that case you have the same problem in that xobject:
7 0 obj
<<
/Type /XObject
/Subtype /Form
/Resources << /XObject << /n0 9 0 R /n1 10 0 R >> >>
/BBox [0 0 100 100]
/FormType 1
/Length 11 0 R
>>
stream
endstream
endobj
This stream also is empty, you forgot to place the xobjects /n0 and /n1.
Those xobjects look correctly defined but seem to be copied from samples from the early age of integrated PDF signatures.
Concerning the Adobe Acrobat error message observed by #stanlyF:
Error during signature verification.
Signature contains incorrect, unrecognized, corrupted or suspicious data.
Support Information: SigDict /SubFilter value
The signature value dictionary also is incomplete:
5 0 obj
<<
/Type /Sig
/Name (sig1)
/ByteRange [0 0 0 0]
/Contents <0000...0000>
>>
endobj
The dictionary neither has a /Filter nor a /SubFilter entry. While nominally the filter is required and the subfilter is optional, interoperable signing mostly depends on the subfilter and the filter ist ignored. Thus the Support Information.
The /Name entry is weird because it is specified to contain the name of the person or authority signing the document (if present)
The signed byte range is empty: it consists of two seqgments, both of them starting at offset 0 and being 0 bytes long.
The contained signature container itself consists only of 0x00 bytes.
Acrobat said:
"Error during signature verification.
Signature contains incorrect, unrecognized, corrupted or suspicious data.
Support Information: SigDict /SubFilter value"
Signature has incorrect/incomplete the content-closing marker.
And also /n0 /n1 XObjects in resources have no pdf instructions.
I am generating a PDF (using fpdf) and I am wondering if there is a way to set the document's properties to to default to print with no scaling.
So when you select print from the print dialogue menu, scaling is set to none. I'm trying to determine if this is a user setting or something I can control in the creation of the PDF.
Thanks in advance.
I've done it adding to the method _putcatalog() the following:
$this->_out('/ViewerPreferences [/PrintScaling/None]');
After the line:
$this->_out('/Type /Catalog');
Implementing a method is just fast and easy...
Print-scaling can be turned off for invividual PDF files using Adobe Acrobat, by going to File -> Preferences -> Advanced -> Page scaling. (You can try this using the trial version of Acrobat.)
As for achieving this in code, I've tried and failed to make it work, but the critical difference in the files seems to be:
10 0 obj
<</Metadata 2 0 R/Outlines 6 0 R/Pages 7 0 R/Type/Catalog/ViewerPreferences<</PrintScaling/None>>>>
endobj
for non-scaling PDFs, compared to
10 0 obj
<</Metadata 2 0 R/Outlines 6 0 R/Pages 7 0 R/Type/Catalog>>
endobj
for those that use the default shrink-to-fit option.
For me changing the FPDF Catalog method _putcatalog() and adding
$this->_out('/ViewerPreferences [/PrintScaling/None]');
wasn't accomplishing the goal so I looked at the code produced by a Acrobate XI PDF and found some more verbage. Adding the following code
$this->_out('/ViewerPreferences<</Duplex/Simplex/Enforce[/PrintScaling]/PrintScaling/None>>');
created a PDF that no longer defaulted to scaling and instead only gave the option to print Actual Size which was what was desired.
Scaling is controlled by the PDF application - it is not set in the file.
well i'm not sure if you mean somethink like this:
http://www.fpdf.org/en/doc/setdisplaymode.htm
or no "scaling" for images?
$im2 = pdf_open_image_file($dokument, 'jpeg', 'example.jpg');
pdf_place_image($dokument, $im2, 395, 655, 1.0); /* 1.0 = qualiti/scaling - 1.0 is original .../*
pdf_close_image($dokument, $im2);
I ran into the same problem.
I have several PDFs where the content of the PDF, that is text and images, go very near the PDFs border but still the print dialogue Preview/Acrobat suggests printing it in 100% scaling, thus cutting off the contents which aren't printable because of the printers natural margins.
Creating any PDF in Pages for example results in a PDF which is printed in 100% scaling by default.
However if I create a PDF using TCPDF which is related to FPDF than the printer dialog suggests to scale it in order to fit the page.
My suspicion is that the way the PDF is created is different. I suspect that Pages and other tools create separate layers and they are then handeled differently, possibly by a flag or something.
I compared the readable parts of my two PDF-Files and did come accross some differences, especially on how the documents begin. My knowledge of the PDF-Sources is, however very limited, so I can only guess what needs to change.
Is there a PDF-Reference where it is stated how to control the printable objects/areas?
Here the content of a minimal PDF which will be printed without scaling:
%PDF-1.4
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
>>
endobj
2 0 obj
<< /Type /Outlines
/Count 0
>>
endobj
3 0 obj
<< /Type /Pages
/Kids [4 0 R]
/Count 1
>>
endobj
4 0 obj
<< /Type /Page
/Parent 3 0 R
/MediaBox [0 0 595 842]
/Contents 5 0 R
/Resources << /ProcSet 6 0 R
/Font << /F1 7 0 R >>
>>
>>
endobj
5 0 obj
<< /Length 73 >>
stream
BT
/F1 24 Tf
100 100 Td
(Hello World) Tj
ET
endstream
endobj
6 0 obj
[ /PDF /Text ]
endobj
7 0 obj
<< /Type /Font
/Subtype /Type1
/Name /F1
/BaseFont /Helvetica
/Encoding /MacRomanEncoding
>>
endobj
xref
0 8
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n
0000000179 00000 n
0000000364 00000 n
0000000466 00000 n
0000000496 00000 n
trailer
<< /Size 8
/Root 1 0 R
>>
startxref
625
%%EOF
Ok, I think I got it.
Try this: open your TCPDF-created PDF and remove all occurenecs of viewerpreferences and any box-statements other than the MediaBox... doing so finally resulted in a print-default-scaling-free PDF :)
seams like those additional infos -intended for professional printing- only confuse the common pdf-viewer instead of helping with anything :)
Goto tcpdf.php and change line 8529 in method _putpages as follows
change
$boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
into
$boxes = array('MediaBox');
In my PDF-output this instantly removed the scaling problem :)