How do scale a pdf with CGPDFDocumentMBS?

I create a pdf from html with

call HTMLViewer1.PrintToPDFFileMBS(tempItem, 50, 50, 50, 50)

which I then embed into another pdf and add a header and page numbers:

[code]dim thePDFDoc as CGPDFDocumentMBS = thePDFFile.OpenAsCGPDFDocumentMBS
dim pageCount as Integer = thePDFDoc.PageCount

dim finalPDF as CGContextMBS = newPrintPath.NewCGPDFDocumentMBS(thePDFDoc.MediaBox(1), left(theSubject, 100), theMessageID, App.ApplicationNameMBS)

'loop through pages and add header information
for currentPage as Integer = 1 to pageCount

dim theRect as new CGRectMBS 
theRect = thePDFDoc.MediaBox(currentPage)
if theRect = nil then Return
finalPDF.BeginPage theRect
finalPDF.DrawCGPDFDocument(thePDFDoc, theRect, currentPage)

if PDFPrintHeader then
  DrawPDFHeader(finalPDF, theSubject, 50, theRect.Height - 35)
end if
DrawPDFHeader(finalPDF, str(currentPage) + "/" + str(pageCount), theRect.Width - 50, theRect.Height - 35)

'page is finished
finalPDF.EndPage

next

finalPDF.Flush[/code]

Now I want to change the PrintToPDFFileMBS to

dim PDFData as MemoryBlock = me.RenderDocumentToPDFMBS

which doesn’t have margins. I see how to use a CGDataProviderMBS to create the pdf:

dim theProvider as CGDataProviderMBS = CGDataProviderMBS.CreateWithData(PDFData) dim thePDFDoc as CGPDFDocumentMBS = CGOpenPDFDocumentMBS(theProvider)

But how do I scale the original pdf so that it fits into the MediaBox of the new one? Changing the CGRectMBS didn’t do anything.

you can pass a new rectangle with the new size for DrawCGPDFDocument function.
and of course use NewCGPDFDocumentMBS with new rectangle page size.

PS: With DynaPDF classes you have more options.

No, that does’t work. Already tried that.

No, DynaPDF also doesn’t work because I have html which I convert to pdf. If I pay so much for a solution then I want the solution to do everything that I need.

this works fine for me:

[code]Dim thePDFFile As FolderItem = SpecialFolder.Desktop.Child(“test.pdf”)
Dim thePDFDoc As CGPDFDocumentMBS = thePDFFile.OpenAsCGPDFDocumentMBS
Dim pageCount As Integer = thePDFDoc.PageCount

Dim newPrintPath As FolderItem = SpecialFolder.Desktop.Child(“output.pdf”)
Dim finalPDF As CGContextMBS = newPrintPath.NewCGPDFDocumentMBS(thePDFDoc.MediaBox(1), “test”, “test”, “test”)

'loop through pages and add header information
For currentPage As Integer = 1 To pageCount

Dim theRect As CGRectMBS = thePDFDoc.MediaBox(currentPage)
If theRect = Nil Then Return
finalPDF.BeginPage theRect

// shrink by 100 point.
Dim r As new CGRectMBS(theRect.Origin.x + 100, theRect.Origin.y + 100, theRect.Size.Width-200, theRect.size.Height-200)

finalPDF.DrawCGPDFDocument(thePDFDoc, r, currentPage)
finalPDF.EndPage
Next

finalPDF.Flush[/code]

Urg… plus equals minus as my old physics professor always said. Of course, I tried to make the rect smaller and not larger. Will check later.