Page 1 of 1

PDF Manipulation in PB? PDF to TIF Conveter

Posted: Wed May 30, 2012 2:28 pm
by treebolt
Can this be done in PureBasic? I need to basically convert PDF to TIF in PB.

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Wed May 30, 2012 3:57 pm
by IdeasVacuum
I think you possibly need a GhostScript license to do it. It's an unusual requirement........
Maybe DIY, here's the PDF spec: http://www.adobe.com/devnet/pdf/pdf_reference.html

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Thu May 31, 2012 7:54 pm
by morosh
using pdf2image (from www.verypdf.com), it can be launched from a command line. then using
RunProgram("pdf2img.exe" -i file1.pdf -o file1.tiff -b 1 -c lzw -r 300")
you can get what you want, but it's not free :(

Regards

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Fri Jun 01, 2012 12:36 am
by acreis
I think you can use xpdf, it's free.

http://www.foolabs.com/xpdf/index.html

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Fri Jun 01, 2012 4:38 am
by IdeasVacuum
Xpdf is only free if you are going to use it as-is without modification. Otherwise you have to either distribute your own app under GPL, or buy a commercial license for Xpdf.

Another possibility would be to run a script that opens the PDF in Adobe Reader, screen-capture each page, save as TIF. There is an AutoIt wrapper for PB: http://www.purebasic.fr/english/viewtop ... =5&t=49438

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Fri Jun 01, 2012 8:44 am
by Kukulkan
We are using a tool for this. It is QuickPDF library. It costs money, but it is very powerfull.

http://www.quickpdflibrary.com/

It costs minimum $349.00 (single developer licence), but there are no runtime licences needed. It is definitely worth the price, because it saved me so many days and gives professional features to our product...

There is also a free version with limited functionality. Maybe it is enough for your needs?

Kukulkan

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Fri Jun 01, 2012 10:45 pm
by IdeasVacuum
That certainly looks like a very nice lib. The lite version though is not as good as PurePDF.

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Sun Jun 03, 2012 6:51 pm
by treebolt
Thanks everyone for all the input
morosh wrote:using pdf2image (from http://www.verypdf.com), it can be launched from a command line. then using
RunProgram("pdf2img.exe" -i file1.pdf -o file1.tiff -b 1 -c lzw -r 300")
you can get what you want, but it's not free :(

Regards
I like this method the best honestly. It provides what I need the quickets without having to use libraries to write my own converter. I wish they would let me use the command line version in the trial. When I try it opens the app asking me to register first. Probobly will buy this once I get go ahed from my boss. In your command line example you have this

Code: Select all

"pdf2img.exe" -i file1.pdf -o file1.tiff -b 1 -c lzw -r 300"
I assume
-b = bits per pixel
-c = compression (I hope CITTFAX4 is supported... im sure it is)
-r = DPI resolution of output

am i correct? the website and trial application do not give help on command line parameters. Thank you.

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Sun Jun 03, 2012 7:45 pm
by morosh
here you have the meaning of all parameters:

Command Line Usage:

C:\>pdf2img.exe
-------------------------------------------------------
PDF To Image Converter Copyright @2000 - 2006 verypdf.com Inc
Description:
Convert PDF to TIF, TIFF, JPG, GIF, PNG, BMP, WMF, EMF, PCX, TGA, etc. formats
Release Date: Oct 13 2004
Usage: pdf2img [options] <-i PDF File> [-o Output]
-i [input PDF file] : Specify input PDF filename
-o [output TIF file] : Specify output TIFF filename
-g : Convert to 8-bit grayscale image file, this option
is only available while bitcount equal 8 (-b 8)
-m : Set output to multi-page TIFF file, the
default is output to single page TIFF files
-r [resolution] : Set resolution in generated image files
-r 300 : Set horizontal and vertical resolution to 300 DPI
-r 200x300 : Set horizontal and vertical resolution to 200x300 DPI
-r 204x98 : Set horizontal and vertical resolution to 204x98 DPI
-f [first Page] : First page to convert
-l [last Page] : Last page to convert
-c [compress] : Set compression method in generated image
files (for tif only)
-c none : Create TIFF file without compression
-c lzw : Compress TIFF using LZW arithmetic
-c jpeg : Compress TIFF using JPEG arithmetic
-c packbits : Compress TIFF using packbits arithmetic
-c g3 : Compress TIFF using CCITT G3 arithmetic
-c g4 : Compress TIFF using CCITT G4 arithmetic
-c ClassF : Compress TIFF into Fax compatible ClassF 204x98 format
-c ClassF196 : Compress TIFF into Fax compatible ClassF 204x196 format
-q [quality] : Set quality in generated image files (for jpeg image only)
-b [bit count] : Set bit count in generated image files
-? : Help
-------------------------------------------------------
Example:
pdf2img -i C:\input.pdf -o C:\output.tif
pdf2img -m -i C:\input.pdf -o C:\output.tif
pdf2img -c lzw -i C:\input.pdf -o C:\output.tif
pdf2img -q 80 -i C:\input.pdf -o C:\output.jpg
pdf2img -b 4 -i C:\input.pdf -o C:\output.tif
pdf2img -i C:\input.pdf -o C:\output.tif -b 1 -c ClassF -r 204x98 -m
pdf2img -f 1 -l 9 C:\input.pdf -o C:\output.jpg
pdf2img -i C:\*.pdf -o C:\*.pcx

Please notice, if your input pdf's filename or output tiff's filename contain space(s), you must use quotation mark to include them, for example,

C:\>pdf2img "C:\123 456.pdf" "C:\my test\aaa.tif"

Re: PDF Manipulation in PB? PDF to TIF Conveter

Posted: Wed Jun 06, 2012 4:00 pm
by ABBKlaus
im using Ghostscript without any problems, here“s the code :

Code: Select all

;http://www.ghostscript.com/download/
;Put in GS$ the path to Ghostscipt
GS$="c:\Program Files\gs\gs9.05\"
GSLib$=GS$+"lib"
GSFonts$=GS$+"fonts"
GSCmd$=GS$+"bin\gswin32c.exe"

FileName$=OpenFileRequester("Please choose a file","","PDF (*.pdf)|*.pdf",0,#PB_Requester_MultiSelection)
index=0
While Len(FileName$)
  index+1
  Debug Str(index)+" "+FileName$
  Filepart$=GetFilePart(FileName$)
  Pathpart$=GetPathPart(FileName$)
  Extpart$=GetExtensionPart(FileName$)
  NewName$=Left(Filepart$,Len(Filepart$)-(1+Len(Extpart$)))+"_P%04d.tif"
  command$="-I"+Chr(34)+GSLib$+";"+GSFonts$+Chr(34)+" "
  command$+"-sDEVICE=tiffg3 "
  command$+"-dNOPAUSE "
  command$+"-dSAFER "
  command$+"-dBATCH "
  command$+"-sPAPERSIZE=a4 "
  command$+"-r600"
  parameter1$=command$+" -sOutputFile="+Chr(34)+Pathpart$+NewName$+Chr(34)+" "+Chr(34)+FileName$+Chr(34)
  parameter2$=Pathpart$
  ProgramID=RunProgram(GSCmd$,parameter1$,parameter2$,#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
  If ProgramID
    Output$=""
    While ProgramRunning(ProgramID)
      If AvailableProgramOutput(ProgramID)
        Output$ + ReadProgramString(ProgramID) + Chr(13)
      EndIf
    Wend
    Exitcode=ProgramExitCode(ProgramID)
    If Exitcode
      MessageRequester("Ghostscript","Exitcode="+Str(Exitcode))
    Else
      If Len(Output$)
        ;MessageRequester("Ghostscipt",Output$)
      EndIf
    EndIf
  EndIf
  FileName$ = NextSelectedFileName()
Wend