3

I want to scale a full pdf-page and insert into an new document. This works fine. But i have problems with the scale-factor when the factor is less than 1%. for example with a factor of 0,5%, no scale is happening. With a factor from 0,7%, the document (rectagle) has the correct size, but the scaled page is bigger then the calculated new size. Is there a way to scale a page continuously? It looks like, that in such cases with very small scale factors, the scaling works only in stages. Or maybe is there a problem with the internal matrix-calculation?

float scale = 1.005f; //100,5%
var newWidth = originWidth*scale;
var newHeight = originHeight*scale;
PdfReader reader = new PdfReader(inputfile);
var newMediaBox = new Rectangle(newWidth, newHeight);
Document doc = new Document(newMediaBox);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(outputfile,FileMode.Create));

doc.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page = writer.GetImportedPage(reader, 1); //page #1

cb.AddTemplate(page, scale, 0, 0, scale, 0, 0);

doc.Close();

The other way: Can i calculate or read out the new size after the scaling?

Thanks.

1 Answers1

2

iTextSharp by default will use two decimal places rounded when adding the template. You can change this by setting the HIGH_PRECISION static variable of the ByteBuffer class to true which will give you six decimal places. I do not know if this will affect your overall application performance but I'm fairly confident that it won't.

iTextSharp.text.pdf.ByteBuffer.HIGH_PRECISION = true;
Chris Haas
  • 53,986
  • 12
  • 141
  • 274