<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali Jago Seif</title>
    <description>The latest articles on DEV Community by Ali Jago Seif (@alijagoseif).</description>
    <link>https://dev.to/alijagoseif</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F120931%2F2d637cd5-818e-4a8c-9d5d-a2919b5605c8.jpg</url>
      <title>DEV Community: Ali Jago Seif</title>
      <link>https://dev.to/alijagoseif</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alijagoseif"/>
    <language>en</language>
    <item>
      <title>Rotating PDF page in C#</title>
      <dc:creator>Ali Jago Seif</dc:creator>
      <pubDate>Wed, 19 Dec 2018 16:49:14 +0000</pubDate>
      <link>https://dev.to/alijagoseif/rotating-pdf-page-in-c-6ol</link>
      <guid>https://dev.to/alijagoseif/rotating-pdf-page-in-c-6ol</guid>
      <description>&lt;p&gt;Here I am going to show you how to rotate PDF in C# with RotatePage method. I use BCL's &lt;a href="https://www.pdfonline.com/c%23-pdf-library/"&gt;PDF Library&lt;/a&gt; to process data in PDF files. It also allows you to create, manipulate and convert files to PDF from multiple sources accurately.&lt;/p&gt;

&lt;p&gt;PDF Processor API, that allows to process and manipulate existing PDF documents, has several methods. The one that does pages rotation is called "RotatePages".&lt;/p&gt;

&lt;p&gt;This particular code below rotates the page(s). All the parameters should be set in this string:&lt;br&gt;
&lt;code&gt; oPDFProcessor.RotatePages(string InputFileName,string OutputFileName,int From,int To,prcPageRotation.PRC_ROT_{angle}_DEG &lt;br&gt;
        MessageBox.Show("Rotate Success!");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;br&gt;
InputFileName - Input file name;&lt;br&gt;
OutputFileName - Output file name;&lt;br&gt;
From - Rotate page from (first page = 0);&lt;br&gt;
To -  Rotate Page to;&lt;br&gt;
Angle - 0|90|180|270|clockwise|counterclockwise|anticlockwise|upsidedown.&lt;/p&gt;

&lt;p&gt;This code demonstrates how to rotate pages. The code rotates the first page in a PDF file by 90 degrees.&lt;/p&gt;

&lt;pre&gt;
private void Rotate_Test(string inFile, string outFile)
{
    try
    {
        PDFProcessor oPDFProcessor = new PDFProcessor();
            // rotate the first page 90 by degrees
oPDFProcessor.RotatePages(inFile,outFile,0,0,prcPageRotation.PRC_ROT_90_DEG 
        MessageBox.Show("Rotate Success!");
    }
    catch(System.Runtime.InteropServices.COMException err)
    {
        MessageBox.Show(err.Message + " (" + err.ErrorCode.ToString() + ")");
    }
}
&lt;/pre&gt;

</description>
      <category>pdf</category>
      <category>rotate</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Merge PDF files in C#</title>
      <dc:creator>Ali Jago Seif</dc:creator>
      <pubDate>Tue, 18 Dec 2018 18:37:29 +0000</pubDate>
      <link>https://dev.to/alijagoseif/merge-pdf-files-in-c-2k74</link>
      <guid>https://dev.to/alijagoseif/merge-pdf-files-in-c-2k74</guid>
      <description>&lt;p&gt;In this article, I am going to show you how to merge multiple PDF files programmatically using Merge_File method and &lt;a href="http://pdfonline.com/pdf-sdk/"&gt;easy PDF SDK&lt;/a&gt;. This C# sample program demonstrates how to merge PDF pages using the PDFProcessor API.&lt;/p&gt;

&lt;p&gt;The file names are assumed to be in the array files[]. The merged file is saved under “outFileName”&lt;/p&gt;

&lt;pre&gt;
private void Merge_File(string[] files, string outFileName)
{
    try
    {
        PDFProcessor oPDFProcessor = new PDFProcessor();
            // loop over all the files, which are concatenated one by one
            string inFileName = files[0];
    
        for(int i = 1; i &amp;lt; files.Length; i++)
        {
            oPDFProcessor.Merge(inFileName, files[i], outFileName);         
            inFileName = outFileName;
        }               
            
        MessageBox.Show(files.Length.ToString() + " files merged!");
    }
    catch(System.Runtime.InteropServices.COMException err)
    {
        MessageBox.Show(err.Message + " (" + err.ErrorCode.ToString() + ")");
    }
}
&lt;/pre&gt;

</description>
      <category>csharp</category>
      <category>pdf</category>
    </item>
    <item>
      <title>Merge PDF Documents in Directory in C#</title>
      <dc:creator>Ali Jago Seif</dc:creator>
      <pubDate>Tue, 11 Dec 2018 19:23:41 +0000</pubDate>
      <link>https://dev.to/alijagoseif/merge-pdf-documents-in-directory-in-c-5854</link>
      <guid>https://dev.to/alijagoseif/merge-pdf-documents-in-directory-in-c-5854</guid>
      <description>

&lt;p&gt;In my first post, I am going to provide you with a method to merge all of the pdf files in a particular directory. The full method is displayed in &lt;a href="https://www.pdfonline.com/easypdf/sdk/programming-pdf/csharp/"&gt;PDF C#&lt;/a&gt; code below. Feel free to copy and paste it into your application in its entirety. Together we will cover all of the individual steps of this way to merging PDF files in C#.&lt;/p&gt;

&lt;p&gt;First of all, please keep in mind to add the proper References to your Project, and the Using Entries to go along with these References. Your project is required that the &lt;a href="https://www.pdfonline.com/c%23-pdf-library/"&gt;C# PDF Library&lt;/a&gt;  Processor Reference is added, and will require the following "using" entries:&lt;/p&gt;

&lt;p&gt;using System;&lt;br&gt;
using System.IO;&lt;br&gt;
using System.Collections;&lt;br&gt;
using BCL.easyPDF8.Interop.EasyPDFProcessor;&lt;/p&gt;

&lt;p&gt;The Method's Name is as follows:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
public static string MergeAllPDFFilesInDIR(string inFileDir, string OutFileName)&lt;br&gt;
    {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It is proposed to take two string variables and return one string variable. The return value is a String that will contain a status report, either a report of the successful conversion, with the name of the Output File produced, or the best possible Error Reports. inFileDir is the place you determine your Input Directory, while OutFileName is the output FileName.&lt;/p&gt;

&lt;p&gt;inFileDir must use this format: @"C:\YourFolderName\". On the other side OutFileName needs to follow this format: @"C:\YourFolderName\OutName.pdf".&lt;br&gt;
Otherwise, you can enter a value of null for OutFileName and the method will automatically generate an output File Name with its own name.&lt;/p&gt;

&lt;p&gt;This is how we declare the Primary Variables and Objects.&lt;br&gt;
&lt;code&gt;&lt;br&gt;
 //Declare Major Variables and Objects&lt;br&gt;
        string result = null;&lt;br&gt;
        DirectoryInfo Dir = null;&lt;br&gt;
        FileInfo[] FileList = null;&lt;br&gt;
        ArrayList InputFileList = null;&lt;br&gt;
        PDFProcessor oMerger = null;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once Variables and Objects are declared, you need to check that the Input Directory exists by a small if-then statement. This also checks to see if a null variable was passed as the OutputFileName, and if so, generates a filename inside the input directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
 // Identify inFileDir and OutFileName&lt;br&gt;
        Dir = new DirectoryInfo(inFileDir);&lt;br&gt;
        if (!Dir.Exists)&lt;br&gt;
        {&lt;br&gt;
            result = "Directory : " + inFileDir + " : Does not Exist";&lt;br&gt;
            return result;&lt;br&gt;
        }&lt;br&gt;
        if (OutFileName == null)&lt;br&gt;&lt;br&gt;
        //If OutFileName is NUll, provide a&lt;br&gt;
        //Default File Name and Location&lt;br&gt;
        {&lt;br&gt;
            OutFileName = inFileDir + "_1_Merged.pdf";&lt;br&gt;
        }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After that, we need to gather all of the input files to the ArrayList Object as it is shown above. If there are no PDF files in the directory, an error will be returned and the programme will end. Otherwise, all of the PDF files in the directory are going to be loaded one by one into the ArrayList Object for further merging.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// Gather Input Files&lt;br&gt;
        FileList = Dir.GetFiles("*.pdf", SearchOption.AllDirectories);&lt;br&gt;
        InputFileList = new ArrayList();&lt;br&gt;
        foreach (FileInfo FI in FileList) { InputFileList.Add(FI.FullName); &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;        if (InputFileList.Count == 0)&lt;br&gt;
        {&lt;br&gt;
            result = "There were no PDF Files in : " + inFileDir;&lt;br&gt;
            return result;&lt;br&gt;
        }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When the input files are collected, the method creates the Processory Object and Initializes it as well. In addition, it applies the License Key (which is required to use this C# PDF Library) to the object. You can get the free one on &lt;a href="https://www.pdfonline.com/pdf-sdk/"&gt;PDF SDK&lt;/a&gt; website.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// Create Processor Object&lt;br&gt;
        try&lt;br&gt;
        {&lt;br&gt;
            oMerger = new PDFProcessor();&lt;br&gt;
            oMerger.LicenseKey = "475D-E1ED-5336-DD76-2C5E-FDAE";&lt;br&gt;
//If you are using the BCL Licensing System, enter your License Key Here;&lt;br&gt;
        }&lt;br&gt;
        catch (Exception errCreate)&lt;br&gt;
        {&lt;br&gt;
            result = "Attempt to create PDFProcessor oMerger Failed : Message : " &lt;br&gt;
                + errCreate.Message + " : Inner Exception : "&lt;br&gt;
                + errCreate.InnerException;&lt;br&gt;
            return result;&lt;br&gt;
        }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the Object is initialized, the actual merger is carried out in the following code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;//Run MergeBatch&lt;br&gt;
        try&lt;br&gt;
        {&lt;br&gt;
            oMerger.MergeBatch(InputFileList.ToArray(), OutFileName);&lt;br&gt;
        }&lt;br&gt;
        catch (Exception errRun)&lt;br&gt;
        {&lt;br&gt;
            result = "Attempt to Merge the Documents Failed : Message : " &lt;br&gt;
                + errRun.Message + " : Inner Exception : " + errRun.InnerException;&lt;br&gt;
            return result;&lt;br&gt;
        }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;        result = "Merging Complete : Output File located at : " + OutFileName;&lt;br&gt;
        return result;&lt;br&gt;
    }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You receive a message that indicates that the Merge has been completed if everything works as intended. The output file is located at the location specified by you. Because we formatted the OutFileName string to include the entire file address, you will be told both what the file is named and where it is located. If there are any errors, they should be reported instead.&lt;/p&gt;

&lt;p&gt;Here is the full Method's code, ready to be added to any C# application:&lt;/p&gt;

&lt;pre&gt;
public static string MergeAllPDFFilesInDIR(string inFileDir, string OutFileName)
    {
            //Declare Major Variables and Objects
        string result = null;
        DirectoryInfo Dir = null;
        FileInfo[] FileList = null;
        ArrayList InputFileList = null;
        PDFProcessor oMerger = null;

            // Identify inFileDir and OutFileName
        Dir = new DirectoryInfo(inFileDir);
        if (!Dir.Exists)
        {
            result = "Directory : " + inFileDir + " : Does not Exist";
            return result;
        }
        if (OutFileName == null)    
        //If OutFileName is NUll, provide a
        //Default File Name and Location
        {
            OutFileName = inFileDir + "_1_Merged.pdf";
        }

            // Gather Input Files
        FileList = Dir.GetFiles("*.pdf", SearchOption.AllDirectories);
        InputFileList = new ArrayList();
        foreach (FileInfo FI in FileList) { InputFileList.Add(FI.FullName); }

        if (InputFileList.Count == 0)
        {
            result = "There were no PDF Files in : " + inFileDir;
            return result;
        }

            // Create Processor Object
        try
        {
            oMerger = new PDFProcessor();
            oMerger.LicenseKey = "475D-E1ED-5336-DD76-2C5E-FDAE";    
            //If you are using the BCL Licensing System, enter your License Key Here;
        }
        catch (Exception errCreate)
        {
            result = "Attempt to create PDFProcessor oMerger Failed : Message : " 
                + errCreate.Message + " : Inner Exception : "
                + errCreate.InnerException;
            return result;
        }
        
            //Run MergeBatch
        try
        {
            oMerger.MergeBatch(InputFileList.ToArray(), OutFileName);
        }
        catch (Exception errRun)
        {
            result = "Attempt to Merge the Documents Failed : Message : " 
                + errRun.Message + " : Inner Exception : " + errRun.InnerException;
            return result;
        }

        result = "Merging Complete : Output File located at : " + OutFileName;
        return result;
    }
&lt;/pre&gt;

&lt;p&gt;Please feel free to contact me if you have any questions or problems concerning this method, or if you have any ideas for Methods you would like me to create.&lt;/p&gt;

&lt;p&gt;Have a good coding!&lt;/p&gt;


</description>
      <category>pdf</category>
      <category>csharp</category>
      <category>mergepdf</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
