<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">REM  *****  BASIC  *****

Sub ExportToPdf(ByVal tmpDir As String)
    Const pageMargin = 500
    Dim document As Object, pageStyles As Object
    document = ThisComponent

    cnt = document.Sheets.Count - 1
    Dim dict(0 To cnt) As new com.sun.star.beans.PropertyValue

    pageStyles = document.StyleFamilies.getByName(&quot;PageStyles&quot;)
        For i = 0 To cnt
                Dim sheet As Object, style As Object

                sheet = document.Sheets(i)
                style = pageStyles.getByName(sheet.PageStyle)
                style.ScaleToPagesX = 1
                style.printGrid = True
                style.HeaderOn = False
                style.FooterOn = False
                style.IsLandscape = True
                style.TopMargin = pageMargin
                style.LeftMargin = pageMargin
                style.BottomMargin = pageMargin
                style.RightMargin = pageMargin

                num = i + 1
                fileName = &quot;/fullview_page&quot; + num + &quot;.pdf&quot;
                url = tmpDir + fileName
                ExportSheetToPdf document, url, sheet

                dict(i).Name = sheet.name
                dict(i).Value = fileName
        Next
        On Error Resume Next

        pathToJson = tmpDir + &quot;/fullview_pages.json&quot;
        CreateJsonMeta pathToJson, dict, cnt

        document.storeSelf(Array())
        document.close(true)
End Sub

REM Эспортирует лист oSheet документа oDoc в файл filePath (формат URL или операционной системы).
REM Если oSheet не указан (или Nothing), то экспортируются все листы.
Sub ExportSheetToPdf(ByVal oDoc As Object, ByVal filePath As String, Optional ByVal oSheet As Object)
  Dim oSh
  Dim args(1) as new com.sun.star.beans.PropertyValue
  Dim aFilterData(1) as new com.sun.star.beans.PropertyValue
  If IsMissing(oSheet) Then oSheet=Nothing

  args(0).Name = &quot;FilterName&quot;
  args(0).Value = &quot;calc_pdf_Export&quot;

  If Not (oSheet Is Nothing) Then
        args(1).Name = &quot;FilterData&quot;
        aFilterData(0).Name=&quot;Selection&quot; 
        aFilterData(0).Value=oSheet
    args(1).Value = aFilterData
  End If

  oDoc.StoreToUrl ConvertToUrl(filePath), args
End Sub

REM Сохраняет наименования листов в json файл
Sub CreateJsonMeta(ByVal filePath As String, dict As Object, cnt as Integer)
	Dim json As Integer
	Dim fn As String
	fn = filePath
	json = FreeFile

	num = 0
	Open fn For Output As json
		Print #json, &quot;[&quot;
		For Each d in dict
			comma = &quot;&quot;	
      If num &lt; cnt Then
        comma = &quot;,&quot;
      End If
      item = &quot;{&quot; &amp; &quot;&quot;&quot;&quot; &amp; Replace(d.Name, &quot;&quot;&quot;&quot;, &quot;\&quot;&quot;&quot;) &amp; &quot;&quot;&quot;:&quot;&quot;&quot; &amp; d.Value &amp; &quot;&quot;&quot;&quot; &amp; &quot;}&quot; &amp; comma
      num = num + 1
      Print #json, item
    Next
		On Error Resume Next    
		Print #json, &quot;]&quot;
	Close #json
End Sub

Sub Main()
   ExportToPdf &quot;~/1&quot;
End Sub
</script:module>