DynaPDF Manual - Page 626

Previous Page 625   Index   Next Page 627

Function Reference
Page 626 of 839
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;
double w, h;
// Create a new PDF file
pdfCreateNewPDF(PDF, "cppout.pdf");
pdfSetPageCoords(PDF, pcTopDown);
// Open an existing PDF file
pdfOpenImportFile(PDF, "c:/PDFs/test.pdf", ptOpen, NULL);
double x = 50.0;
double y = 50.0;
SI32 count = pdfGetInPageCount(PDF);
for (i = 1; i <= count; i++)
{
// Get the page format and orientation angle of the source page.
// We need the original page format to center the template into the
// destination rectangle.
pdfGetInBBox(PDF, i, pbMediaBox, mediaBox);
pdfGetInBBox(PDF, i, pbCropBox, cropBox);
orientation = pdfGetInOrientation(PDF, i);
// Import the page as a template
tmpl = pdfImportPage(PDF, i);
// Calculate the logical width and height of the page.
w = cropBox.Right - cropBox.Left;
h = cropBox.Top - cropBox.Bottom;
if (w < 1.0)
{
w = mediaBox.Right - mediaBox.Left;
h = mediaBox.Top - mediaBox.Bottom;
}
// Exchange the widht and height if necessary
switch(orientation)
{
case 90:
 

Previous topic: PlaceTemplateEx

Next topic: PlaceTemplByMatrix