that helps a lot, thanks for the screen snip and markings. bless you!
Hi Keith,
Thanks a lot for you script. I have been looking on the internet to find a way to also add image of charts to this pdf. But I canāt really find anything at the moment.
Would you have an idea ?
I looked here to find some System.Drawing namespaces, I need to dig deeper.
Thanks a lot !
Baudouin
1 Like
@keith.sowinski any help on how you would modify your excellent code for multiple file paths and corrosponding string inputs to create a pdf for eachā¦guessing loop through a list for each but thenā¦?
Many thanks.
import clr
import System
import math
clr.AddReference('System.Drawing')
from System.Drawing.Printing import *
from System.Drawing import Brushes, Font, StringFormat, SizeF, StringAlignment
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilePath
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import System
run = IN[0]
string = IN[1]
filePaths = IN[2]
ltMargin = IN[3]
rtMargin = IN[4]
tpMargin = IN[5]
btmMargin = IN[6]
font = IN[7]
size = IN[8]
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilePath
output = []
#loops through list for paths
for paths in filePaths:
output.append(paths)
#something needed here?
def printPDF():
pd = PrintDocument()
pd.PrinterSettings.PrinterName = "Microsoft Print to PDF"
pd.PrinterSettings.PrintToFile = True
pd.PrinterSettings.PrintFileName = paths
pd.DefaultPageSettings.Margins.Left = ltMargin
pd.DefaultPageSettings.Margins.Right = rtMargin
pd.DefaultPageSettings.Margins.Top = tpMargin
pd.DefaultPageSettings.Margins.Bottom = btmMargin
pd.PrintPage += PrintPageEventHandler(print_page)
pd.Print()
# return file
data = []
#loops through list for strings
for i in string:
data.append(i)
#something needed here?
def print_page(sender, e):
global i
fnt = Font(font, size)
charactersOnPage = clr.Reference[System.Int32]()
linesPerPage = clr.Reference[System.Int32]()
e.Graphics.MeasureString(i, fnt, SizeF(e.MarginBounds.Size), StringFormat.GenericDefault, charactersOnPage, linesPerPage)
e.Graphics.DrawString(i, fnt, Brushes.Black, e.MarginBounds)
i = i.Substring(charactersOnPage.Value)
e.HasMorePages = i.Length > 0
if run:
OUT = printPDF()
Make it into a custom node.
1 Like