Skip to content

Additional features #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: v22.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6816ba7
add new docx table celll and border style features and update templaa…
anush735 Dec 20, 2024
2558bdb
add {remove?} feature to remove the added shape completely when the t…
anush735 Dec 24, 2024
3ec7eed
add new pdf option convert_to_pdfa for generating PDF/A format and up…
anush735 Dec 25, 2024
c24f7b1
add option to addd custom text to signature field
anush735 Dec 25, 2024
a8edf10
add new option watermark_rotation for pdf config
anush735 Dec 26, 2024
a5c3b4a
add new option to provide start of the page number in output config
anush735 Dec 26, 2024
03a3336
add new option to hide pptx slides
anush735 Dec 27, 2024
6b48a39
add new options in autolink and hyperlink tags to provide font_color …
anush735 Dec 30, 2024
26c494a
add feature to attach files in pdf and updated output options to retr…
anush735 Dec 30, 2024
806a1e6
add _distribute option to distribute the data evenly among the column…
anush735 Dec 30, 2024
c41bdd4
add preserve_tag_style option for hyperlink and autolink
anush735 Dec 31, 2024
cd797d5
add new option for xlsx cell style property
anush735 Dec 31, 2024
0a82907
add new option for html property
anush735 Dec 31, 2024
63915e6
add option to update table of content of word document
anush735 Jan 2, 2025
eb8d7f8
add new option to insert barcode in pdf config
anush735 Jan 2, 2025
efd715c
add new options firstSliceAngle and holeSize in chart options for dop…
anush735 Jan 2, 2025
460029e
add new chart option enableAreaTransparency for Area Chart
anush735 Jan 2, 2025
6277a63
add new chart types AreaStacked and LineStacked chart
anush735 Jan 2, 2025
1ef961d
update documentation and examples
anush735 Jan 6, 2025
d7860c5
refectore and update documentation
anush735 Jan 6, 2025
c1551ce
refactore code to add new classes for autolink and hyperlink options
anush735 Jan 6, 2025
fa6a318
update documentation
anush735 Jan 6, 2025
bfa3479
refactor constructor of pdf config and update documentation
anush735 Jan 7, 2025
85437af
add pdf include feature and test
prabinbessie Apr 18, 2025
fdf50a1
added compare files feature and test
prabinbessie Apr 18, 2025
95994c1
add change locale with test
prabinbessie Apr 18, 2025
843374a
Add PDF annotation feature with tests for PDFComment and PDFComments
prabinbessie Apr 21, 2025
561a286
Add Password Encryption Feature with Test
prabinbessie Apr 25, 2025
39ca78c
Add Merge Cells on Tabular Looping with example
prabinbessie Apr 28, 2025
f39f23f
PDF Forms using Form Tag
prabinbessie Apr 29, 2025
d87a7ff
Add density on Image Tag Options
prabinbessie May 2, 2025
a98aeee
Add Output to Directory now supports return_output
prabinbessie May 6, 2025
88b3ced
Add Data Batching with test
prabinbessie May 6, 2025
ecf2b49
fix: return value
prabinbessie May 7, 2025
f3c0e7b
Add Transformation Function with example
prabinbessie May 9, 2025
d061142
Test Fix
prabinbessie May 9, 2025
2630153
Docs Upadted For Density
prabinbessie May 13, 2025
56ac682
Updated PptxAutolink : where now constructor have name and value othe…
prabinbessie May 13, 2025
2104fcb
Renamed :From ( Remove -> PptxShapeRemove)
prabinbessie May 13, 2025
17bcd2d
Updated PptxHyperlink : where now constructor have name and Url othe…
prabinbessie May 13, 2025
9364aac
Updated _distribute to ForEachInline class and added example
prabinbessie May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added BeginerGuide/Loop/data/tem.docx
Binary file not shown.
63 changes: 63 additions & 0 deletions BeginerGuide/Loop/merge_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys
sys.path.insert(0, "C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python")
import cloudofficeprint as cop


data = cop.elements.ElementCollection("data")

eng_emp1 = cop.elements.ElementCollection.from_mapping({
"name": "John Smith",
"project": "Website Redesign",
"status": "In Progress"
})

eng_emp2 = cop.elements.ElementCollection.from_mapping({
"name": "Emily Johnson",
"project": "API Development",
"status": "Completed"
})

eng_emp3 = cop.elements.ElementCollection.from_mapping({
"name": "Michael Brown",
"project": "Mobile App",
"status": "Planning"
})

mkt_emp1 = cop.elements.ElementCollection.from_mapping({
"name": "Sarah Wilson",
"project": "Brand Campaign",
"status": "In Progress"
})

mkt_emp2 = cop.elements.ElementCollection.from_mapping({
"name": "David Thompson",
"project": "Market Research",
"status": "Not Started"
})

engineering_dept = cop.elements.ElementCollection.from_mapping({
"department": "Engineering"
})
engineering_dept.add(cop.elements.ForEachMergeCells("employees", [eng_emp1, eng_emp2, eng_emp3]))

marketing_dept = cop.elements.ElementCollection.from_mapping({
"department": "Marketing"
})
marketing_dept.add(cop.elements.ForEachMergeCells("employees", [mkt_emp1, mkt_emp2]))

departments = cop.elements.ForEachMergeCells("departments", [engineering_dept, marketing_dept])

data.add(departments)

server = cop.config.Server(
"http://localhost:8010/"
)
# Create print job
# PrintJob combines template, data, server and an optional output configuration
printjob = cop.PrintJob(
data=data,
server=server,
template=cop.Resource.from_local_file("C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python/BeginerGuide/Loop/data/tem.docx"),
)
response = printjob.execute()
response.to_file("C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python/BeginerGuide/Loop/output/output.docx")
Binary file added BeginerGuide/Loop/output/output.docx
Binary file not shown.
Binary file added BeginerGuide/Transformation/data/template.docx
Binary file not shown.
Binary file added BeginerGuide/Transformation/output/output.pdf
Binary file not shown.
127 changes: 127 additions & 0 deletions BeginerGuide/Transformation/usingTransformation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import sys
sys.path.insert(0, "C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python")
import cloudofficeprint as cop

# Create main data structure representing the files array
files = cop.elements.ElementCollection(name="files")

# Create a file entry
file_entry = cop.elements.ElementCollection()
file_entry.add(cop.elements.Property("filename", "file1"))

# Add customer data
data_array = cop.elements.ElementCollection()
customer = cop.elements.Property(
name='cust_first_name',
value='John'
)
customer_last_name = cop.elements.Property(
name='cust_last_name',
value='Dullas'
)

data_array.add(customer)
data_array.add(customer_last_name)

# Product data
product1 = cop.elements.ElementCollection.from_mapping({
"product_name": "Buisness Shirt",
"unit_price": 50,
"quantity": 3,
"category": "Mens"
})

product2 = cop.elements.ElementCollection.from_mapping({
"product_name": "Trousers",
"unit_price": 80,
"quantity": 3,
"category": "Mens"
})

product3 = cop.elements.ElementCollection.from_mapping({
"product_name": "Jacket",
"unit_price": 150,
"quantity": 3,
"category": "Mens"
})
product4 = cop.elements.ElementCollection.from_mapping({
"product_name": "Blouse",
"unit_price": 60,
"quantity": 3,
"category": "Womens"
})
product5 = cop.elements.ElementCollection.from_mapping({
"product_name": "Skirt",
"unit_price": 80,
"quantity": 3,
"category": "Womens"
})
product6 = cop.elements.ElementCollection.from_mapping({
"product_name": "Ladies Shoes",
"unit_price": 120,
"quantity": 2,
"category": "Womens"
})
product7 = cop.elements.ElementCollection.from_mapping({
"product_name": "Belt",
"unit_price": 50,
"quantity": 2,
"category": "Accessories"
})
product8 = cop.elements.ElementCollection.from_mapping({
"product_name": "Bag",
"unit_price": 50,
"quantity": 2,
"category": "Accessories"
})
product9 = cop.elements.ElementCollection.from_mapping({
"product_name": "Mens Shoes",
"unit_price": 110,
"quantity": 2,
"category": "Mens"
})
product10 = cop.elements.ElementCollection.from_mapping({
"product_name": "Wallet",
"unit_price": 50,
"quantity": 2,
"category": "Accessories"
})

product = cop.elements.ForEach("product", [product1, product2, product3, product4, product5, product6, product7, product8, product9, product10])
data_array.add(product)

# Create main data object
main_data = cop.elements.ElementCollection()
main_data.add(cop.elements.Property("data", data_array))
data = main_data.as_dict

# Transformation function
js_code ="function generateProductRows(products, category) {\r\n return products\r\n .filter(product => product.category === category)\r\n .map(product => {\r\n if (category === \"Mens\") {\r\n product.category_bold = \"true\";\r\n product.product_name_font_color = \"blue\";\r\n } else {\r\n product.category_italic = \"true\";\r\n product.product_name_font_color = \"red\";\r\n }\r\n const totalCost = product.unit_price * product.quantity;\r\n return `\r\n <tr>\r\n <td style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">${product.product_name}</td>\r\n <td style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">${product.unit_price}</td>\r\n <td style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">${product.quantity}</td>\r\n <td style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">${totalCost}</td>\r\n </tr>\r\n `;\r\n })\r\n .join('');\r\n}\r\n\r\nfunction transform() {\r\n files.forEach(file => {\r\n let data = file.data;\r\n // Initialize HTML strings for mens_products and womens_products\r\n let mensProductsHtml = '<table style=\"width: 100%; border: 2px solid blue; border-collapse: collapse;\">';\r\n let womensProductsHtml = '<table style=\"width: 100%; border: 2px solid red; border-collapse: collapse;\">';\r\n\r\n // Add table headers\r\n const tableHeaders = `\r\n <tr>\r\n <th style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">Product Name</th>\r\n <th style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">Unit Price</th>\r\n <th style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">Quantity</th>\r\n <th style=\"border-width: 1px; border-style: solid; border-color: black; padding: 8px;\">Total Cost</th>\r\n </tr>\r\n `;\r\n mensProductsHtml += tableHeaders;\r\n womensProductsHtml += tableHeaders;\r\n\r\n // Generate HTML rows for mens and womens products\r\n const mensProductsRows = generateProductRows(data.product, \"Mens\");\r\n const womensProductsRows = generateProductRows(data.product, \"Womens\");\r\n\r\n // Calculate totals using reduce\r\n const mensTotals = data.product\r\n .filter(product => product.category === \"Mens\")\r\n .reduce((totals, product) => {\r\n totals.quantity += product.quantity;\r\n totals.cost += product.unit_price * product.quantity;\r\n return totals;\r\n }, { quantity: 0, cost: 0 });\r\n\r\n const womensTotals = data.product\r\n .filter(product => product.category === \"Womens\")\r\n .reduce((totals, product) => {\r\n totals.quantity += product.quantity;\r\n totals.cost += product.unit_price * product.quantity;\r\n return totals;\r\n }, { quantity: 0, cost: 0 });\r\n\r\n // Close the HTML tables\r\n mensProductsHtml += mensProductsRows + '</table>';\r\n womensProductsHtml += womensProductsRows + '</table>';\r\n\r\n // Add the new entries to the data object\r\n data.mens_products = mensProductsHtml;\r\n data.womens_products = womensProductsHtml;\r\n data.mens_total_quantity = mensTotals.quantity;\r\n data.mens_total_cost = mensTotals.cost;\r\n data.womens_total_quantity = womensTotals.quantity;\r\n data.womens_total_cost = womensTotals.cost;\r\n });\r\n return files;\r\n}\r\n"
# Transformation objeect
transformation_function = cop.TransformationFunction(js_code)

# transformation_function = cop.TransformationFunction("sample_transform.js")

# Configure the Server
server = cop.config.Server(
url="http://localhost:8010/",
config=cop.config.ServerConfig(api_key="YOUR_API_KEY")
)

template = cop.Resource.from_local_file(
"C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python/BeginerGuide/Transformation/data/template.docx"
)
output_conf = cop.config.OutputConfig(filetype="pdf")

# Create print job
printjob = cop.PrintJob(
data=data,
server=server,
template=template,
output_config=output_conf,
transformation_function=transformation_function
)

response = printjob.execute()
response.to_file(
"C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python/BeginerGuide/Transformation/output/output.pdf")
2 changes: 2 additions & 0 deletions BeginerGuide/UsingCharts/usingChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
'2px',
'sysDash'
)

# To make line stacked chart you can simply use cop.elements.LineStackedChart
line_chart = cop.elements.LineChart(
'line_chart_name',
(line1, line2)
Expand Down
75 changes: 75 additions & 0 deletions BeginerGuide/UsingDistribute/UsingDistribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import sys
sys.path.insert(0, "C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python")
import cloudofficeprint as cop

#ROOT element collection
root = cop.elements.ElementCollection("root")

# Create file entry with filename
file_entry = cop.elements.ElementCollection.from_mapping({
"filename": "department_report.docx"
})

# Main data container
data_content = cop.elements.ElementCollection("data")

# Create department elements
def create_department(name, employees):
dept = cop.elements.ElementCollection.from_mapping({
"department": name
})
dept.add(cop.elements.ForEach("employees", employees))
return dept

# Create departments with distribution
departments = cop.elements.ForEachInline(
name="departments",
content=[
create_department("Engineering", [
cop.elements.ElementCollection.from_mapping({
"name": "John Smith",
"project": "Website Redesign",
"status": "In Progress"
}),
cop.elements.ElementCollection.from_mapping({
"name": "Emily Johnson",
"project": "API Development",
"status": "Completed"
})
]),
create_department("Marketing", [
cop.elements.ElementCollection.from_mapping({
"name": "Sarah Wilson",
"project": "Brand Campaign",
"status": "In Progress"
}),
cop.elements.ElementCollection.from_mapping({
"name": "David Thompson",
"project": "Market Research",
"status": "Not Started"
})
])
],
distribute=True
)

# Build the hierarchy correctly
data_content.add(departments)
file_entry.add(data_content)
root.add(file_entry)

# Configure server
server = cop.config.Server("http://localhost:8010/")

# Create print job with CORRECT OUTPUT PATH
printjob = cop.PrintJob(
data=root,
server=server,
template=cop.Resource.from_local_file(
"C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python/BeginerGuide/UsingDistribute/data/horizontal_tabular_looping_output-ed506eb2e341afbf52e1a05319e2b086.docx"
),
)

# Save to DIFFERENT FILE than template
response = printjob.execute()
response.to_file("C:/Users/em8ee/OneDrive/Documents/cloudofficeprint-python/BeginerGuide/UsingDistribute/output/output.docx")
Binary file not shown.
Binary file added BeginerGuide/UsingDistribute/output/output.docx
Binary file not shown.
Binary file modified BeginerGuide/UsingElements/data/template.docx
Binary file not shown.
Binary file modified BeginerGuide/UsingElements/output/output.docx
Binary file not shown.
34 changes: 31 additions & 3 deletions BeginerGuide/UsingElements/using_elements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Install cloudofficeprint using pip install cloudofficeprint
#Import the cloudofficeprint libary.
from ... import cloudofficeprint as cop
import sys
sys.path.insert(0, "PATH_TO_COP_DIR")
import cloudofficeprint as cop

# Main object that holds the data
collection = cop.elements.ElementCollection()
# Create the title element and add it to the element collection
Expand Down Expand Up @@ -42,6 +45,31 @@
)
collection.add(styled_prop)

docx_column1_cell_style = cop.elements.CellStyleDocx(
cell_background_color='red',
border_color='0d72c7',
border_top='double'
)
docx_column1_table_style_property = cop.elements.CellStyleProperty(
name='column1',
value='DemoCustomerName',
cell_style=docx_column1_cell_style
)
collection.add(docx_column1_table_style_property)

docx_column2_cell_style = cop.elements.CellStyleDocx(
border_diagonal_down='single',
border_diagonal_down_size=10,
border_diagonal_up='single',
border_diagonal_up_color='#0d72c7'
)
docx_column2_table_style_property = cop.elements.CellStyleProperty(
name='column2',
value='DemoCustomerName',
cell_style=docx_column2_cell_style
)
collection.add(docx_column2_table_style_property)

# ------------------watermark----------
watermark = cop.elements.Watermark(
name='watermark_name',
Expand All @@ -66,8 +94,8 @@
printjob = cop.PrintJob(
data=collection,
server=server,
template=cop.Resource.from_local_file("./data/template.docx"),
template=cop.Resource.from_local_file("D:/UC/cloudofficeprint-python/BeginerGuide/UsingElements/data/template.docx"),
)
# Execute print job and save response to file
response = printjob.execute()
response.to_file("output/output")
response.to_file("D:/UC/cloudofficeprint-python/BeginerGuide/UsingElements/output/output.docx")
Loading