

PdfWriter writer PdfWriter.GetInstance(doc, ms). PdfWriter writer = PdfWriter.GetInstance(doc, outPDF) i created a pdf doc using itextsharp and saved in to memorystream this memorystream write into pdf file. Using (Document doc = new Document(PageSize.LETTER)) Using (PdfReader pdfr = new PdfReader(inPDF)) MemoryStream outPDF = new MemoryStream() Throw new ArgumentException("Function only supports from size A4 to size letter") If (fromSize != LetterSize.A4 || toSize != LetterSize.Letter) My code: public static byte ConvertPdfSize(byte inPDF, LetterSize fromSize, LetterSize toSize) The below code only work for text, If you text contain html text then you have to change below code.
#Use memory stream with pdfwriter how to
How to get a byte array from PdfWriter, writing to a memorystream in iTextSharp I have slightly modified your code, please fine below. In place B and C, the stream is closed, and cannot be accessed. My guess is the doc.Close() has to run first. In place A, the length of the memorystream is only 255, which doesn't work. I tried putting this code in three places, see place A, B and C in the code. After, I want to say outBytes = outPDF.ToArray().

I create the PdfWriter using a memorystream in the constructor ( outPDF), and then does my conversion. I want to return a byte array, and want to keep the whole thing in memory. The idea is it transforms a PDF file with a specific size, to another size. I have a method, which takes in the following:
