best solution for sending fax in asterisk - pdf

I want to write a script for sending a fax with Asterisk,
but many faxes have an error when sending.
I use Spandsp for Asterisk and I use gs for converting PDF to TIFF.
I think it may be a problem of converting PDF to TIFF.
I very try to convert's command for this, such as:
gs -q -sDEVICE=tiffg3 -dNOPAUSE -dBATCH -sOutputFile=Sample.pdf.tif -f Sample.pdf
/usr/bin/acroread -toPostScript -size a4 <filename>
/usr/bin/gs -q -sDEVICE=tiffg32d -sPAPERSIZE=a4 -r204x196 -sOutputFile=<outputfile> -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dNOPAUSE -dBATCH -f <inputfile.ps>
and I tested anyways into link for converting, but it doesn't work fine, and most of sending fax have issue.
Also, I have another problem in answer detection beep in my Asterisk when the trunk with Newrock gateway(analog), this is cause some fax doesn't send correctly!

Check hylafax code. It have working script
I use code like this:
gs -sDEVICE=tiffg3 -sPAPERSIZE=$pagesize -r204x196 -dNOPAUSE -dNOPAGEPROMPT -dBATCH -sOutputFile=dest.tif \
-c save pop -f input.pdf -c quit
But actualy it doesn't metter. More important how setup your routes/codecs.
Other problem is for sure offtopic here. You have read more books or hire expert.

Related

ghostscript pdf to postscript conversion taking long time

I am trying to convert 1000 pages PDF document to postscript file using the below command.
gswin32c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=out.ps -f input.pdf
It takes 5 mins to convert, but in real-time, I will have more number of pages than this. I have tried with 30k pages pdf to convert ps using the same command. It takes 45mins.
After search in stack overflow, I have tried the below options of reducing resolution, set buffer memory, threading options, and all. Nothing worked. PF command below.
gswin32c.exe -q -r300 -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=out.ps -dNumRenderingThreads=8 -dBufferSpace=2000000000 -f input.pdf
dCompressEntireFile option also not helps. Please, anyone, suggest improving the performance of ps conversion with Ghostscript.

When adding a -c option to a Ghostscript command the printer popup appears even though it has been suppressed

Consider the following ghostscript command invoked form the command line on windows.
"C:\Program Files\gs\gs9.23\bin\gswin64c.exe" -sDEVICE=mswinpr2 -dORIENT1=false -dNOPROMPT -dNOPAUSE -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNOPAGEPROMPT -dQUIET -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" "c:\print\download\133679.pdf"
This command works great. The print comes out and there is no pop up box. Now I add the following.
-c "<</Orientation 2>>setpagedevice"
to the above command to make
"C:\Program Files\gs\gs9.23\bin\gswin64c.exe" -sDEVICE=mswinpr2 -c "<</Orientation 2>>setpagedevice" -c "quit" -dORIENT1=false -dNOPROMPT -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" "c:\print\download\133679.pdf"
the print window appears. I have changed no other part of the command. What is causing this to happen? How can I stop the print window appearing?
The order of operands to Ghostscript is important. Especially when using the -c switch, which introduces PostScript to be executed.
Effectively you are running two commands here:
-sDEVICE=mswinpr2 -c "<</Orientation 2>>setpagedevice" -c "quit"
-dORIENT1=false -dNOPROMPT -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" "c:\print\download\133679.pdf"
As soon as it hits the -c Ghostscript stops processing the command line, and runs the PostScript. At this point we have not yet encountered the -dNOPROMPT, and as you haven't (yet) set the printer, Ghostscript doesn't know what printer to use so , unsurprisingly, the printer popup appears.
Ghostscript carries on processing the remainder of the command line as PostScript until it reaches a -f, or in fact any switch beginning -. You haven't put a -f in there, but I would very strongly recommend that you do. You also don't need to put a secopnd -c, once you've started processing the command line as PostScript it continues, until you stop it. I also suspect that you really don't want the quit in there. That terminates the interpreter, which means the changes you've introduced via setpagedevice will be discarded, because the interpreter returns to the default state.
After processing the content of the -c, Ghostscript carries on and processes the remainder of the command line. This time there's a -dNOPROMPT so you don't get prompted.
I would expect that this:
"C:\Program Files\gs\gs9.23\bin\gswin64c.exe" -sDEVICE=mswinpr2 -dORIENT1=false -dNOPROMPT -dPrinted -dBATCH -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" -c "<</Orientation 2>>setpagedevice" -f "c:\print\download\133679.pdf"
would work much better. Note your initial command line has a duplicate NOPAUSE and specifies both NOPROMPT and NOPAGEPROMPT (you don't need NOPAGEPROMPT if you set NOPROMPT, and you don't need either if you set NOPAUSE).
Finally I would urge you not to use -dNOSAFER, while it currently has no effect (because that's the default setting) we will soon be making SAFER the default and setting -dNOSAFER will substantially reduce your security when running files.
You should really use -dSAFER right now. There are a number of CVEs against this, and proof of concepts circulating right now which can have undesirable effects on your computer (running arbitrary executables, opening, writing, deleting files etc) if you don't use -dSAFER. If you don't know why you want -dNOSAFER, then use -dSAFER instead.
Oh, you should also upgrade to the current version, 9.27, the version you are using is a year old.

How to merge all PDF's in a directory with ghostscript

How can I read the files contained in the directory d:\ with batchscript not one by one files like that. I have tried the following:
#echo off
"C:\Program Files\gs\gs9.25\bin\gswin32c.exe" -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dPDFSETTINGS=/printer -dColorImageResolution=90 -dAutoRotatePages=/None -dBATCH -dNOPAUSE -sOutputFile=d:\d\koran.pdf *d:\a\01.pdf d:\a\02.pdf d:\a\03.pdf d:\a\04.pdf d:\a\05.pdf d:\a\06.pdf d:\a\07.pdf d:\a\08.pdf d:\a\09.pdf d:\a\10.pdf d:\a\11.pdf d:\a\12.pdf d:\a\13.pdf d:\a\14.pdf d:\a\15.pdf d:\a\16.pdf d:\a\17.pdf d:\a\18.pdf d:\a\19.pdf d:\a\20.pdf d:\a\21.pdf d:\a\22.pdf d:\a\23.pdf d:\a\24.pdf*
exit
Ghostscript doesn't 'merge' PDF files. It creates new PDF files by interpreting the contents of its input, this is not the same thing. You should read the documentation here
You haven't said what the problem is with the command you have tried, its going to be hard to help you if you don't do that.
The most likely problem is that you have put * characters at the start and end of the input filenames. Ghostscript itself doesn't match wildcards, it expects you to tell it each file you want to process individually. So in order to process a directory of files is to first get a list of all the files, and then tell Ghostscritp to use each of those files in turn.
You can use the Ghostscript #filename syntax (documented here)to tell Ghostscript to use the contents of a file as if it were the command line.
So all you need to do is come up with a shell script which will write the filenames from a folder into a file. That's not a Ghostscript question, and depends totally on the operating system you are using.
For Windows something like:
dir /B *.pdf >> files.txt
gswin32c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=\temp\out.pdf #files.txt
del files.txt
might be sufficient for your needs.
I could not make it work using "files.txt" but I am using this and everything works just fine.
gswin64c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile="out.pdf" (Get-ChildItem -Path .\*.pdf)
You can execute like below:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf *.pdf
Reference:
https://gist.github.com/moaazsidat/b94185e9cfdba9e3cfb5bc90407e6397

How to remove right and left margins from a PDF file using Ghostscript or any other command line tool?

I've been trying several GS commands to remove the margins from right and left side of a PDF file such as:
gs \
-q -dNOPAUSE -dBATCH \
-sDEVICE=pdfwrite \
-dSAFER \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/printer \
-dSubsetFonts=true \
-dEmbedAllFonts=true \
-sPAPERSIZE=a4 \
-sOutputFile=d:\\ghost\\gs\\bin\\shiftedgulf.pdf \
-c <</BeginPage{0.9 0.9 scale 29.75 42.1 translate}>> setpagedevice \
-f d:\\ghost\\gs\\bin\\gulf.pdf"
but its like nothing is happening, my question is there any effective, direct and clear way to achieve this ?
Maybe this questions is duplicated but I tried most of the scripts and none of them is giving me any result, any other command line tool might be suggested is fine as well.
PDF files don't have 'margins'. The content is placed on the page, which may leave white space at the edges of the media, but its not a margin as such.
I'd need to see the PDF file to have any chance of figuring out what you're trying to achieve, and why what you are doing doesn't work. Setting the PAPERSIZE to A4 seems like a bad start though. You probably want to set a specific medi asize and set -dFIXEDMEDIA so that the PDF interpreter doesn't overrride it.
You may want to study this other Stackoverflow answer to a similar question
PDF - Remove White Margins
and you'll probably be able to achieve what you want....
Thank you all for the answers i found very easy and direct to the point tool, it called briss all you need is downloading the JAR briss-0.0.14 and run the command :
java -jar briss-0.0.14.jar -s original.pdf -d cropped.pdf -c 0.11/0.08/0.11/0.08:0.11/0.08/0.11/0.08
and thats all :)

GhostScript removes images from some processed PDF files

I'm using this command with gs 9.01:
gs -q -dAutoRotatePages=/None -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -sOutputFile=out.pdf in.pdf in.pdfmarks
and on some processed files (out.pdf) I noticed that images are missing, although present in input file (in.pdf).
Why is this and how can I assure that images are retained after processing with gs?
1) Update to the current version, 9.04.
2) If you still experience problems, report a bug at http://bugs.ghostscript.com. You will need to attach a sample PDF file