Ghostscript does not convert pdf file with attachments - ghostscript

The ghostcript (version 9.21) ignores attachments within a pdf a file
Command used
cmd /c %GHOST_SCRIPT_EXE% -dPDFA=2 -dBATCH -dNOPAUSE -dSubsetFonts=false -dPDFSETTINGS=/printer -sProcessColorModel=DeviceRGB -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 -dOptimize=true -dPDFACompatibilityPolicy=1 -dAutoRotatePages=/None -sOutputFile="out.pdf" "test.pdf"
As you can see, test.pdf has an attachment 1.pdf. But in the converted pdf i.e., out.pdf does not have 1.pdf.
The pdf files are attached test.pdf and out.pdf

This isn't merely an attached file, its an embedded file.
The embedded data is not copied for several reasons. Firstly because we don't support embedded files at all in Ghostscript (we can't do anything useful with them) and secondly because you are creating a PDF/A file.
The embedded file is only valid in a PDF/A if its also a PDF/A file (your embedded file is not a PDF/A PDF file, so it would need to be converted first). There's no way for Ghostscript to easily verify that, so we (again) don't copy embedded files.
You can (of course) enhance Ghostscript yourself to do so. You will need to handle the /EF (Embedded File) key and create the stream using pdfmarks, then insert that into the dictionary for the /FS (FileSpec) key in the FileAttachment annotation.
[Edit]
The current Ghostscript PDF interpreter is written in PostScript. If you look in /ghostpdl/Resource/Init/pdf_draw.ps you will see :
/FileAttachment {mark exch loadannot /ANN pdfmark false} bdef
That's where FileAttachment annotations are processed. As you can see that uses a function called loadannot to convert the annotation dictionary into a series of strings which are stored on the operand stack, and then adds the /Ann and calls pdfmark to process the strings.
You can find the pdfmark operator documented in the Adobe pdfmark reference (available somewhere on the Adobe web site, I recommend Google, they keep moving it).
Here's what the original file looks like, you need to create pdfmarks to reproduce this:
23 0 obj
<<
/AP <<
/N 26 0 R
>>
/C [ 0.25 0.333328009 1 ]
/Contents (1.pdf)
/CreationDate (D:20180402114155+05'30')
/F 28
/FS 24 0 R
/NM (55b56d89-a71e-484c-bf64-e4608540304b)
/Name /Paperclip
/RC (<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:11.0.21" xfa:spec="2.0.2" ><p>1.pdf</p></body>)
/Rect [ 200.852997 727.552979 207.852997 744.552979 ]
/Subj (File Attachment)
/Subtype /FileAttachment
/T (ybn9mk)
/Type /Annot
>>
endobj
24 0 obj
<<
/EF <<
/F 25 0 R
>>
/F (1.pdf)
/Type /Filespec
/UF (1.pdf)
>>
endobj
25 0 obj
<<
/DL 82637
/Subtype /application#2Fpdf
/Length 82637
/Params <<
/CheckSum <EC9AED504CB6442F260E1379E21A0873>
/CreationDate (D:20180402114059+05'30')
/ModDate (D:20170907123559+05'30')
/Size 82637
>>
>>
stream
%PDF-1.5
.....
.... embedded PDF file here
....
....
endstream
endobj
The current Ghostscript implementation will reproduce object 23, the FileAttachement annotation, and it will correctly expand the /EF dictionary inline into that annotation. However, it doesn't write object 25, the actual embedded PDF file.
So you would need to add code to read the Embedded File object, write that as a named content stream, using pdfmark, and then reference that named object stream from the /EF key in the FileSpec dictionary (object 24 in the original file, but expanded and included inline in the pdfwrite output).
Unless you are very familiar with PostScript, this will be quite a challenge.

Related

Latex not opening png and windows not being able to generate bb

I'm using TexMaker (on Windows 10), using the pdflatex (F6) and yet I can't open the PNG file in the folder of my .tex
\usepackage{graphicx}
\begin{document}
\begin{figure}[h!]
\includegraphics[width=\linewidth]{File.png}
\end{figure}
\end{document}
so I tried to create an bb file from the PNG. I opened cmd at the folder and typed:
ebb File.png
ebb: file not writable for security reasons: File.bb
ebb: fatal: Unable to open output file File.bb
When clicking in the properties and security of File.png I see that my user both: is the owner of the folder and has all permissions set in (even tho I cannot uncheck any of the permissions I have, weirdly).
The folder which I'm working on has that black square marked on the "read only" attribute (in properties). Which I can't quite keep unchecked even tho I'm the owner of it. What is wrong?
EDIT: Here's what happens when I click on show permissions (>properties >security >advanced >show permissions) my user is the owner.
I can't click on anything even tho I'm the owner.
Edit, the logfile:
LOG FILE :
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.10) (preloaded format=pdflatex 2020.10.24) 25 OCT 2020 10:47
entering extended mode
**./test.tex
(test.tex
LaTeX2e <2020-10-01> patch level 1
L3 programming layer <2020-10-05> xparse <2020-03-03>
("C:\Program Files\MiKTeX\tex/latex/base\article.cls"
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
("C:\Program Files\MiKTeX\tex/latex/base\size12.clo"
File: size12.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
)
\c#part=\count175
\c#section=\count176
\c#subsection=\count177
\c#subsubsection=\count178
\c#paragraph=\count179
\c#subparagraph=\count180
\c#figure=\count181
\c#table=\count182
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)
("C:\Program Files\MiKTeX\tex/latex/graphics\graphicx.sty"
Package: graphicx 2020/09/09 v1.2b Enhanced LaTeX Graphics (DPC,SPQR)
("C:\Program Files\MiKTeX\tex/latex/graphics\keyval.sty"
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV#toks#=\toks15
)
("C:\Program Files\MiKTeX\tex/latex/graphics\graphics.sty"
Package: graphics 2020/08/30 v1.4c Standard LaTeX Graphics (DPC,SPQR)
("C:\Program Files\MiKTeX\tex/latex/graphics\trig.sty"
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
("C:\Program Files\MiKTeX\tex/latex/graphics-cfg\graphics.cfg"
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 105.
("C:\Program Files\MiKTeX\tex/latex/graphics-def\pdftex.def"
File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex
))
\Gin#req#height=\dimen139
\Gin#req#width=\dimen140
)
("C:\Program Files\MiKTeX\tex/latex/l3backend\l3backend-pdftex.def"
File: l3backend-pdftex.def 2020-09-24 L3 backend support: PDF output (pdfTeX)
\l__kernel_color_stack_int=\count183
\l__pdf_internal_box=\box47
) (test.aux)
\openout1 = `test.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
("C:\Program Files\MiKTeX\tex/context/base/mkii\supp-pdf.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count184
\scratchdimen=\dimen141
\scratchbox=\box48
\nofMPsegments=\count185
\nofMParguments=\count186
\everyMPshowfont=\toks16
\MPscratchCnt=\count187
\MPscratchDim=\dimen142
\MPnumerator=\count188
\makeMPintoPDFobject=\count189
\everyMPtoPDFconversion=\toks17
) ("C:\Program Files\MiKTeX\tex/latex/epstopdf-pkg\epstopdf-base.sty"
Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
85.
)
<semirreta.png, id=1, 368.1253pt x 99.37125pt>
[1{C:/Users/JoaoV/AppData/Local/MiKTeX/pdftex/config/pdftex.map}] (test.aux) )
Here is how much of TeX's memory you used:
1167 strings out of 480236
17436 string characters out of 2890433
280939 words of memory out of 3000000
17769 multiletter control sequences out of 15000+200000
535555 words of font info for 31 fonts, out of 3000000 for 9000
1141 hyphenation exceptions out of 8191
60i,4n,66p,199b,236s stack positions out of 5000i,500n,10000p,200000b,50000s
<C:/Program Files/MiKTeX/fonts/type1/public/amsfonts/cm/cmr12.pfb><C:/Program F
iles/MiKTeX/fonts/type1/public/amsfonts/cm/cmtt12.pfb>
Output written on test.pdf (1 page, 13448 bytes).
PDF statistics:
15 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
6 words of extra memory for PDF output out of 10000 (max. 10000000)
I made a little test:
the real image is suposed to be these two lines: https://ibb.co/yYQCfnd
Remove the draft option, this prevents images from showing up

How to crop AI (PDF embedded) to PNG using Ghostscript?

I've read a number of post and tried to follow but it's not working.
Using GS (gsdll32.dll) with the following arguments:
Info from bbox
%%BoundingBox: 33 244 577 546 %%HiResBoundingBox: 33.611976 244.201633
576.009896 545.351819
render and crop AI2PNG
-P-
-dNOPAUSE
-dBATCH
-dSAFER
-q
-IC:/Program Files (x86)/Gerber Scientific Products/OMEGA 6.50/Software/gs/fonts;C:/Program Files (x86)/Gerber Scientific Products/OMEGA 6.50/Software/gs/lib;C:/Program Files (x86)/Gerber
Scientific Products/OMEGA 6.50/Software/gs/resource
-sDEVICE=pngalpha
-g544x302
-c <> setpagedevice
-sOutputFile=E:/Images/AI from PLM/captain-america [Converted].png E:/Images/AI from PLM/captain-america [Converted].ai
Without any cropping logic I get the image on an 8.5 x 11, with cropping(above commands) the objects are translated mostly off the top of the page and do not seem to move to the left.
The size of the result image is correct.
Does anyone see anything wrong?
Thanks
You've put the /Install after the input file, that means it will be executed after the input file is complete. Which means it takes effect after the input is completely processed, which is too late to have nay effect.
Order of switches, and particularly order of input, is important in Ghostscript.
That's assuming that 'AI2PNG' is a synonym for Ghostscript.

ghostscript convert pdf to pcl with wrong orientation

I have an issue trying to convert a pdf document to a pcl document using Ghostscript.
The original pdf document is landscape and so the pcl should be as well. Nevertheless in windows using Ghostscript 9.14 with the following command functions:
gswin32 -dNOPAUSE -dBATCH -sDEVICE=ljet4 -dSAFER -dAutoRotatePages=/NONE -sPAPERSIZE=a4 -sOutputFile=./convert_windows.pcl ./duplicate_windows.pdf
The same command in Ubuntu Linux Kernel Version 3.2.0-40-generic 64 bit - but with Ghostscript 9.05 - results in a wrong orienteated pcl file of size A3 instead of A4 as the original.
The original pdf file contains windows font "arial", which should be available in linux as well. The package "msttorcefonts" is installed on linux. This is an short extract of the fontmap of Ghostscript:
cat /usr/share/ghostscript/9.05/Resource/Init/Fontmap.GS
gives:
% This font, and only this font among the Hershey fonts, uses
% the SymbolEncoding.
/Hershey-Symbol (hrsyr.gsf) ; % 5066567
/Arial /ArialMT ;
/Arial,Bold /Arial-BoldMT ;
/Arial,Italic /Arial-ItalicMT ;
/Arial,BoldItalic /Arial-BoldItalicMT ;
The following listing shows the output of the linux command line, which is the same output as from the windows Ghostscript console!
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Loading NimbusMonL-Bold font from /usr/share/fonts/type1/gsfonts/n022004l.pfb... 3627296 2211468 1767360 473754 3 done.
Loading NimbusSanL-Bold font from /usr/share/fonts/type1/gsfonts/n019004l.pfb... 3668288 2319461 1807728 497748 3 done.
Loading NimbusSanL-Regu font from /usr/share/fonts/type1/gsfonts/n019003l.pfb... 3800176 2466391 1827912 512832 3 done.
Loading NimbusMonL-Regu font from /usr/share/fonts/type1/gsfonts/n022003l.pfb... 3964224 2617715 1969200 654805 3 done.
Page 2
I alredy tried several options of Ghostscript like
-dFIXEDMEDIA
-dNORAGEPAGESIZE
and others.
When converting the pdf document to ps the result is the same on both environments.
Does anyone has experiences with that issue or an idea?
Thanks in advance and kind regards
Its unlikely anyone can help at all without seeing teh original PDF file, so I would suggest that you open a bug report and attach the PDF file there.
A few observations:
-dAutoRotatePages only has an effect when creating a PDF file, not when interpreting one.
The switch -dFIXMEDIA should be -dFIXEDMEDIA, likewise NORAGEPAGESIZE should be NORANGEPAGESIZE
This may be a possible solution, which works in my case. Precondition: Ghostscript Version 8.6.0 or higher!
Converting pdf to ps not with gs command, but with gs wrapper pdf2ps, which is part of the ghostscript package:
pdf2ps input.pdf output.ps
BUT: For landscape pdf documents this works only since version 8.60 or higher! Otherwise landscape documents will be printed in portrait.
Converting pdf to pcl worked for me using the following command:
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=ljet4 -sPAPERSIZE=a4 -sOutputFile=output.pcl -c "<< /InputAttributes << currentpagedevice /InputAttributes get { pop null } forall >> dup 0 << /PageSize [ 595 842 ] >> put >> setpagedevice" save pop -f input.pdf
BUT: This command is based on the documentation of Bug Bug 689919 of ghostscript (refer to http://bugs.ghostscript.com/show_bug.cgi?id=689919) and works for portrait-orientated documents only if you have installed a version 8.60 or higher. Because I have three different environments I can approve, that this command works since version 8.60. I used Versions 8.16, 8.62 and 9.05.
For versions 8.62 and 9.05 of ghostscript both commands worked properly for pdf --> ps and pdf --> pcl for landscape and portrait.

How to make croatian characters show correctly on all platforms in a PDF?

I've created this small Postscript to create a test page:
100 100 moveto
/Courier findfont 10 scalefont setfont
(This is croatian characters test: ) show
/scaron glyphshow
/dcroat glyphshow
/ccaron glyphshow
/cacute glyphshow
/zcaron glyphshow
/Scaron glyphshow
/Dcroat glyphshow
/Ccaron glyphshow
/Cacute glyphshow
/Zcaron glyphshow
showpage
I ran it through ps2pdf shell on Linux (on Fedora 13 and Enterprise release 5), and the resulting PDF shows up good on these systems. However, if I try to open the document on a Windows system (tested on Windows XP, Vista and 7), the characters /dcroat, /ccaron, /cacute, /Dcroat, /Ccaron and /Cacute don't show up at all! Can someone please point me in the right direction about where the problem might be and perhaps the solution?
I've run this through multiple versions of GS, the latest being GPL Ghostscript 8.71 (2010-02-10). The result is always the same. The resulting PDF can be found here (scroll down on the page to see text).
Use gs (Ghostscript) instead of ps2pdf to convert your PostScript file to PDF. (ps2pdf is only a simple wrapper around a Ghostscript commandline anyway.)
As you are using Courier (which is one of the 'base 14' fonts), Ghostscript will by default NOT embed the font into the PDF. That means, you'll have to use some additional commandline magic to enforce the Courier embedding:
gs \
-o croatian-glyphs.pdf \
-sDEVICE=pdfwrite \
-c ".setpdfwrite <</NeverEmbed [ ] /AlwaysEmbed [/Courier]>> setdistillerparams" \
-f croation-glyphs.ps
Note, that when I run this command on my Mac, I see only 4 croatian characters in the output (scaron, Scaron, zcaron and Zcaron). The reason for this is: my Courier here does not have all of the croatian glyphs which were asked for (and hence cannot embed them).
However, if you run this command on a system which has a Courier including the other glyphs, and if you pass me your resulting PDF, I could see the glyphs just fine (since the font, or at least the subset of glyphs in use, is now embedded in the PDF).
Try to embed fonts by using ps2pdf -dEmbedAllFonts=true ...

How to get a LZW tiff with 24 bit depth from pdf file using Ghostscript

I am using Ghostscript9.0, I try to generate a LZW TIFF images with 24 bit depth from pdf file, I always get bit depth = 1 using this GS command:
gswin32.exe -dSAFER -dBATCH -dNOPAUSE -r200 -sDEVICE=tifflzw -sOutputFile=tmp.tiff myfile.pdf
I searched in several manuals:
http://ghostscript.com/doc/current/Devices.htm
http://www.ghostscript.com/doc/8.54/Use.htm
but I didn't find anything of parameters to do that.
I add an image example proporties that I would like to produce with gs:
Here we can see the bit depth (profondeur de couleur) = 24 and the image is compressed with LZW
It is clearly stated that the format tifflzw you have chosen is located in the section
The remaining TIFF drivers all
produce black-and-white output with
different compression modes
http://ghostscript.com/doc/current/Devices.htm
If you want a 24bit output you have to use tiff24nc instead and add specify the compression via the parameter -sCompression=lzw
gswin32.exe -dSAFER -dBATCH -dNOPAUSE -r200 -sDEVICE=tiff24nc -sCompression=lzw -sOutputFile=tmp.tiff myfile.pdf

Resources