DynaPDF Manual - Page 584

Previous Page 583   Index   Next Page 585

Function Reference
Page 584 of 787
Return values:
If the function succeeds the return value is 1. If the function fails the return value is 0.
Example (C++)
The following code collects 6 imported pages on one destination page. The imported pages are
placed horizontally and vertically centered into a fixed destination rectangle.
// This is our error callback function
SI32 PDF_CALL PDFError(const void* Data, SI32 ErrCode,
const char* ErrMessage, SI32 ErrType)
{
printf("%s\n", ErrMessage);
return 0;
}
// This function places a template horizontally and vertically centered
// into a destination rectangle
SI32 PlaceCenteredEx(const void* PDF, // Instance pointer
SI32 Tmpl,
// Template handle
double SrcWidth,
// Logical page width
double SrcHeight,
// Logical page height
double DestX,
// Destination x-coordinate
double DestY,
// Destination y-coordinate
double DestWidth,
// Destination width
double DestHeight) // Destination height
{
double x, y, w, h, sx;
sx = DestWidth / SrcWidth; // Compute the scaling factor
// Which side must be centered?
if (SrcHeight * sx <= DestHeight)
{
w = SrcWidth
* sx;
h = SrcHeight * sx;
x = DestX + (DestWidth
- w) * 0.5;
y = DestY + (DestHeight - h) * 0.5;
pdfPlaceTemplateEx(PDF, Tmpl, x, y, DestWidth, 0.0);
}else
{
sx = DestHeight / SrcHeight;
w = SrcWidth
* sx;
h = SrcHeight * sx;
x = DestX + (DestWidth
- w) * 0.5;
y = DestY + (DestHeight - h) * 0.5;
pdfPlaceTemplateEx(PDF, Tmpl, x, y, 0.0, DestHeight);
}
// We draw the destination rectangle on the page so that we can check
// whether the position was correctly calculated.
pdfSetLineWidth(PDF, 0.5);
return pdfRectangle(PDF, DestX, DestY, DestWidth, DestHeight, fmStroke);
}
// The PDF instance must be created outside the function
LBOOL TestTemplates(const void* PDF)
{
bool newPage = true;
SI32 i, tmpl, orientation = 0;
TPDFRect mediaBox, cropBox;
 

Previous topic: PlaceTemplateEx

Next topic: PlaceTemplByMatrix, PolygonAnnot

Start Chat