13 Replies Latest reply on Jun 24, 2014 5:06 AM by MartinCrosman

    Writing FM Data to existing PDF Files

    MartinCrosman

      I recall this being discussed here but after 45 minutes of looking for the thread I am asking the questions again.

       

      Environment - FileMaker Pro 13, FileMaker Server 13, Windows 7, Acrobat Pro

       

      The database has a few fields including a container field in which a PDF file is stored. The PDFs are stored externally using Open storage option.

       

      I would like to write data in a few of the fields to the PDF. For example "stamp" the PDF to indicate it is completed and the date completed. I'd like the text to be written to the PDF file but would settle for it being printed on the PDF when it is printed or the field's contents exported.

       

      This would be on an adhoc basis or could be part of the loop applied to a found set.

       

      The text would be printed to the first page of the pdf. Some PDFs are single pages some a couple of hundred pages.

       

      I have looked at Scribe and PDF Manipulator but they appear to require a form field/placeholder already in the document. That is not possible in this situation.

       

      I have looked at some neat VB to Word integration (thanks Wim) and this kind of think to PDF would be fantastic.

       

      I beleive the earlier thread was started by Lee Snover but I just can't find it. I beleive it also pointed to another plug in that might support this.

       

      Thanks in advance for any comments or advice.

       

      Martin

        • 1. Re: Writing FM Data to existing PDF Files
          keywords

          I'm not sure if the following is what you are after, but it may help.

           

          I use a process of saving quote letters as PDFs, then importing the PDF into a container field. Whenever I realise I have to amend the quote after saving the PDF I simply run the process again and the revised PDF crunches the old one and is hence updated. This works because each version has the same name, so the old is simply overwritten. While this does not preserve and add to an existing PDF, as you seem to want to do, it has the same effect since the originating content (the FM record) is the same.

          • 3. Re: Writing FM Data to existing PDF Files
            jrenfrew

            If you really mean 'stamp' as in as in it is just some text written over the top of the existing PDF file, then you dont need any 'form fields' in the PDF to do this.

            This can easily be done with ScriptMaster and iText, and if you don't want to spend the time learning, the assistance of a person who knows.

             

            Method will work on both platforms and Server - lookout for unconf at Devcon to show this stuff off - and is as solid as the proverbial rock.

            1 of 1 people found this helpful
            • 4. Re: Writing FM Data to existing PDF Files
              MartinCrosman

              Thanks for your reply. Just to clarify what I am looking to do is write to the PDF directly from FileMaker. In your example I may have a found set of 10000 quotes. I want to write on the first page of the PDF the status of the quote and the date. For example Rejected - 6/24/2014. This needs to appear on the first page and no additional/coverpage would do. The users could open each document and use Acrobat's tools to do this one at a time but I am looking for a solution to automate this updating of the PDFs.

               

              Thanks again,

               

              Martin

              • 5. Re: Writing FM Data to existing PDF Files
                MartinCrosman

                I took a look at the tools. from what I read they seem to impose another page on top of the existing PDF page to create this stamp effect. This alters the page count of the PDF. I can have that as the page count has to stay the same.

                 

                I am not sure how to get FileMaker to talk to the Stamp tool.

                • 6. Re: Writing FM Data to existing PDF Files
                  MartinCrosman

                  That is what I really mean. Unfortunately I will not be at Devcon. Any other info sources you can point me to? Are you showing this at the unconf?

                  • 7. Re: Writing FM Data to existing PDF Files
                    jrenfrew

                    Imposition is the act of putting on or more pages into another, usual larger, page for the purpose of printing/archiving.

                     

                    The imposition as described there does not alter the page count, it uses a PDF as the transport mechasnism for what is the equivalent of a <merge> operation...

                     

                     

                    john

                    1 of 1 people found this helpful
                    • 8. Re: Writing FM Data to existing PDF Files
                      user19752

                      page count are stay the same,

                      but stamped to all page ( as docmented. )

                      use a layout "stamp" having transparent body.

                       

                      example

                      //for testing, use unique filename for not to be overwrited.

                      Set Variable [$in; Value:Get ( TemporaryPath ) & Get ( UUID ) & ".PDF"]

                      Set Variable [$out; Value:Get ( TemporaryPath ) & Get ( UUID ) & ".PDF"]

                      Set Variable [$stamp; Value:Get ( TemporaryPath ) & Get ( UUID ) & ".PDF"]

                      Export Field Contents [PDFstamp::PDF; “$in”]

                      Go to Layout [“stamp” (PDFstamp)]

                      Save Records as PDF [Restore; No dialog; “$stamp”; Current record]

                      Go to Layout [original layout]

                      Go to Field [PDFstamp::PDF]

                      Set Variable [$$cmd; Value:Quote ( "C:\Program Files\PDFtk\bin\pdftk.exe" ) &  " " & Quote ( Replace ( $in ; 1 ; 1 ; "" ) ) &  " stamp " & Quote ( Replace ( $stamp ; 1 ; 1 ; "" ) ) &  " output " & Quote ( Replace ( $out ; 1 ; 1 ; "" ) )]

                      Send Event [“aevt”; “odoc”; Quote ( "C:\Program Files\PDFtk\bin\pdftk.exe" ) &  " " & Quote ( Replace ( $in ; 1 ; 1 ; "" ) ) &  " stamp " & Quote ( Replace ( $stamp ; 1 ; 1 ; "" ) ) &  " output " & Quote ( Replace ( $out ; 1 ; 1 ; "" ) )]

                      Pause/Resume Script [Duration (seconds): 3]

                      Insert PDF [“$out”]

                      Commit Records/Requests [No dialog]

                      • 9. Re: Writing FM Data to existing PDF Files
                        user19752

                        Minimum example.

                        This seems better than my example of PDFtk .

                        output file size is smaller and script is simpler.

                         

                        Something to do for better use

                        1. y is count from bottom (point)
                        2. font, size, style, and color are hard coded

                         

                        RegisterGroovy( "Stamp ( src ; dst ; stamptext ; x ; y )" ;

                        "import java.io.FileOutputStream;

                        import java.io.IOException;

                        import java.awt.Color;

                         

                        import com.itextpdf.text.BaseColor;

                        import com.itextpdf.text.DocumentException;

                        import com.itextpdf.text.Element;

                        import com.itextpdf.text.Font;

                        import com.itextpdf.text.FontFactory;

                        import com.itextpdf.text.Phrase;

                        import com.itextpdf.text.pdf.ColumnText;

                        import com.itextpdf.text.pdf.PdfContentByte;

                        import com.itextpdf.text.pdf.PdfReader;

                        import com.itextpdf.text.pdf.PdfStamper;

                         

                        Float fx = Float.parseFloat(x);

                        Float fy = Float.parseFloat(y);

                        PdfReader reader = new PdfReader(src);

                        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dst));

                        PdfContentByte canvas = stamper.getOverContent(1);

                        ColumnText.showTextAligned(canvas,

                            Element.ALIGN_LEFT,

                            new Phrase(stamptext, FontFactory.getFont(FontFactory.COURIER, 12.0, Font.NORMAL, BaseColor.BLACK)),

                            fx, fy, 0);

                        stamper.close();

                        reader.close();

                        " ;

                        "isGUI=false" )

                        • 10. Re: Writing FM Data to existing PDF Files
                          monkeybreadsoftware

                          Did you look into MBS plugin and it's DynaPDF functions?

                           

                          You can open existing PDF, write text on it and save back to a container.

                          • 11. Re: Writing FM Data to existing PDF Files
                            jrenfrew

                            Let's at least tidy up the code... and return a result based on whether it is done or not.. for those of us with slight OCD.

                             

                            import com.itextpdf.text.BaseColor

                            import com.itextpdf.text.Element

                            import com.itextpdf.text.Font

                            import com.itextpdf.text.FontFactory

                            import com.itextpdf.text.Phrase

                            import com.itextpdf.text.pdf.ColumnText

                            import com.itextpdf.text.pdf.PdfContentByte

                            import com.itextpdf.text.pdf.PdfReader

                            import com.itextpdf.text.pdf.PdfStamper

                             

                             

                            try {

                                      reader = new PdfReader(src)

                                      stamper = new PdfStamper(reader, new FileOutputStream(dst))

                                      PdfContentByte canvas = stamper.getOverContent(1)

                                      ColumnText.showTextAligned(canvas,

                                          Element.ALIGN_LEFT,

                                          new Phrase(stamptext, FontFactory.getFont(FontFactory.COURIER, 12.0, Font.NORMAL, BaseColor.BLACK)),

                                          x.toFloat(), y.toFloat(), 0)

                                      stamper.close()

                                      reader.close()

                            } catch (e) {

                                      return false

                            } //end try

                            return true

                             

                            its a bit blunt and doesnt cope with the OP request for date..

                            john

                            • 12. Re: Writing FM Data to existing PDF Files
                              MartinCrosman

                              Hi John and user 19752

                               

                              Thanks for this. This is way out of the box for me. But on target.

                              • 13. Re: Writing FM Data to existing PDF Files
                                MartinCrosman

                                Thanks Christian. I'll look at it as well.