DynaPDF Manual - Page 58
Previous Page 57 Index Next Page 59

Content parsing & editing
Page 58 of 860
In order to place objects on this position it is usually best to enable visible coordinates with
SetUseVisibleCoords() and to rotate the coordinate system with SetOrientationEx() according to
the page orientation after the page was opened for editing. See example on the next page.
Example:
This example draws a rectangle over every letter to check whether the coordinates are correct.
void TestContentParser(const PPDF* PDF, const wchar_t* InFile, wchar_t* OutFile, SI32 Page)
{
IPSR* ctx;
IPGE* page;
SI32 i, j, n, cnt;
TBBox b, list[8192];
TContent out = {0, 0};
TTextSelection sel, *curr;
pdfCreateNewPDF(PDF, NULL);
// No need to override the original producer
pdfSetDocInfo(PDF, diProducer, NULL);
// Do not convert pages to templates
pdfSetImportFlags(PDF, ifImportAll | ifImportAsPage);
// Reduce the memory usage
pdfSetImportFlags2(PDF, if2UseProxy);
pdfOpenImportFileW(PDF, InFile, ptOpen, NULL);
if (!Page)
pdfImportPDFFile(PDF, 1, 1.0, 1.0);
else
{
pdfAppend(PDF);
pdfImportPageEx(PDF, Page, 1.0, 1.0);
pdfEndPage(PDF);
}
cnt = pdfGetPageCount(PDF);
ctx = psrCreateParserContext(PDF, ofDefault, NULL);
sel.StructSize = sizeof(sel);
// Important! GetSelBBox() returns top down coordinates.
pdfSetPageCoords(PDF, pcTopDown);
for (i = 1; i <= cnt; i++)
{
curr = NULL;
if (psrParsePage(PDF, ctx, NULL, NULL, i, cpfEnableTextSelection, 0, &out))
{
n = 0;
// The function returns on every single letter if the flag stMatchAlways is set
while (psrFindText(PDF, ctx, NULL, stMatchAlways, curr, NULL, 0, &sel))
{
if (psrGetSelBBox(PDF, ctx, &sel, &b) && n < 8192)
list[n++] = b;
curr = &sel;
}
if (n > 0)
{
pdfEditPage(PDF, i);
pdfSetOrientationEx(PDF, pdfGetOrientation(PDF));
pdfSetLineWidth(PDF, 0.0);
for (j = 0; j < n; j++)
{
TBBox &r = list[j];
pdfRectangle(PDF, r.x1, r.y1, r.Width(), r.Height(), fmClose);
Previous topic: GetSelBBox
Next topic: GetSelBBox2