« Two years junior deve… | Home | MBS FileMaker Plugin,… »

Adding cutting lines for PDF in FileMaker

We have a new example for a client to add cutting edges and a crop box to a PDF document.

The picture on the left shows the debug version, where you see the red lines we add and a rectangle around the content. The crop box is put around the content, so the printing shop will crop the paper at the right position. Only for debugging, we show you the rectangle and leave the crop box away, so you see it.

# Add crop markers

 

# Initialize DynaPDF if needed

If [ MBS("DynaPDF.IsInitialized")  ≠  1 ] 

Perform Script [ Specified: From list ; “InitDynaPDF” ; Parameter:    ]

End If

# Clear current PDF document

Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ] 

# Load PDF from container

Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromContainer"; $pdf; Convert to 2 Pages::InputPDF) ] 

If [ MBS("IsError") ≠ 0 ] 

Show Custom Dialog [ "Failed to load PDF" ; $r ] 

Exit Script [ Text Result:    ] 

End If

Set Variable [ $Debug ; Value: 1 ] 

# Query page size for first page

Set Variable [ $bounds ; Value: MBS("DynaPDF.GetImportPageBounds"; $pdf; 1; "MediaBox") ] 

Set Variable [ $boundsLeft ; Value: MBS("Math.TextToNumber"; MiddleValues ( $bounds ; 1 ; 1 )) ] 

Set Variable [ $boundsTop ; Value: MBS("Math.TextToNumber"; MiddleValues ( $bounds ; 2 ; 1 )) ] 

Set Variable [ $boundsRight ; Value: MBS("Math.TextToNumber"; MiddleValues ( $bounds ; 3 ; 1 )) ] 

Set Variable [ $boundsBottom ; Value: MBS("Math.TextToNumber"; MiddleValues ( $bounds ; 4 ; 1 )) ] 

Set Variable [ $w ; Value: Abs($boundsRight - $boundsLeft) ] 

Set Variable [ $h ; Value: Abs($boundsBottom - $boundsTop) ] 

# now import page as template and place on new page with border around

Set Variable [ $template ; Value: MBS("DynaPDF.ImportPageAsTemplate"; $pdf; 1) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.AppendPage"; $pdf) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.SetPageWidth"; $pdf; $w + 200) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.SetPageHeight"; $pdf; $h + 200) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.PlaceTemplateEx"; $pdf; $template; 100; 100; $w; $h) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.SetStrokeColor"; $pdf; 1; 0; 0) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.SetLineWidth"; $pdf; 1) ] 

If [ $Debug ] 

Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; 100-1; 100-1; $w+2; $h+2; "stroke") ] 

End If

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100; 100 - 10) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; 100; 0) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100; 100 + 10 + $h) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; 100; $h + 200) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100 + $w; 100 - 10) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; 100 + $w; 0) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100 + $w; 100 + 10 + $h) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; 100 + $w; $h + 200) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100 - 10; 100) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; 0; 100) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100 + 10 + $w; 100) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; $w + 200; 100) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100 - 10; 100+$h) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; 0; 100 + $h) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.MoveTo"; $pdf; 100 + 10 + $w; 100 + $h) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.LineTo"; $pdf; $w + 200; 100 + $h) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.ClosePath"; $pdf; "stroke") ] 

If [ $Debug ] 

# no bounding box

Else

Set Variable [ $r ; Value: MBS("DynaPDF.SetBBox"; $pdf; "crop";100; 100; $w+100; $h+100) ] 

End If

Set Variable [ $r ; Value: MBS("DynaPDF.SetBBox"; $pdf; "media"; 0; 0; $w+200; $h+200) ] 

Set Variable [ $r ; Value: MBS("DynaPDF.EndPage"; $pdf) ] 

Set Field [ Convert to 2 Pages::OutputPDF ; MBS("DynaPDF.Save"; $pdf; "Merged.pdf") ] 

# done, save to container

Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ] 

We may include this script as example for future releases. Let us know if you have questions about DynaPDF and MBS Plugin.

Claris FileMaker Plugin
04 01 21 - 14:09