Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/Parse PDF Content
Function:
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Parse PDF Content
This example is the version from Sat, 7th Nov 2014.
Function:
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Parse PDF Content
This example is the version from Sat, 7th Nov 2014.
Project "Parse PDF Content.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
dim f as FolderItem = GetOpenFolderItem(MyFileTypes.All)
if f=nil then
quit
end if
dim p as new MyDynapdfMBS
p.SetLicenseKey "Pro" // For this example you can use a Pro or Enterprise License
call p.CreateNewPDF
// Skip anything that is not required
call p.SetImportFlags p.kifContentOnly+p.kifImportAsPage
// From which PDF file do you want to extract the images?
call p.OpenImportFile(f, p.kptOpen, "")
// Comment this out if you want to extract the images from specific pages only
call p.ImportPDFFile(1, 1.0, 1.0)
// Uncomment this section if you want to extract images from specific pages only
'dim pageCount as integer = p.GetPageCount
'for i as integer = 1 to pageCount
'call p.Append
'call p.ImportPageEx(i, 1.0, 1.0)
'call p.EndPage
'next
call p.CloseImportFile
dim stack as new MyDynaPDFParseInterfaceMBS
stack.dest=SpecialFolder.desktop // destination folder
stack.pdf=p
'If you want to create a multipage TIFF then create the output image here
'and call AddImage() only in the callback function. After the loop
'returns call CloseImage() to close the image file.
dim w as new window1
stack.w = w
dim pageCount as integer = p.GetPageCount
for i as integer=1 to pageCount
call p.EditPage i
call p.ParseContent(stack, p.kpfNone)
call p.EndPage
next
End EventHandler
End Class
Class Window1 Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyDynaPDFParseInterfaceMBS Inherits DynaPDFParseInterfaceMBS
EventHandler Function ApplyPattern(ObjectPtr as integer, Type as integer, PatternPtr as integer) As integer
Write CurrentMethodName
End EventHandler
EventHandler Function BeginLayer(IOCG as integer, InVisible as boolean) As integer
dim s as string
if InVisible then
s = ", visible"
else
s = ", non visible"
end if
Write CurrentMethodName
End EventHandler
EventHandler Function BeginPattern(ObjectPtr as integer, Fill as Boolean, PatternType as integer, BBox as DynaPDFRectMBS, Matrix as DynapdfMatrixMBS, XStep as double, YStep as double) As integer
Write CurrentMethodName
End EventHandler
EventHandler Function BeginTemplate(ObjectPtr as integer, Handle as integer, BBox as DynaPDFRectMBS, Matrix as DynapdfMatrixMBS) As integer
Write CurrentMethodName
End EventHandler
EventHandler Function BezierTo1(ObjectPtr as integer, x1 as double, y1 as double, x3 as double, y3 as double) As integer
Write CurrentMethodName+" "+str(x1)+"/"+str(y1)+" to "+str(x3)+"/"+str(y3)
End EventHandler
EventHandler Function BezierTo2(ObjectPtr as integer, x2 as double, y2 as double, x3 as double, y3 as double) As integer
Write CurrentMethodName+" "+str(x2)+"/"+str(y2)+" to "+str(x3)+"/"+str(y3)
End EventHandler
EventHandler Function BezierTo3(ObjectPtr as integer, x1 as double, y1 as double, x2 as double, y2 as double, x3 as double, y3 as double) As integer
Write CurrentMethodName+" "+str(x1)+"/"+str(y1)+" to "+str(x2)+"/"+str(y2)+" to "+str(x3)+"/"+str(y3)
End EventHandler
EventHandler Function ClipPath(ObjectPtr as integer, EvenOdd as boolean, Mode as integer) As integer
Write CurrentMethodName
End EventHandler
EventHandler Function ClosePath(ObjectPtr as integer, Mode as integer) As integer
Write CurrentMethodName
End EventHandler
EventHandler Function DrawShading(ObjectPtr as integer, Type as integer, Shading as integer) As integer
Write CurrentMethodName
End EventHandler
EventHandler Sub EndLayer(IOCG as integer, InVisible as boolean)
Write CurrentMethodName
End EventHandler
EventHandler Sub EndPattern()
Write CurrentMethodName
End EventHandler
EventHandler Sub EndTemplate()
Write CurrentMethodName
End EventHandler
EventHandler Function InsertImage(image as DynaPDFImageMBS) As integer
Write CurrentMethodName
End EventHandler
EventHandler Function LineTo(ObjectPtr as integer, x as double, y as double) As integer
Write CurrentMethodName+" "+str(x)+"/"+str(y)
End EventHandler
EventHandler Function MoveTo(ObjectPtr as integer, x as double, y as double) As integer
Write CurrentMethodName+" "+str(x)+"/"+str(y)
End EventHandler
EventHandler Sub MulMatrix(ObjectPtr as integer, matrix as DynapdfMatrixMBS)
Write CurrentMethodName
End EventHandler
EventHandler Function Rectangle(ObjectPtr as integer, x as double, y as double, w as double, h as double) As integer
Write CurrentMethodName+" "+str(x)+"/"+str(y)+" with size "+str(w)+"/"+str(h)
End EventHandler
EventHandler Function RestoreGraphicState() As integer
prefix = mid(prefix, 4)
Write CurrentMethodName
End EventHandler
EventHandler Function SaveGraphicState() As integer
Write CurrentMethodName
prefix = prefix + " "
End EventHandler
EventHandler Sub SetCharSpacing(ObjectPtr as integer, Value as double)
Write CurrentMethodName+" "+str(value)
End EventHandler
EventHandler Sub SetExtGState(ObjectPtr as integer, GS as DynaPDFExtGState2MBS)
Write CurrentMethodName
End EventHandler
EventHandler Sub SetFillColor(ObjectPtr as integer, NumComps as integer, Color1 as double, Color2 as double, Color3 as double, Color4 as double, Colors() as double, ColorspaceType as integer, ColorSpace as DynaPDFColorSpaceMBS)
dim lines(-1) as string
for i as integer = 0 to NumComps-1
lines.Append str(colors(i))
next
Write CurrentMethodName+" "+Join(lines, ", ")
End EventHandler
EventHandler Sub SetFont(ObjectPtr as integer, fontType as integer, Embedded as boolean, FontName as string, Style as integer, FontSize as double, FontHandle as integer, FontInfo as DynaPDFFontInfoMBS)
Write CurrentMethodName
End EventHandler
EventHandler Sub SetLeading(ObjectPtr as integer, Value as double)
Write CurrentMethodName+" "+str(value)
End EventHandler
EventHandler Sub SetLineCapStyle(ObjectPtr as integer, Style as integer)
Write CurrentMethodName+" "+str(style)
End EventHandler
EventHandler Sub SetLineDashPattern(ObjectPtr as integer, dash as memoryblock, NumValues as integer, Phase as integer)
Write CurrentMethodName
End EventHandler
EventHandler Sub SetLineJoinStyle(ObjectPtr as integer, Style as integer)
Write CurrentMethodName+" "+str(Style)
End EventHandler
EventHandler Sub SetLineWidth(ObjectPtr as integer, Value as double)
Write CurrentMethodName+" "+str(value)
End EventHandler
EventHandler Sub SetMiterLimit(ObjectPtr as integer, Value as double)
Write CurrentMethodName+" "+str(value)
End EventHandler
EventHandler Sub SetStrokeColor(ObjectPtr as integer, NumComps as integer, Color1 as double, Color2 as double, Color3 as double, Color4 as double, Colors() as double, ColorspaceType as integer, ColorSpace as DynaPDFColorSpaceMBS)
dim lines(-1) as string
for i as integer = 0 to NumComps-1
lines.Append str(colors(i))
next
Write CurrentMethodName+" "+Join(lines, ", ")
End EventHandler
EventHandler Sub SetTextDrawMode(ObjectPtr as integer, Mode as integer)
Write CurrentMethodName+" "+str(mode)
End EventHandler
EventHandler Sub SetTextScale(ObjectPtr as integer, Value as double)
Write CurrentMethodName+" "+str(value)
End EventHandler
EventHandler Sub SetWordSpacing(ObjectPtr as integer, Value as double)
Write CurrentMethodName+" "+str(value)
End EventHandler
EventHandler Function ShowTextArrayA(ObjectPtr as integer, Matrix as DynapdfMatrixMBS, Kerning() as DynaPDFTextRecordAMBS, Count as integer, Width as double) As integer
dim texts() as string
for each k as DynaPDFTextRecordAMBS in Kerning
texts.Append k.Text
next
Write CurrentMethodName+" "+Join(texts)
End EventHandler
EventHandler Function ShowTextArrayW(Source() as DynaPDFTextRecordAMBS, Matrix as DynapdfMatrixMBS, Kerning() as DynaPDFTextRecordWMBS, Count as integer, Width as double, Decoded as boolean) As integer
dim texts() as string
for each k as DynaPDFTextRecordWMBS in Kerning
texts.Append k.Text
next
Write CurrentMethodName+" "+Join(texts)
End EventHandler
Sub Write(s as string)
const cn = "MyDynaPDFParseInterfaceMBS."
if left(s,len(cn)) = cn then
s = mid(s, len(cn)+1)
end if
w.List.AddRow prefix+s
End Sub
Property Counter As Integer
Property dest As folderitem
Property pdf As dynaPDFmbs
Property prefix As string
Property w As window1
End Class
MyFileTypes
Filetype application/pdf
Filetype application/ai
End MyFileTypes
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer
// output all messages on the console:
System.DebugLog str(ErrorCode)+": "+ErrorMessage
// and display dialog:
Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
d.icon=MessageDialog.GraphicCaution //display warning icon
d.ActionButton.Caption="Continue"
d.CancelButton.Visible=True //show the Cancel button
// a warning or an error?
if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then
// if user decided to ignore, we'll ignore
if IgnoreWarnings then Return 0
d.Message="A warning occurred while processing your PDF code."
// we add a third button to display all warnings
d.AlternateActionButton.Caption = "Ignore warnings"
d.AlternateActionButton.Visible = true
else
d.Message="An error occurred while processing your PDF code."
end if
d.Explanation = str(ErrorCode)+": "+ErrorMessage
b=d.ShowModal //display the dialog
Select Case b //determine which button was pressed.
Case d.ActionButton
Return 0 // ignore
Case d.AlternateActionButton
IgnoreWarnings = true
Return 0 // ignore
Case d.CancelButton
Return -1 // stop
End select
End EventHandler
Property IgnoreWarnings As Boolean
End Class
End Project
See also:
The items on this page are in the following plugins: MBS DynaPDF Plugin.
