Revisiting PDF Forms

Discussion in 'Feature: Requests and Planning' started by Graham, Sep 15, 2012.

  1. Graham

    Graham Developer Staff Member

    Synapse has a PDF Forms facility that was written a while back. It differs from Acroforms which uses Acrobat form technology. Instead it uses a bitmap image of the PDF which you then place text on to, then Synapse merges the changes with the original PDF (actually EPS ). Because the govt here changes my forms monthly it is becoming way too much work to update Acroforms so I am looking to use PDF forms again.

    Here's an introduction on how to create the files needed

    1. Extract the PDF page you need if it's a multi-page PDF. You can use PDFTK for this .. just google where to download it. So the following command will split the PDF into separate single page PDFs
      • pdftk input.pdf burst
    2. Create the PNG image of the PDF that Synapse will put text on to
      • gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300
        -sOutputFile=tiger.png tiger.pdf
    3. Create the EPS version of the same PDF
      • gswin32c -o tiger.eps -sDEVICE=epswrite tiger.pdf
    4. Copy both of these files ( tiger.eps and tiger.png ) to the Synapse directory, and then create the fields needed in Settings/Forms/PDFForms
  2. Graham

    Graham Developer Staff Member

    And here's a script to automate that process

    Code:
    Rebol [
        title: "PDF Forms Utility"
        author: "Graham Chiu"
        rights: 'BSD
        date: 16-Sep-2012
        file: %pdf-forms-util.r
        purpose: {
            downloads a PDF, splits into single pages, and creates PNG and EPS versions for each page numbering them as 1 .. n
            Needs ghostscript and PDFTK installed
        }
    ]
     
    sources: [
        http://www.pharmac.govt.nz/2012/09/01/SA1187.pdf
        http://www.pharmac.govt.nz/2012/09/01/SA1157.pdf
    ]
     
    foreach link sources [
        cnt: 1
        print rejoin [ "Downloading " link " now" ]
        pdf: last split-path link
        root: copy/part pdf find pdf %.pdf
        write/binary pdf read/binary link
        ; remove all previous pages
        attempt [ delete pg_*.pdf ]
        print "bursting"
        call/wait rejoin [ "pdftk " pdf " burst" ]
        ; now convert each of the pages created
        forever [
            either exists? single-pdf: rejoin [ %pg_ next form 10000 + cnt %.pdf ] [
                print rejoin [ "creating " root "-" cnt %.png ]
                script: rejoin [ "gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 -sOutputFile="
                    rejoin [ root "-" cnt %.png ] " " single-pdf ]
                call/wait script
                print rejoin [ "creating EPS " root "-" cnt %.eps ]
                script: rejoin [ "gswin32c -o " rejoin [ root "-" cnt %.eps ] " -sPAPERSIZE=a4 -sDEVICE=epswrite " single-pdf ]
                call/wait script
                cnt: cnt + 1
            ][
                ; no page, so go to next download
                break
            ]
        ]
    ]
     
    print "Run finished"
    halt
  3. Graham

    Graham Developer Staff Member

    I've added a render with grid button so that you can more easily place the fields on the PNG
  4. Jason

    Jason Developer / Handyman Staff Member

    I'd love to create some new forms.
  5. Graham

    Graham Developer Staff Member

    This works for single page forms .... is that what you want? If multipage, you'll have to do each page separately or use acroforms
  6. Jason

    Jason Developer / Handyman Staff Member

    Single page is fine.
    :)
  7. Graham

    Graham Developer Staff Member

    Give it a go then ...
    Jason likes this.
  8. Jason

    Jason Developer / Handyman Staff Member

    upload_2021-6-25_14-38-48.png


    @Graham

    How do I set the printer and image offsets ?

    When I click [Print Form & Content], I get this

    upload_2021-6-25_14-42-16.png
  9. Jason

    Jason Developer / Handyman Staff Member

    On a separate question,

    From this directory,
    upload_2021-6-25_14-51-54.png
    I run gswin64c.exe as administrator ... and I get this ...

    From this gs window,
    upload_2021-6-25_14-51-7.png

    How do I do these two commands from this window ?

    gswin64c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 -sOutputFile=stlimaging.png stlimaging.pdf
    gswin64c -o tiger.eps -sDEVICE=epswrite tiger.pdf

    I get this back.

    upload_2021-6-25_15-3-4.png
  10. Jerry

    Jerry Administrator Staff Member

    Jason, it appears you're working on an imaging requisition form. Could you attach a copy of it ? I would like to see if I can get that working as an acroform as well as seeing how the PDF/scan control overlay method works for me.
  11. Graham

    Graham Developer Staff Member

    [​IMG]

    Your values may vary for the offsets of the EPS and PNG versions
  12. Graham

    Graham Developer Staff Member

  13. Graham

    Graham Developer Staff Member

    Hopefully I haven't hard coded in "gswin32c" but who knows? I may have.

    In which case, copy gswin64c.exe to gswin32c.exe, and make sure it's available in your system path.
    Type at a command prompt

    path

    to see if it shows up.

    Cheers
  14. Jason

    Jason Developer / Handyman Staff Member

    I'm trying it manually anyway.
    I'm not running the rebol script.

    Although I think I did buy a license to do that many moons ago.
  15. Jason

    Jason Developer / Handyman Staff Member

    upload_2021-6-28_11-20-29.png

    When I print form only I get this:

    upload_2021-6-28_11-24-31.png

    but the file is there.

    I'm going to reboot this PC to see if that helps.

    The pre-printed form looks good. (see below)

    upload_2021-6-28_11-26-12.png

    The Print Form & Content only shows the first item [Doctor]

    I made the .eps many years ago and it might be bad.
  16. Jason

    Jason Developer / Handyman Staff Member

    What are Native Offsets ?
    upload_2021-6-28_15-33-54.png

    for .pdf ?
  17. Jason

    Jason Developer / Handyman Staff Member

    I was able to make a png from the pdf.

    It appears that there was a permission error to write files.

    I moved gswin64c and the files to my e:\ drive and the file was generated.

    trying to make the .eps gives me this ...

    upload_2021-6-28_15-53-23.png

    GPL Ghostscript 9.16 (2015-03-30)
    Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    Unknown device: epswrite
    Unrecoverable error: syntaxerror in --nostringval--
    Operand stack:
    defaultdevice false
    Unrecoverable error: undefined in .uninstallpagedevice
    Operand stack:
    defaultdevice false
  18. Jason

    Jason Developer / Handyman Staff Member

    I googled.

    https://ghostscript.com/pipermail/gs-devel/2014-July/009671.html


    ------

    eps2write worked :)
  19. Jason

    Jason Developer / Handyman Staff Member

    upload_2021-6-28_16-16-39.png

    Could these issues be related to my cant find the .eps ?

    upload_2021-6-28_16-17-27.png
  20. Graham

    Graham Developer Staff Member

    Not sure. It's been a long time ago since I looked at this. You'll just have to try different values to see what impact it has on printing.

Share This Page