Hello Paulo,
I updated the code due to your reccomendations in the previous posts. here
is the whole function.
Please find two pdfs attached. The small is without itext (54KB), the second
is based on the small and touched by itext (105KB):
http://www.nabble.com/file/p13838047/F593_2033.PDF F593_2033.PDF
http://www.nabble.com/file/p13838047/small_F593_2033.PDF small_F593_2033.PDF
public string StampFile(string fileName, string text, string
fontPath,
float fontSize, float orientation, System.Drawing.Color color, float
horzPos, float vertPos)
{
PdfReader reader = new PdfReader(fileName);
reader.RemoveUnusedObjects();
using (FileStream fs = new FileStream(fileName + "1",
FileMode.Create))
{
PdfStamper stamp = new PdfStamper(reader, fs,
reader.PdfVersion, false);
//stamp.SetFullCompression();
int n = reader.NumberOfPages;
System.Windows.Size dimensions;
// BaseFont bf = BaseFont.CreateFont(fontPath,
BaseFont.IDENTITY_H,
BaseFont.NOT_EMBEDDED); // IDENTITY_H BaseFont.HELVETICA, BaseFont.CP1252
BaseFont bf =
BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.NOT_EMBEDDED); // IDENTITY_H BaseFont.HELVETICA, BaseFont.CP1252
iTextSharp.text.Color iColor = new
iTextSharp.text.Color(color.ToArgb());
for (int index = 1; index <= n; index++)
{
dimensions = new
System.Windows.Size(stamp.GetImportedPage(reader,
index).Width, stamp.GetImportedPage(reader, index).Height);
//PdfContentByte under =
stamp.GetUnderContent(1);
// change the content beneath page 1
PdfContentByte cb =
stamp.GetOverContent(index);
// change the content on top of page 1
cb.BeginText();
cb.SetFontAndSize(bf, fontSize);
cb.SetColorFill(iColor);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, (float)horzPos,
(float)dimensions.Height - vertPos, orientation);
cb.EndText();
}
stamp.Close();
reader.Close();
}
File.Copy(fileName + "1", fileName,true);
File.Delete(fileName + "1");
return "";
}
Please note, If the PDF itself gets bigger itself (ie. 800KB) it gets bigger
in proportion (1600KB)
Thank you!
Paulo Soares wrote:
>
> The PDF you posted was not created with this code. If you use this code
> and the Helvetica font it will not grow that much.
>
> Paulo
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On
>> Behalf Of jamesblast
>> Sent: Monday, November 19, 2007 1:42 PM
>> To: [email protected]
>> Subject: Re: [iText-questions] PDFStamper doubles filesize
>>
>>
>> Hallo Paulo,
>> thank you for your reply.
>> Here is my code like in the initial post:
>> PdfReader reader = new PdfReader(fileName);
>> reader.RemoveUnusedObjects();
>> using (FileStream fs = new FileStream(fileName + "1",
>> FileMode.Create))
>> {
>> PdfStamper stamp = new PdfStamper(reader, fs);
>> int n = reader.NumberOfPages;
>> System.Windows.Size dimensions;
>> //fontpath ie. c:\windows\fonts\arial.ttf
>> BaseFont bf = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H,
>> BaseFont.NOT_EMBEDDED);
>> iTextSharp.text.Color iColor = new
>> iTextSharp.text.Color(color.ToArgb());
>> for (int index = 1; index <= n; index++)
>> {
>> dimensions = new
>> System.Windows.Size(stamp.GetImportedPage(reader,
>> index).Width, stamp.GetImportedPage(reader, index).Height);
>> PdfContentByte cb = stamp.GetOverContent(index);
>> // change the content on top of page 1
>> cb.BeginText();
>> cb.SetFontAndSize(bf, fontSize);
>> cb.SetColorFill(iColor);
>> cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT,
>> text, (float)horzPos,
>> (float)dimensions.Height - vertPos, orientation);
>> cb.EndText();
>> }
>> stamp.Close();
>> reader.Close();
>> }
>> Please show me what is wrong!
>>
>> Thank you!
>>
>> Paulo Soares wrote:
>> >
>> > You are using append mode (why?) and creating a template
>> that is not used.
>> > Please show us your code.
>> >
>> > Paulo
>> >
>> > ----- Original Message -----
>> > From: "jamesblast" <[EMAIL PROTECTED]>
>> > To: <[email protected]>
>> > Sent: Monday, November 19, 2007 7:34 AM
>> > Subject: Re: [iText-questions] PDFStamper doubles filesize
>> >
>> >
>> >>
>> >> Hello Bruno,
>> >>
>> >> please find the file attached!
>> >> "small_xxxx.pdf" is before using itext.
>> >> Thank you for evaluating!
>> >>
>> >> http://www.nabble.com/file/p13828924/F269_1668.PDF F269_1668.PDF
>> >> http://www.nabble.com/file/p13828924/small_F269_1668.PDF
>> >> small_F269_1668.PDF
>> >> Regards!
>> >>
>> >>
>> >>
>> >> Bruno Lowagie (iText) wrote:
>> >>>
>> >>> jamesblast wrote:
>> >>>> There are no images or stuff like that in the source PDF.
>> >>>> Example: A small file (about 25kb) generated by a
>> PDF-printer component
>> >>>> gets
>> >>>> about 50KB.
>> >>>
>> >>> Can you post this small example?
>> >>> That way we can try to reproduce the problem.
>> >>> br,
>> >>> Bruno
>
>
> Aviso Legal:
>
> Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
> informação confidencial ou legalmente protegida. A incorrecta transmissão
> desta mensagem não significa a perca de confidencialidade. Se esta
> mensagem for recebida por engano, por favor envie-a de volta para o
> remetente e apague-a do seu sistema de imediato. É proibido a qualquer
> pessoa que não o destinatário de usar, revelar ou distribuir qualquer
> parte desta mensagem.
>
>
>
> Disclaimer:
>
> This message is destined exclusively to the intended receiver. It may
> contain confidential or legally protected information. The incorrect
> transmission of this message does not mean the loss of its
> confidentiality. If this message is received by mistake, please send it
> back to the sender and delete it from your system immediately. It is
> forbidden to any person who is not the intended receiver to use,
> distribute or copy any part of this message.
>
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> Buy the iText book: http://itext.ugent.be/itext-in-action/
>
>
--
View this message in context:
http://www.nabble.com/PDFStamper-doubles-filesize-tf4820268.html#a13838047
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/