Win10 :Print_to_pdf in batch mode, without prompt for file name

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
marpon
Posts: 321
Joined: Dec 28, 2012 13:31
Location: Paris - France

Win10 :Print_to_pdf in batch mode, without prompt for file name

Postby marpon » Mar 08, 2019 19:01

static lib in 32 or 64 version to print to pdf.
In fact convert files to pdf, with and without need of virtual printer 'Microsoft Print to Pdf'


can be found here, libs
https://github.com/marpon/Print_to_Pdf

an example of use , very simple code corrected version last edited 09 march 2019 13h00 Paris time

Code: Select all

/' test example to use libPrint2Pdf32.a or libPrint2Pdf64.a
   version 1.0 by marpon  08 March 2019
            contact marpon@aliceadsl.fr


   work in win10 with 'Microsoft Print To Pdf' virtual printer
      but much better because can be used in batch mode, without prompt for target file name

   but can also work stand-alone for differents file types
      raw text  as       "txt", "log", "lst", "bas", "bi", "inc", "me",
                     "c", "cpp", "h", "hpp", "cxx", "hxx", "inf",
                     "bat" , "cmd" and even  ""   (ex for makefile)

      pictures  as      "bmp", "jpg", "jpeg", "png", "tiff", "gif"
            it will try to reproduce the 'real size' checking dimensions and dpi resolution
            and try also to best fit , so rotate 270° when needed.


 '/

#include once "./print2pdf.bi"      ' for pdf convertion : txt, pictures
                           '  and more if exists 'Microsoft print to pdf' virtual printer



'usage
'==============================================================================


dim as string s_in = $"D:\freebasic\testlib\ms_word.doc"         'notice $ in front of string to avoid warning possible escape sequence on backslash
dim as string s_out = $"D:\freebasic\testlib\ms_word_doc.pdf"     ' or ! in front of string to say use escape sequence with \\ for backslash


print "return = " &  print2pdf(strptr(s_in),strptr(s_out), 1)      'notice here without verbose mode, no need for third argument
print : print

 s_in = $"D:\freebasic\testlib\plan.bmp"
s_out = $"D:\freebasic\testlib\plan_bmp.pdf"
print2pdf(strptr(s_in),strptr(s_out),1)               'notice here in verbose mode, third argument <>0,  if no console opens 1 console



s_in = $"D:\freebasic\testlib\penguin.jpg"
s_out = $"D:\freebasic\testlib\penguin_jpg.pdf"
print2pdf(strptr(s_in),strptr(s_out),1)               'notice here in verbose mode, third argument <>0,  if no console opens 1 console


s_in = $"D:\freebasic\testlib\blabla.txt"
s_out = $"D:\freebasic\testlib\blabla_txt.pdf"
print2pdf(strptr(s_in),strptr(s_out))               'notice here without verbose mode, no need for third argument

 


remarks, tests... do not hesitate to conct me!
Last edited by marpon on Mar 18, 2019 8:05, edited 2 times in total.
jj2007
Posts: 1134
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Win10 :Print_to_pdf in batch mode, without pronpt for file name

Postby jj2007 » Mar 08, 2019 19:39

Does it miss a file?

Code: Select all

ld.exe: cannot find -lpdfgen32
marpon
Posts: 321
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Win10 :Print_to_pdf in batch mode, without pronpt for file name

Postby marpon » Mar 09, 2019 9:05

@jj2007

True, sorry , I've put the wrong debug libs.
i'll will try to put the right final working libs / .bi file and example of use in next 4 or 5 hours.

right now i'm blocked on one subject to continue more features to the lib :
How to merge existing pdf into one, did not found any simple code in c (nor obviously in freebasic) to do that.

I've already done that on previous life using Pdfcreator, via COM object code and powerbasic,
but now i'm trying to avoid Pdfcreator installation.

Also because Pdfcreator i've modified totaly their code, so now my code does not work with their actual COM objects,
and I think the previous free application was more powerfull than the actual one :
They are pushing the usage for paid versions for ...
marpon
Posts: 321
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Win10 :Print_to_pdf in batch mode, without pronpt for file name

Postby marpon » Mar 09, 2019 12:08

updated version in Github
the old version removed

the example file corrected in first topic.


Now, still searching a simple way to merge pdf into 1.

Marpon
jj2007
Posts: 1134
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Win10 :Print_to_pdf in batch mode, without pronpt for file name

Postby jj2007 » Mar 10, 2019 0:16

Great stuff, marpon! Here is a condensed test file using #define path and #define win10:

Code: Select all

#define PdfPath "C:\FreeBasic\Print_to_Pdf-master"
#define Win10   1   ' put 0 if you run it on older Windows versions
 /' test example to use libPrint2Pdf32.a or libPrint2Pdf64.a
   version 1.0 by marpon  08 March 2019
            contact marpon@aliceadsl.fr
 '/

#include once "./print2pdf.bi"      ' for pdf convertion : txt, pictures
                           '  and more if exists 'Microsoft print to pdf' virtual printer
'usage
'==============================================================================
#if Win10
dim as string s_in = PdfPath+"\ms_word.doc"
dim as string s_out = PdfPath+"\ms_word_doc.pdf"

print "return = " &  print2pdf(strptr(s_in),strptr(s_out), 1)      'notice here without verbose mode, no need for third argument
print : print
#else
  Dim as string s_in, s_out
#endif

s_in = PdfPath+"\plan.bmp"
s_out = PdfPath+"\plan_bmp.pdf"
print2pdf(strptr(s_in),strptr(s_out),1)               'notice here in verbose mode, third argument <>0,  if no console opens 1 console

s_in = PdfPath+"\penguin.jpg"
s_out = PdfPath+"\penguin_jpg.pdf"
print2pdf(strptr(s_in),strptr(s_out),1)               'notice here in verbose mode, third argument <>0,  if no console opens 1 console


s_in = PdfPath+"\blabla.txt"
s_out = PdfPath+"\blabla_txt.pdf"
print2pdf(strptr(s_in),strptr(s_out))               'notice here without verbose mode, no need for third argument
marpon
Posts: 321
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Win10 : Print_to_pdf in batch mode, without prompt for file name

Postby marpon » Mar 16, 2019 11:37

last updated version 1.2 in https://github.com/marpon/Print_to_Pdf

the main changes are (see in Print2Pdf.bi file)
the returned error codes ;
the new function to check if 'Microsoft Print to Pdf' in available ( group check if win10 version and if virtual printer installed)

a new sample code Print2Pdf.bas to build a simple cmd line tool Print2Pdf.exe
it can be compiled in console or gui but the better option is compiling to gui , because it can give when needed a console for follow-up


as always send remarks...

marpon
jj2007
Posts: 1134
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Win10 :Print_to_pdf in batch mode, without pronpt for file name

Postby jj2007 » Mar 16, 2019 14:27

Works fine, compliments! What I find slightly odd is that Acrobat reader asks me, when closing the doc, whether I want to save changes.
marpon
Posts: 321
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Win10 :Print_to_pdf in batch mode, without prompt for file name

Postby marpon » Mar 18, 2019 8:16

You are true again,
it happens with the raw text file types , my conversion is probably not totally compliant with the last pdf versions, i am using a very rudimentary 1.1/1.2 pdf format to do that quickly.

I will see if i can improve that. I know i could use also for that raw text , 'Microsoft Print to Pdf', but i wanted to avoid it usage because i do not like the way it converts, putting extra stuff (footprint...) , i will see.

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 0 guests