The following example creates a PDF document, and adds text, DataWindow, .rtf file content, and watermark into the document.
PDFdocument lpdf_doc PDFpage lpdf_page PDFtext lpdf_text lpdf_doc = create PDFdocument lpdf_page = create PDFpage lpdf_text = create PDFtext long ll_return lpdf_text.content = "Gets or sets the content of the object. " lpdf_text.textcolor.rgb = rgb(255,0,0) lpdf_page.addcontent( lpdf_text) ll_return = lpdf_page.importcontent( "import\noannots.pdf", 2, 10, 50, 500, 700) ll_return = lpdf_doc.addpage( lpdf_page) lpdf_doc.importdatawindow( dw_1) lpdf_doc.importpdf( "D:\import\noannots.pdf",1,1,4) rte_1.insertdocument( "TXdemo.rtf", false,FileTypeRichText!) ll_return = lpdf_doc.importrichtextedit( rte_1) lpdf_doc.watermark.image.filename="D:\import\image1\image.png" lpdf_doc.watermark.opacity = 50 lpdf_doc.watermark.rotate = 45 ll_return = lpdf_doc.save( "D:\save\pdf_dw_WaterMark.pdf")
The following example creates a PDF document, adds chapters, links and images, and then sets a table of contents for the document.
PDFdocument lpdf_doc
PDFpage lpdf_page,lpdf_page2,lpdf_page3
PDFtext lpdf_text,lpdf_title,lpdf_title1,lpdf_chapter,lpdf_textclone,lpdf_seartext
PDFrichtext lpdf_rtext
PDFimage lpdf_image,lpdf_wrapimage
PDFtableofContents lpdf_toc,lpdf_toc1
PDFtableofContentsitem lpdf_tocitem
PDFtextblock lpdf_block
long ll_return,ll_count
string ls_text
lpdf_doc = Create PDFdocument
lpdf_page = Create PDFpage
lpdf_page2 = Create PDFpage
lpdf_page3 = Create PDFpage
lpdf_text = Create PDFtext
lpdf_title = Create PDFtext
lpdf_chapter = Create PDFtext
lpdf_rtext = Create PDFrichtext
lpdf_image = Create PDFimage
lpdf_wrapimage = Create PDFimage
lpdf_toc = Create PDFtableofContents
lpdf_title.content = "TableOfContent"
lpdf_title.font.fontsize = 36
lpdf_title.x = lpdf_page.getwidth( )/2 -lpdf_title.width/2
lpdf_toc.setstyle( PDFTableOfContentsStyle_Classic!)
lpdf_toc.setrightmargin( 100)
lpdf_toc.setleftmargin( 100)
lpdf_toc.settopmargin( 50)
lpdf_toc.settitle( lpdf_title)
lpdf_chapter.content = "Chapter1"
lpdf_tocitem = lpdf_toc.additem( lpdf_chapter)
//PDFtext
lpdf_textclone = lpdf_chapter.clone( )
lpdf_textclone.content = "Chapter1_PDFtext"
lpdf_tocitem.additem( lpdf_textclone)
lpdf_page.addcontent( lpdf_chapter)
lpdf_page.addcontent( lpdf_textclone)
lpdf_text.name = "textname"
lpdf_text.content = "I am PDFtext Content"
//Sets a link that goes to the google translate page
ll_return = lpdf_text.setlinkaddress( "https://translate.google.com/")
lpdf_text.textcolor.rgb =rgb(255,0,0)
lpdf_text.font.bold = true
lpdf_text.font.italic = true
lpdf_page.addcontent( lpdf_text)
//Imports the first PDF page
lpdf_page.importcontent( "import\noannots.pdf", 1, 10, 50, 550, 600)
//PDFimage
lpdf_textclone = lpdf_textclone.clone( )
lpdf_textclone.content = "Chapter1_PDFimage"
lpdf_tocitem.additem( lpdf_textclone)
lpdf_image.filename = "import\image1\image.png"
lpdf_image.y= lpdf_textclone.y + 10
//Sets the image transparency
lpdf_image.transparency = 50
//Links the lpdf_image object to lpdf_text
lpdf_image.linktoobject( lpdf_text)
lpdf_page2.addcontent( lpdf_textclone)
lpdf_page2.addcontent( lpdf_image)
//PDFrichtext
lpdf_textclone = lpdf_textclone.clone( )
lpdf_textclone.content = "Chapter1_PDFrichtext"
lpdf_tocitem.additem( lpdf_textclone)
lpdf_rtext.y = lpdf_textclone.y + 10
lpdf_rtext.width = lpdf_page.getwidth( )
ls_text = "The PDFDocument object allows to import data from a DataWindow object, a DataWindowChild object or a DataStore object, or an existing PDF document to a new PDF document and save the document."
lpdf_block = lpdf_rtext.addtextblock( ls_text)
lpdf_block.textcolor.rgb = rgb(0,0,255)
lpdf_block.layout.firstlineindent = 10
lpdf_block.layout.linespacing = 500
lpdf_block.layout.charspacing =10
//Adds image
lpdf_wrapimage.filename = "import\image1\image2.png"
lpdf_wrapimage.setposition( 40, 10)
lpdf_page3.addcontent( lpdf_wrapimage)
lpdf_rtext.wrapimage( lpdf_wrapimage)
lpdf_page3.addcontent(lpdf_textclone )
lpdf_page3.addcontent(lpdf_rtext )
lpdf_doc.addpage( lpdf_page)
lpdf_doc.addpage( lpdf_page2)
lpdf_doc.addpage( lpdf_page3)
//Gets the count of the level 1 items in the TOC
ll_count = lpdf_toc.getitemcount( )
//Gets the count of the level 2 items in the TOC
ll_count = lpdf_tocitem.getitemcount( )
lpdf_doc.settableofcontents( lpdf_toc)
//Gets the PDFTableOfContents object
lpdf_toc1 = lpdf_doc.gettableofcontents( )
//Gets the title
lpdf_title1 = lpdf_toc1.gettitle( )
ls_text = lpdf_title1.content
//Adds text type watermark
lpdf_doc.watermark.text.content = "WaterMark Test"
lpdf_doc.watermark.text.font.fontsize = 36
lpdf_doc.watermark.text.textcolor.rgb = rgb(0,255,0)
lpdf_doc.watermark.rotate = 45
lpdf_doc.watermark.opacity = 50
//Imports a DataWindow at the end of page 3
ll_return = lpdf_doc.importdatawindow( dw_1,3)
//Counts the pages in lpdf_doc
ll_count = lpdf_doc.getpagecount( )
//Search for PDFText having name = textname
if lpdf_doc.searchobject( "textname").typeof( )=pdftext! then
lpdf_seartext = lpdf_doc.searchobject( "textname")
//Gets the content in the object
ls_text = lpdf_seartext.content
messagebox("searchobject",ls_text)
//Modifies the content
lpdf_seartext.content = lpdf_seartext.content+ "123"
else
end if
ll_return = lpdf_doc.save( "D:\save\test1.pdf")
The following example creates a PDF document, sets its properties and security, and adds an attachment to it.
PDFdocument lpdf_doc PDFpage lpdf_page PDFtext lpdf_text lpdf_doc = create PDFdocument lpdf_page = create PDFpage lpdf_text = create PDFtext DataStore lds_1 lds_1 = Create DataStore lds_1.dataobject = "d_dept" lds_1.settransobject(sqlca) lds_1.retrieve() long ll_return //Sets the document properties lpdf_doc.properties.author = "tester" lpdf_doc.properties.subject = "Test subject" //Sets the document security lpdf_doc.security.allowcopy = true lpdf_doc.security.masterpassword = "builder123" lpdf_doc.security.userpassword = "builder123" lpdf_text.content = "Gets or sets the content of the object. " lpdf_text.textcolor.rgb = rgb(255,0,0) lpdf_page.addcontent( lpdf_text) ll_return = lpdf_page.importcontent( "import\noannots.pdf", 2, 10, 50, 500, 700) lpdf_doc.addpage( lpdf_page) lpdf_doc.importdatawindow(lds_1) lpdf_doc.importpdf( "D:\import\noannots.pdf",1,1,4) //Adds attachment lpdf_doc.attachment.addfile( "D:\import\image1\image.png") ll_return = lpdf_doc.save( "D:\save\pdf_dw_attachment.pdf")
The following example adds attachments into a PDF document, and then manages the attachments.
long ll_return,ll_count PDFdocument lpdf_doc PDFpage lpdf_page PDFattachment lpdf_attach lpdf_doc = create PDFdocument lpdf_page = create PDFpage lpdf_attach = create PDFattachment //Add file ll_return =lpdf_attach.addfile( "D:\image\image.png") //Add files in the specified folder,true means recursively get the files in the sub folders as well lpdf_attach.addfolder ( "D:\image",true) lpdf_doc.attachment = lpdf_attach //Get the count of attachments ll_count = lpdf_attach.getcount( ) //Remove all attachments ll_return = lpdf_attach.removeall( ) lpdf_doc.addpage( lpdf_page) lpdf_doc.save( "D:\save\pdfattachment_addfile.pdf")
The following example uses the PDFDocExtractor to open the PDF file "extract.pdf" and extract its content.
PDFdocument lpdf_doc
PDFpage lpdf_page
long ll_open,index
double ld_width,ld_height
PDFDocExtractor lpdf_docExt
lpdf_docExt = create PDFDocExtractor
lpdf_doc = create PDFdocument
lpdf_page = create PDFpage
ll_open = lpdf_docExt.open("extract.pdf" )
//Extract all attachments and save in the specified folder. Create the folder if it does not exist
lpdf_docExt.extractallattachments("file" )
//Get the height and width of the first page
lpdf_docExt.getpagesize( 1,ld_width,ld_height )
messagebox("Get the page size of the specified page:","width="+string(ld_width)+",height="+string(ld_height))
lpdf_docExt.close()
lpdf_page.importcontent( "extract.pdf", 1, 10, 10, ld_width, ld_height)
lpdf_doc.addpage( lpdf_page)
lpdf_doc.save( "D:\save\getPagesize.pdf")
The following example uses the PDFDocExtractor to check the compatible standards of PDF files before merging them.
pdfdocument lpdf_doc
PDFdocextractor lpdf_extract
lpdf_extract = create PDFdocextractor
lpdf_doc = create PDFdocument
string ls_pdffile[]
int li_count,li_i,li_standardIndex
long ll_return
PDFstandard lpdf_standard[],lpdf_outPutPDFFileStandard[]
//The relative path to the PDF files
ls_pdffile = {"import\standard_1a.pdf","import\standard_1b.pdf","import\standard_3a.pdf","import\standard_3b.pdf","import\standard_3u.pdf"}
li_count = upperbound(ls_pdffile)
li_standardIndex = 1
//Get the standards of the PDF files to be merged
for li_i = 1 to li_count step 1
lpdf_extract.open( ls_pdffile[li_i])
lpdf_standard[li_standardIndex] = lpdf_extract.getstandard( )
li_standardIndex++
lpdf_extract.close( )
next
lpdf_extract.getcompatiblestandards( lpdf_standard, lpdf_outPutPDFFileStandard)
if upperbound(lpdf_outPutPDFFileStandard) <=0 then
messagebox("tips","There is no compatible standards for all the PDF fiels")
end if
messagebox("tip","Count of the compatible standards="+string(upperbound(lpdf_outPutPDFFileStandard)))
//Merge the PDF files
for li_i = 1 to li_count step 1
pdf_doc.importpdf( ls_pdffile[li_i])
next
li_count = upperbound(lpdf_outPutPDFFileStandard)
//Save all the compatible standards
for li_i = 1 to li_count
ll_return = lpdf_doc.save("D:\save\getcompatiblestandards"+string(li_i)+"_real.pdf",lpdf_outPutPDFFileStandard[li_i])
next
The following example creates a PDF page, adds text to the page, adds a link, and save the page in a PDF document.
PDFdocument lpdf_doc PDFpage lpdf_page,lpdf_page1 PDFtext lpdf_text,lpdf_textlink,lpdf_textaddress string ls_address lpdf_doc = create PDFdocument lpdf_page = create PDFpage lpdf_page1 = create PDFpage lpdf_text = create PDFtext lpdf_textlink = create PDFtext lpdf_textaddress = create PDFtext lpdf_text.backcolor.rgb = rgb(255,0,0) lpdf_text.textcolor.rgb = rgb(0,255,0) lpdf_text.font.fontsize = 38 lpdf_text.content = "I am PDFtext text" lpdf_textlink.content = "jump to me" //Support PDFtext, PDFmultilinetext, PDFimage, and PDFtextblock lpdf_text.linktoobject( lpdf_textlink) lpdf_textaddress.content = "translate.google.com.hk" //Jump to a website, which can be http, https, ftp, file, and mailto lpdf_textaddress.setlinkaddress( "https://translate.google.com.hk/?hl=zh-CN&sourceid=cnhp") //Get the link address ls_address = lpdf_textaddress.getlinkaddress( ) lpdf_page.addcontent( lpdf_text) lpdf_page.addcontent( lpdf_textaddress) lpdf_page1.addcontent( lpdf_textlink) lpdf_doc.addpage( lpdf_page) lpdf_doc.addpage( lpdf_page1) lpdf_doc.save( "save\textlink.pdf")
The following example creates a PDF page, adds a text block with link, and save the page in a PDF document.
PDFdocument lpdf_doc PDFpage lpdf_page PDFrichtext lpdf_rtext PDFtextblock lpdf_block lpdf_doc = create PDFdocument lpdf_page = create PDFpage lpdf_rtext = create PDFrichtext lpdf_block = create PDFtextblock lpdf_rtext.width = lpdf_page.getwidth( ) lpdf_block.content = "test localfileaction" //setlinkaddress. Supported; mailto://, file://, https://, and http:// lpdf_block.setlinkaddress( "https://translate.google.com.hk/?hl=zh-CN&sourceid=cnhp") lpdf_rtext.addtextblock( lpdf_block) lpdf_block.getlinkaddress( ) lpdf_page.addcontent( lpdf_rtext) lpdf_doc.addpage( lpdf_page) lpdf_doc.save( "D:\block_linkaddress.pdf")
The following example presents more detailed settings of the text block.
PDFdocument lpdf_doc PDFpage lpdf_page PDFrichtext lpdf_rtext PDFtextblock lpdf_block PDFtext lpdf_text lpdf_doc = create PDFdocument lpdf_page = create PDFpage lpdf_rtext = create PDFrichtext lpdf_block = create PDFtextblock lpdf_text = create PDFtext lpdf_rtext.width = lpdf_page.getwidth( ) lpdf_block.charspacing = 300 lpdf_block.backcolor.rgb = rgb(0,255,0) lpdf_block.textcolor.rgb = rgb(0,0,255) lpdf_block.font.fontsize = 36 lpdf_block.layout.alignment = PDFTextAlignCenter! lpdf_block.content = "pdftextblock linkto pdftext" lpdf_text.content = "link to me" //Link to PDFmultilinetext, PDFimage, PDFtext, or PDFtextblock lpdf_block.linktoobject( lpdf_text) lpdf_rtext.addtextblock( lpdf_block) lpdf_page.addcontent( lpdf_rtext) lpdf_page.addcontent( lpdf_text) lpdf_doc.addpage( lpdf_page) lpdf_doc.save( "D:\ block_linkto.pdf")
The following example sets a PDF watermark which is text.
PDFdocument lpdf_doc
PDFpage lpdf_page
PDFwatermark lpdf_water
lpdf_doc = create PDFdocument
lpdf_page = create PDFpage
lpdf_water = create PDFwatermark
lpdf_doc.addpage( lpdf_page)
lpdf_doc.watermark.text.content = "text watermark"
//The fontsize determines the watermark size
lpdf_doc.watermark.text.font.fontsize = 38
lpdf_doc.watermark.opacity = 50
lpdf_doc.watermark.rotate = 45
lpdf_doc.save("D:\ watermark.pdf" )
The following example sets a PDF watermark which is an image.
PDFdocument lpdf_doc
PDFpage lpdf_page
PDFwatermark lpdf_water
lpdf_doc = create PDFdocument
lpdf_page = create PDFpage
lpdf_water = create PDFwatermark
lpdf_doc.addpage( lpdf_page)
lpdf_doc.watermark.image.filename = "D:\image\image.jpg"
lpdf_doc.watermark.opacity = 50
lpdf_doc.watermark.rotate = 45
//The scale setting determines the watermark size
lpdf_doc.watermark.scale = 0.5
lpdf_doc.save("save\watermark_2.pdf" )


