Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

We have been using GraphicsMagick functions for years to draw some text, but we can do the same in DynaPDF. We draw text in a new PDF document and then render it as image without ever saving the PDF document. We can even use transparency and render the PDF with alpha channel and save as PNG image.

DynaPDFRender1.jpg

 

Our first example places some text on the PDF page using the DynaPDF.WriteStyledTextEx function. This function can take text with styles from a field in FileMaker (or variable) and draw it into the PDF. The styles are converted for DyynaPDF's format commands. The text is wrapped to the desired width of 300 points and we use justify for alignment. 

 

After the text is drawn, we use DynaPDF.GetLastTextPosY to query how big the text block is. Passing -1 as height for the text box allows us to have a variable height. This provides you the information on where to place another text or where to draw additional text. In our example we use the text position and the page height to calculate a new media box. This limits the visible part of the page to only the size of our text box.

 

Then we close the page and render the 1st page of the PDF document as an image. We pass the page number and the request resolution with 150 dpi. The default format is a RGB image stored as JPEG. In the script you can decide whether you like to save as PDF or render the image.

Here is the complete script except the DynaPDF initialization:

 

# Start with a new PDF document

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

# Add page

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

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

Set Variable [ $r ; Value: MBS("DynaPDF.SetFont"; $pdf; "Helvetica"; 0; 12) ]

# Write some text

Set Variable [ $text ; Value: "The award winning MBS Plugin is easily the most powerful plug-in available..." ]

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

Set Variable [ $r ; Value: MBS("DynaPDF.WriteStyledTextEx"; $pdf; 10; 10; 300; -1; "justify"; $Text) ]

# now figure out how much space we needed to make the page the right size

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

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

Set Variable [ $r ; Value: MBS( "DynaPDF.SetBBox"; $PDF; "Media"; 0; $ph; 320; $height - 10 ) ]

# close page, document and save PDF

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

If [ 0 ]

# save as PDF

Set Variable [ $Result ; Value: MBS("DynaPDF.Save"; $pdf; "hello.pdf") ]

Else

# or render a picture

Set Variable [ $Result ; Value: MBS("DynaPDF.RenderPage"; $pdf; 1; 150) ]

End If

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

# Put in Container

Set Field [ Create Text::PDF ; $Result ]

 

DynaPDFRender2.png

Let's make a change and calculate the size upfront. This allows use to draw a round rectangle before we draw the text. For this we first convert the styled text to DynaPDF's format commands. Then we calculate the height of the text box with the desired width of 300 points. 

 

Since we know the size of the textbox, we can change the page size to match what we need. We leave 10 points margin on all sizes and define the page size accordingly. On that small page, we can draw the round rectangle with a 5 point margin. You usually don't draw something round directly on the edge of the paper. It doesn't look nice in the viewers later with anti-aliased drawing. Then we draw the text.

 

The new script looks like this:

 

# Start with a new PDF document

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

# Add page

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

Set Variable [ $r ; Value: MBS("DynaPDF.SetFont"; $pdf; "Helvetica"; 0; 12) ]

# Write some text

Set Variable [ $text ; Value: "The award winning MBS Plugin is easily the most powerful plug-in available…" ]

Set Variable [ $ftext ; Value: MBS( "DynaPDF.ConvertStyledText"; $PDF; $Text) ]

# calculate height

Set Variable [ $width ; Value: 300 ]

Set Variable [ $height ; Value: MBS( "DynaPDF.GetFTextHeightEx"; $PDF; $width; "justify"; $ftext ) ]

# resize page

Set Variable [ $r ; Value: MBS( "DynaPDF.SetBBox"; $PDF; "Media"; 0; 0; $width + 20; $height + 20 ) ]

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

# draw round rect

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

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

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

Set Variable [ $r ; Value: MBS( "DynaPDF.RoundRectEx"; $PDF; 5; 5; $width + 10; $Height + 10; 10; 10; "FillStroke" ) ]

# and draw text

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

Set Variable [ $r ; Value: MBS("DynaPDF.WriteFTextEx"; $pdf; 10; 10; $width; -1; "justify"; $ftext) ]

# close page, document and save PDF

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

If [ 0 ]

# save as PDF

Set Variable [ $Result ; Value: MBS("DynaPDF.Save"; $pdf; "hello.pdf") ]

Else

# or render a picture, PNG with transparency

Set Variable [ $Result ; Value: MBS("DynaPDF.RenderPage"; $pdf; 1; 150; 0; 0; ""; "RGBA"; "Flate"; "PNG"; "image.png") ]

End If

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

# Put in Container

Set Field [ Create Text::PDF ; $Result ]

 

The sample scripts are included with the Create Text as PDFA.fmp12 example file for the next version.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.