I am trying to rotate a pdf 180 degrees and I am using the ITextSharp library to do so. The code below is taken from their site's examples. However, I can't seem to find the right namespace to import to get the "FileOutputStream" to work.
This is a console app, so not sure if Java's "FileOutpuStream" will work.
The PDFStamper() is structured like this:
PdfStamper(PDFReader reader, Stream os)
public void rotatePDF(string inputFile)
{
// get input document
PdfReader reader = new PdfReader(inputFile);
PdfName pdfName = new PdfName(inputFile);
int n = reader.NumberOfPages;
int rot;
PdfDictionary pageDict;
for (int i = 1; i <= n; i++)
{
rot = reader.GetPageRotation(i);
pageDict = reader.GetPageN(i);
pageDict.Put(PdfName.ROTATE, new PdfNumber(rot + 180));
}
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(inputFile));
stamper.closer();
reader.Close();
}
InputStream − This is used to read (sequential) data from a source. OutputStream − This is used to write data to a destination.
FileWriter vs FileOutputStreamFileWriter writes streams of characters while FileOutputStream is meant for writing streams of raw bytes.
Creates a file output stream to write to the file represented by the specified File object. If the second argument is true , then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.
FileOutputStream is an outputstream for writing data/streams of raw bytes to file or storing data to file. FileOutputStream is a subclass of OutputStream. To write primitive values into a file, we use FileOutputStream class.
Try using a FileStream
. It's in System.IO
PdfStamper stamper = new PdfStamper(reader, new FileStream(inputFile, FileMode.Create));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With