PDF/A compatibility processing color gradients in Ghostscript - gradient

I have this PDF image which contains color gradients. I want to convert it to a PDF/A with Ghostscript 9.22. My command is
gs -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dSAFER -sColorConversionStrategy=UseDeviceIndependentColor -dCompressFonts=true -dEmbedAllFonts=true -dPDFA -dPDFACompatibilityPolicy=1 -dDetectDuplicateImages=true -dFastWebView=true -sOutputFile=$2 $1
but I got the following errors when trying to validate the result with PDFBox preflight:
2.4.3 : Invalid Color space, DestOutputProfile is missing
2.4.3 : Invalid Color space, DestOutputProfile is missing
2.4.3 : Invalid Color space, DestOutputProfile is missing
2.4.3 : Invalid Color space, The operator "f" can't be used without Color Profile
I thought I have to tell Ghostscript to use a color profile in the output, so I tried these parameters separately and together
-sOutputICCProfile=/usr/share/color/icc/CoatedFOGRA39.icc -sProfileOut=/usr/share/color/icc/CoatedFOGRA39.icc -sPostRenderProfile=/usr/share/color/icc/CoatedFOGRA39.icc
without luck (I have the profile in that path).
What can I do?
Note: The figure is built with TikZ and is part of a document: I actually would like to have the whole document to be compliant, but it fails just on this figure.

You haven't specified a PDFA_def.ps file. This is a requirement, it is not optional, and you must edit the contents to be correct. You can only specify the DestOutputProfile using the means outlined in the PDFA_def.ps file (basically a bunch of pdfmarks).
The steps are documented here
I'm not certain, but I would not use FastWebView to create a PDF/A file, I'm not sure that linearised files can be PDF/A compliant. Its also more or less pointless anyway.

Related

papaja: Changing font sizes and faces for code listings and R output

Based on the answer to this question, I was able to get 2-column papaja with listings wrapping (rather than overflowing column width). But the listings package turns off various features that help code listings and R output stand out relative to the main text.
A simple solution would be if I could globally change the font faces and/or sizes selectively for code and R output. Is there a way to do that in papaja? I haven't been able to figure this out from papaja or Rmarkdown documentation. Thank you!
When you use the listings package in a papaja (or bookdown) document, what is technically happening is that all code is wrapped into an lstlisting LaTeX environment that comes with its own capabilities of customizing code appearance. Hence, you don't see the syntax highlighting that you would otherwise see if you would not use the listings package. The documentation of the listings package with instructions how to style your code can be found here.
To make use of this, you can extend the YAML header of your papaja document like this:
documentclass : "apa6"
classoption : "jou"
output :
papaja::apa6_pdf:
pandoc_args: --listings
header-includes:
- \lstset{breaklines=true,language=R,basicstyle=\tiny\ttfamily,frame=trB,commentstyle=\color{darkgray}\textit}
Here, I first specify the code's language, and use a tiny monospace font. With frame, I add a frame around the code block, and with commentstyle I set comments in italic and gray.

Clear font.ttf from unused glyphs

For example I want to use this .ttf font file:
https://www.onlinewebfonts.com/download/3b2646a48566403a55f62ceddbecbe18
It contains 29,064 glyphs.
I want to leave in it only the letters I use.
A short example: どこでもタップしてプレイ
So, from 29,064 it will be only 12 characters left. In my actual situation if will be around 300 glyphs.
Basically, I want to dramatically decrease it's file-size by removing unused glyphs
Is there a way to implement this by some script? I'm on macOS.
Or some app can do this and how exactly? Is there a real life example?
upd: answer from this question not working, throwing errors:
./subset.pl --chars="どこでもタップしてプレイ" /Users/User/Desktop/1.ttf /Users/User/Desktop/2.ttf
Wide character in subroutine entry at Font/Subsetter.pm line 1496.
In that question there are recommendation of use fixed this bug repo: https://github.com/fnp/librarian/blob/master/librarian/font-optimizer/subset.pl
And with it executing same command gives another errors:
Uses unhandled table 'BASE'
Uses forbidden table 'CFF '
As font file I used that from first link, just renamed it to 1.ttf

Detecting location of any text in an image in opencv using c++

http://www.2d3dfloorplans.com/wp-content/themes/default/images/2dfloorplans_1.jpg is my input image. I would like to remove texts from this image. (For ex. Bedroom, 11'X12', Closet...). Note: I want to remove automatically. Not manually.(When I run my code. Texts will be removed. I won't remove manually).
If you know all the possible text variations, and there not too many of them, (individual words can be split) then you can detect them using template matching technique. Once a word is detected you can overlay it's region with a background color.
http://docs.opencv.org/doc/tutorials/imgproc/histograms/template_matching/template_matching.html
suggested code stucture:
program/
samples/
sample1.png # image with a "Bedroom" text
sample2.png # rotated image with "Bedroom" text
sample3.png # ...
sample4.png # etc
src/
main.cpp
readme.txt
makefile
main reads image from argv and applies each template from samples folder to it. Once text is found it then uses some logic to overlay the occupied region.
Try to run an OCR algorithm on the images and delete the regions detected by the OCR algorithm.

Can't save figure as .eps [gswin32c is not recognized]

I'm using Enthought Canopy with PyLab(64-bit). For my report I need to use Latex (XeLaTex) and the plots are done with matplotlib.
To have an first idea I just copied the second example from http://matplotlib.org/users/usetex.html and compiled it. It looks fine and I can save it as a normal png without problems. However if i try to save it as .eps or.ps it does not work and an error appears:
invalid literal for int() with base 10: "
Additionaly in the Pylab shell it shows:
'gswin32c' is not recognized as an internal or external command, operable program or batch file'.
If I save it as .pdf I have no problems except the text is all black instead of being red and blue. This is a problem because in my plots I have two axes and I need them colorized for better readability.
If I then try to delete some lines from the example given (all text) I still cannot save it as .eps nor .ps. I can't figure out the problem and all the other topics related to this have not given me an insight. So I really need your help because I can't use .png for my report.
Thank you in advance!!!
I finally managed to solve this problem. It might look weird but maybe other people can benefit from it.
The solution might depend upon the software you use. I use Enthought Canopy (Python) and MikTeX 2.9 under W8 64bit.
If you want to output .ps and .eps files with matplotlib using the 'text.usetex': True option then you will encounter the problem posted above.
Solution:
Download and install Ghostscript (32bit) from http://www.ghostscript.com/download/gsdnld.html.
Download ps2eps-1.68.zip from http://www.tm.uka.de/~bless/ps2eps. The proceeding is given in the manual, however I like to point out the part with the environment variables. In this last step you need to go to Control Panel --> System --> Advanced system settings. Then click on the header 'Advanced' and on the bottom of the window you see 'Environment Variables' on which you click. Then you use the 'New'-Button for User Variables for USERNAME. Then you type in as variable name 'ps2eps' and for variable value you type in the actual path where you have saved the ps2eps.pl file. In my case this is 'C:\Program Files (x86)\ps2eps\bin\'. You can check if you type 'ps2eps' in the command-window.
Download xpdfbin-win-3.03.zip from http://www.foolabs.com/xpdf/download.html. You only need the file 'pdftops.exe'. However I could not assign a path like in step 2. I solved this by putting the 'pdftops.exe' in the MikTeX 2.9 folder. The exact location for me was 'C:\Program Files\MiKTeX 2.9\miktex\bin\x64'.
I was then able to save figures as .ps and have no more any error messages. Remember to use the settings proposed on http://matplotlib.org/users/usetex.html under 'postscript options'.
In myself used the following settings:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.rc('font', **{'family':'serif', 'serif':['Computer Modern Roman'],
'monospace':['Computer Modern Typewriter']})
params = {'backend': 'ps',
'text.latex.preamble': [r"\usepackage{upgreek}",
r"\usepackage{siunitx}",
r"\usepackage{amsmath}",
r"\usepackage{amstext}",],
'axes.labelsize': 18,
#'axes.linewidth': 1,
#'text.fontsize':17,
'legend.fontsize': 10,
'xtick.labelsize': 13,
#'xtick.major.width' : 0.75,
'ytick.labelsize': 13,
'figure.figsize': [8.8,6.8],
#'figure.dpi': 120,
'text.usetex': True,
'axes.unicode_minus': True,
'ps.usedistiller' : 'xpdf'}
mpl.rcParams.update(params)
mpl.rcParams.update({'figure.autolayout':True})
(whereas many of the params are just for my own purpose later in the plots)
As a beginner I am not well informed about the dependence from the 'backend' used if you are running a script from your python console. I however used this without any --pylab settings in before and I do not know if one needs to switch the backend manually if he is working already in a console with a specific matplotlib backend.
I had the same problem and my problem was a font adjustment in the python code that is :
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)
when I remove this iit works fine and now i can save eps.
So be sure that any shortest working example is working for you or not then check the font and other style edits in your code. This may help.

How to get paper.print() to work?

I have been trying to get the following Raphael code to just write something on the screen with no luck!
paper.print(30, 15, "TEXT", paper.getFont("Arial"), 20).attr({fill: "black"});
Is there anything else you need to do to get the text in the paper?!?!!?
You need to cufonize a font, being sure to indicate that the cufonized font should register itself with Raphael, and include the resulting .js file before you can use getFont to retrieve it (there are no fonts available by default). If you check, I'm reasonably sure you'll find that paper.getFont("Arial") is returning undefined.
Cufon essentially converts every glyph in a provided font into its vector equivalent -- Raphael simply transforms and sequences those paths to produce output.