Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
Where a PDF's Bytes Go: the Optimize Audit
See more PDF Optimization Examples
Demonstrates the "audit" operation, which measures the loaded PDF and changes nothing. The report says how large the file is, which PDF version it claims, whether it claims to be PDF/A, where its bytes go ("usage", as stored in the file, so compressed sizes), and how many bytes each lossless option would be expected to save ("estimatedSavings"). Use it to decide whether optimizing is worth the trouble, and which options matter for this file.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loJsonOut
LOCAL loEst
LOCAL i
LOCAL lnNumEst
LOCAL lcOptionName
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* The PDF used in this example is available at grand_canyon_hiking_guide.pdf
loPdf = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf.LoadFile("qa_data/pdf/grand_canyon_hiking_guide.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
CANCEL
ENDIF
* "audit" takes the same options as "optimize", so an empty JSON means the default options.
loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
lnSuccess = loPdf.Optimize("audit",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "fileSize: " + STR(loJsonOut.IntOf("fileSize"))
? "pdfVersion: " + loJsonOut.StringOf("pdfVersion")
? "pdfa: " + loJsonOut.StringOf("pdfa")
* Where the bytes go. Every category is present even when it is 0, and the sizes are the stored
* (compressed) sizes, so they add up to fileSize. "overhead" is what is left: the cross-reference
* tables, the object headers and the white space between objects.
? "images: " + STR(loJsonOut.IntOf("usage.images.bytes")) + " in " + STR(loJsonOut.IntOf("usage.images.count")) + " objects"
? "fonts: " + STR(loJsonOut.IntOf("usage.fonts.bytes")) + " in " + STR(loJsonOut.IntOf("usage.fonts.count")) + " objects"
? "pageContent: " + STR(loJsonOut.IntOf("usage.pageContent.bytes"))
? "formXObjects: " + STR(loJsonOut.IntOf("usage.formXObjects.bytes"))
? "annotations: " + STR(loJsonOut.IntOf("usage.annotations.bytes"))
? "structureTree: " + STR(loJsonOut.IntOf("usage.structureTree.bytes"))
? "metadata: " + STR(loJsonOut.IntOf("usage.metadata.bytes"))
? "embeddedFiles: " + STR(loJsonOut.IntOf("usage.embeddedFiles.bytes"))
? "oldRevisions: " + STR(loJsonOut.IntOf("usage.oldRevisions.bytes"))
? "overhead: " + STR(loJsonOut.IntOf("usage.overhead.bytes"))
* What each option is expected to save. An option that would save nothing is left out.
? "estimated total: " + STR(loJsonOut.IntOf("estimatedSavings.total"))
loEst = CreateObject('Chilkat.JsonObject')
lnSuccess = loJsonOut.ObjectOf2("estimatedSavings",loEst)
IF (lnSuccess = 0) THEN
? loJsonOut.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loEst
CANCEL
ENDIF
i = 0
lnNumEst = loEst.Size
DO WHILE i < lnNumEst
lcOptionName = loEst.NameAt(i)
? " " + lcOptionName + ": " + STR(loEst.IntOf(lcOptionName))
i = i + 1
ENDDO
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loEst