Saving webviewer contents as a PDF

Hi All, first post here.

I am trying to Save as PDF a Layout that contains a webviewer.

I can accomplish this by:
going to that Layout,
clicking Preview,
clicking Save as PDF,
selecting the Folder required
and then saving.

When I attempt this via the script I receive the following error message:

Gonzalo error

Any help in resolving this issue would be greatly appreciated.

Regards

Milton.

On the Layout as shown below, I have the following items:

Players::PhotoDefault: Container, External (Open)

Players::id_fk_PlayerNickname: Calculation, result is Text.

4 Merge Fields as follows: (Merge fields enclosed in quotes)
"First" has Played: = Players::First
"PlayerGames2024Thursday" Games on a Thursday for a Total of "PlayerPoints2024Thursday" Points.
"PlayerGames2024Friday" Games on a Friday for a Total of "PlayerPoints2024Friday" Points.
"PlayerGames2024Sunday" Games on a Sunday for a Total of "PlayerPoints2024Sunday" Points.

And the Webviewer named "Weekly-Chart-Lge"

The Contents of the Webviewer are below.

The script to Save as PDF is as follows:

#Set the full file path
Set Variable [$ChartPath; Value:"filewin:/C:/Users/milta/OneDrive/Toowong - Personal/Toowong Website - 2024/Charts/" & Players::FirstAndLastPDF

#Players::FirstAndLastPDF holds:       Players::First & " " & Players::Last  & ".pdf"

#Save the current record as a PDF
Print Setup [Restore; With dialog:Off]
Save Records as PDF [Restore; With dialog: Off; "$ChartPath"; Current Record; Create Folders: Off]

The settings for Print Setup are:
Printer Name: Microsoft Print to PDF
Paper size: A4
Orientation: Landscape.

For the Save Records as PDF options:
Specify options are set to:
Current Record
Options: Page 1 through 1

And the Webviewer named "Weekly-Chart-Lge"

The contents of the Webviewer are as follows:

"<!DOCTYPE html>
<html>
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js\"></script>
<body>
<canvas id=\"myChart\" style=\"width:100%;max-width:1500px\"></canvas>

<script>
const xValues = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44];
const yValues1 = [
" & Players::WK1 TH  & ",
" & Players::WK2 TH  & ",
" & Players::WK3 TH  & ",
" & Players::WK4 TH  & ",
" & Players::WK5 TH  & ",
" & Players::WK6 TH  & ",
" & Players::WK7 TH  & ",
" & Players::WK8 TH  & ",
" & Players::WK9 TH  & ",
" & Players::WK10 TH  & ",
" & Players::WK11 TH  & ",
" & Players::WK12 TH  & ",
" & Players::WK13 TH  & ",
" & Players::WK14 TH  & ",
" & Players::WK15 TH  & ",
" & Players::WK16 TH  & ",
" & Players::WK17 TH  & ",
" & Players::WK18 TH  & ",
" & Players::WK19 TH  & ",
" & Players::WK20 TH  & ",
" & Players::WK21 TH  & ",
" & Players::WK22 TH  & ",
" & Players::WK23 TH  & ",
" & Players::WK24 TH  & ",
" & Players::WK25 TH  & ",
" & Players::WK26 TH  & ",
" & Players::WK27 TH  & ",
" & Players::WK28 TH  & ",
" & Players::WK29 TH  & ",
" & Players::WK30 TH  & ",
" & Players::WK31 TH  & ",
" & Players::WK32 TH  & ",
" & Players::WK33 TH  & ",
" & Players::WK34 TH  & ",
" & Players::WK35 TH  & ",
" & Players::WK36 TH  & ",
" & Players::WK37 TH  & ",
" & Players::WK38 TH  & ",
" & Players::WK39 TH  & ",
" & Players::WK40 TH  & ",
" & Players::WK41 TH  & ",
" & Players::WK42 TH  & ",
" & Players::WK43 TH  & ",
" & Players::WK44 TH  & "
];

const yValues2 = [
" & Players::WK1 FRI  & ",
" & Players::WK2 FRI  & ",
" & Players::WK3 FRI  & ",
" & Players::WK4 FRI  & ",
" & Players::WK5 FRI  & ",
" & Players::WK6 FRI  & ",
" & Players::WK7 FRI  & ",
" & Players::WK8 FRI  & ",
" & Players::WK9 FRI  & ",
" & Players::WK10 FRI  & ",
" & Players::WK11 FRI  & ",
" & Players::WK12 FRI  & ",
" & Players::WK13 FRI  & ",
" & Players::WK14 FRI  & ",
" & Players::WK15 FRI  & ",
" & Players::WK16 FRI  & ",
" & Players::WK17 FRI  & ",
" & Players::WK18 FRI  & ",
" & Players::WK19 FRI  & ",
" & Players::WK20 FRI  & ",
" & Players::WK21 FRI  & ",
" & Players::WK22 FRI  & ",
" & Players::WK23 FRI  & ",
" & Players::WK24 FRI  & ",
" & Players::WK25 FRI  & ",
" & Players::WK26 FRI  & ",
" & Players::WK27 FRI  & ",
" & Players::WK28 FRI  & ",
" & Players::WK29 FRI  & ",
" & Players::WK30 FRI  & ",
" & Players::WK31 FRI  & ",
" & Players::WK32 FRI  & ",
" & Players::WK33 FRI  & ",
" & Players::WK34 FRI  & ",
" & Players::WK35 FRI  & ",
" & Players::WK36 FRI  & ",
" & Players::WK37 FRI  & ",
" & Players::WK38 FRI  & ",
" & Players::WK39 FRI  & ",
" & Players::WK40 FRI  & ",
" & Players::WK41 FRI  & ",
" & Players::WK42 FRI  & ",
" & Players::WK43 FRI  & ",
" & Players::WK44 FRI  & "
];

const yValues3 = [
" & Players::WK1 SUN  & ",
" & Players::WK2 SUN  & ",
" & Players::WK3 SUN  & ",
" & Players::WK4 SUN  & ",
" & Players::WK5 SUN  & ",
" & Players::WK6 SUN  & ",
" & Players::WK7 SUN  & ",
" & Players::WK8 SUN  & ",
" & Players::WK9 SUN  & ",
" & Players::WK10 SUN  & ",
" & Players::WK11 SUN  & ",
" & Players::WK12 SUN  & ",
" & Players::WK13 SUN  & ",
" & Players::WK14 SUN  & ",
" & Players::WK15 SUN  & ",
" & Players::WK16 SUN  & ",
" & Players::WK17 SUN  & ",
" & Players::WK18 SUN  & ",
" & Players::WK19 SUN  & ",
" & Players::WK20 SUN  & ",
" & Players::WK21 SUN  & ",
" & Players::WK22 SUN  & ",
" & Players::WK23 SUN  & ",
" & Players::WK24 SUN  & ",
" & Players::WK25 SUN  & ",
" & Players::WK26 SUN  & ",
" & Players::WK27 SUN  & ",
" & Players::WK28 SUN  & ",
" & Players::WK29 SUN  & ",
" & Players::WK30 SUN  & ",
" & Players::WK31 SUN  & ",
" & Players::WK32 SUN  & ",
" & Players::WK33 SUN  & ",
" & Players::WK34 SUN  & ",
" & Players::WK35 SUN  & ",
" & Players::WK36 SUN  & ",
" & Players::WK37 SUN  & ",
" & Players::WK38 SUN  & ",
" & Players::WK39 SUN  & ",
" & Players::WK40 SUN  & ",
" & Players::WK41 SUN  & ",
" & Players::WK42 SUN  & ",
" & Players::WK43 SUN  & ",
" & Players::WK44 SUN  & "
];

new Chart(\"myChart\", {
  type: \"line\",
  data: {
    labels: xValues,
    datasets: [
      {
        label: 'Thursday',
        fill: false,
        lineTension: 0,
        backgroundColor: \"rgba(0,0,255,1.0)\",
        borderColor: \"rgba(0,0,255,0.1)\",
        data: yValues1
      },
      {
        label: 'Friday',
        fill: false,
        lineTension: 0,
        backgroundColor: \"rgba(255,0,0,1.0)\",
        borderColor: \"rgba(255,0,0,0.1)\",
        data: yValues2
      },
      {
        label: 'Sunday',
        fill: false,
        lineTension: 0,
        backgroundColor: \"rgba(0,255,0,1.0)\",
        borderColor: \"rgba(0,255,0,0.1)\",
        data: yValues3
      }
    ]
  },
  options: {
    legend: {
      display: true,
      position: 'top',
      labels: {
        fontColor: 'rgb(0, 0, 0)',
        fontSize: 14
      }
    },
    scales: {
      yAxes: [{
         ticks: {
           min: 0, 
           max:250}}],
    }
  }
});
</script>

</body>
</html>"

You could use MBS FileMaker Plugin to make it an image or PDF.

See WebView.RenderImage, WebView.RenderPDF or WebView.PrintToFile functions. Then you could use FileMaker to show the same layout with a container instead of the web viewer and have FileMaker include the image or PDF of the web content.

I suggest you step through your code with the debugger. Pay attention to your $ChartPath variable. In my experience, the "could not be created on this disk" error is usually associated to an incorrect path.

1 Like

It seems to be a font issue.
The path is correct, as I have tried numerous different paths.
When I debugged I received error code 800 which led me to the font issue. Apparently Fonts need to be installed for All Users.

I have yet to find a way to accomplish this on Windows 11 Home.

Fonts can cause all sorts of problems, such as, not being available because they are only installed for a single user. Annoying. You'll see a version of this problem if you try to generate PDF using FileMaker Server. A server rarely has the same set of fonts as a workstation.

Also, not all fonts are equal, some are good, others are not. The "not-good" fonts cause problems that are hard to track down - until you remove the font from the layouts.

Thanks Malcolm,
I have tried many ways to resolve this, I have altered all items fonts on a layout from Arial to Calibri with no change.
Then I tried a blank Layout and still the error message persists.
I have tried to find where I can set the fonts to all users but in Windows 11 there doesn't seem to be that option.
I can have a button with Save Records as PDF (Dialog ON) but this means I manually have to specify the filename, and then specify current record otherwise it saves all records as one pdf.
I also installed ScriptMaster and tried their Screenshot Plugin and that gives me the same error message.

Change the value in the variable storing the path. Use one of the “allowed” paths, such as Get(DesktopPath).

Thanks Malcolm,

I tried the following:

Set Variable [$desktopPath;  Value: Get ( DesktopPath )]
Set Variable [$ChartPath;  Value: Get ( DesktopPath ) & "ChartImages/Players::FirstAndLastPDF"]
Print Setup [Restore; with dialog: Off]
Save Records as PDF [Restore; with dialog: Off; "$ChartPath"; Current record; Create folders:Off]

but I still get the same error.

I then tried it without any folder on the desktop, just straight to desktop and again the same message except it says "Desktop" could not be created etc.

I just tried utilising Specify Output File.
I clicked the Add File button and then selected the path to the folder I want to save the pdf's in.
This added in the Output File Path List:
file:Toowong Website - 2024/Charts/untitled.pdf.

This worked and saved the current file in the correct folder as Untitled.
I then tried to use Players::FirstAndLastPDF instead of Untitled and this got the same error message.

So now my question is how do I name the filepath so that when I carry out a loop of all records, it doesn't just keep overwriting the Untilted.pdf file?

Set Variable [$ChartPath;  Value: Get ( DesktopPath ) & "fileName.PDF" ]

If the filename is stored in a field then provide a field reference

Set Variable [$ChartPath;  Value: Get ( DesktopPath ) & Players::fileName ]

When you are creating a lot of files you can simply use an iterator in the loop

Set Variable [ $i ; $i + 1 ]
Set Variable [$ChartPath;  Value: Get ( DesktopPath ) & "fileName_" & $i & ".PDF" ]

or you could use something from the record.

Set Variable [$ChartPath;  Value: Get ( DesktopPath ) & Players::fileName & ".pdf" ]

You have to be careful with this option. If the data you use for the file name is not unique, you'll overwrite a file by accident.

Hi Malcolm,

Finally got the script to work by making a $variable for the Player first and last name and the .pdf extension. See code below:

#Set the desktop path
Set Variable [$desktopPath; Value: Get ( DesktopPath )]

#Set the full file path via the desktop path
Set Variable $ChartPath; Value: Get ( DesktopPath )]

#Set the Players First and Last name and the .pdf extension
Set Variable $playerName; Value: Players::FirstAndLastPDF]

#Setup the Printer
Print Setup [Restore; With dialog:Off]
#Microsoft Print To PDF
#A4
#Landscape

#Save the current record as a PDF
Save Records as PDF [Restore; With dialog: Off; "$playerName"; Current Record; Create Folders: Off]
#Output file path List:  file:BPU Website - 2024/Charts/$playerName
#Specify Options: Specify Options: Save - Current Record, Options: Specific Pages - 1 through 1

Great! I'm glad it's working.

The script code you've shown is using the variable $playerName to generate a path from the value stored (or calculated) in the field Players::FirstAndLastPDF.

The variable $ChartPath and the variable $desktopPath aren't being used.

I edited the script and added a loop, it saved the pdfs of 607 players in 20 minutes.
One thing I have noticed is when I carry out a Preview, the data in the chart is not in the correct place on the x axis compared to the layout view.
I have added the layout view which shows the correct position of the player for each week, whereas the preview view is miles out.

Any idea why this would be happening?

The chart is inside a webviewer.


No idea. You'd have to tell us something about the data being passed to the web viewer.