Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Originally Posted by GeoCrystal
Hi Stanav,
May be a stupid doubt, but.....
Can I use the same code for a web application? coz, I think iTextSharp does not work on relative paths....
Yes, you certainly can. You don't use the relative paths. However, you can get the physical path from a relative path using Server.MapPath method in asp.net or something equivalent in other platforms.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Originally Posted by stanav
This thread was originally about extracting and merging pdf files using iTextSharp. However, as time goes by, I have added a lot more code to do other stuff and put them all together into a handy class called PdfManipulation. There are 2 classes as below (choose the one that matches the iTextSharp version you're using):
1. The original PdfManipulation.vb class is coded based on itextsharp version 4. This class is obsolete and no longer maintained.
2. The updated PdfManipulation2.vb class is for the newer itextsharp version 5. This class also contains alot more methods than the original one and I highly recommend it over the old one. I will update this class from time to time to fix bugs and/or add more functionality. Consider it's a work in progress
Please verify the version of iTextSharp you're using and download the correct class.
Below is the list of public methods in the new PdfManipulation2 class
vb.net Code:
'Remove all restrictions from a pdf file
Public Shared Function RemoveRestrictions(ByVal restrictedPdf As String, Optional ByVal saveABackup As Boolean = True) As Boolean
'Parse text from a specified range of pdf pages
Public Shared Function ParsePdfText(ByVal sourcePDF As String, _
Optional ByVal fromPageNum As Integer = 0, _
Optional ByVal toPageNum As Integer = 0) As String
'Parse all text from a pdf
Public Shared Function ParseAllPdfText(ByVal sourcePDF As String) As Dictionary(Of Integer, String)
'Page to page comparision of 2 pdf files and write the differences to a resulting text file
Public Shared Sub ComparePdfs(ByVal pdf1 As String, ByVal pdf2 As String, _
ByVal resultFile As String, _
Optional ByVal fromPageNum As Integer = 0, _
Optional ByVal toPageNum As Integer = 0)
'Extract specified pages from a pdf to create a new pdf
Public Shared Sub ExtractPdfPages(ByVal sourcePdf As String, ByVal pageNumbersToExtract As Integer(), ByVal outPdf As String)
'Split a pdf into specified number of pdfs
Public Shared Sub SplitPdfByParts(ByVal sourcePdf As String, ByVal parts As Integer, ByVal baseNameOutPdf As String)
'Split a pdf into multiple pdfs each containing a specified number of pages.
Public Shared Sub SplitPdfByPages(ByVal sourcePdf As String, ByVal numOfPages As Integer, ByVal baseNameOutPdf As String)
'Extract pages from multiple source pdfs and merge into a final pdf
Public Shared Sub ExtractAndMergePdfPages(ByVal sourceTable As DataTable, ByVal outPdf As String)
'Set security password on an existing pdf file
Public Shared Sub SetSecurityPasswords(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal userPassword As String, ByVal ownerPassword As String)
'Add watermark to pdf pages using an image
Public Shared Sub AddWatermarkImage(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkImage As String)
'Add water mark to all pdf pages using text
Public Shared Sub AddWatermarkText(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkText() As String, _
Optional ByVal watermarkFont As iTextSharp.text.pdf.BaseFont = Nothing, _
Optional ByVal watermarkFontSize As Single = 48, _
Optional ByVal watermarkFontColor As iTextSharp.text.BaseColor = Nothing, _
Optional ByVal watermarkFontOpacity As Single = 0.3F, _
Optional ByVal watermarkRotation As Single = 45.0F)
'Merge multiple pdfs into a single one.
Public Shared Function MergePdfFiles(ByVal pdfFiles() As String, ByVal outputPath As String, _
Optional ByVal authorName As String = "", _
Optional ByVal creatorName As String = "", _
Optional ByVal subject As String = "", _
Optional ByVal title As String = "", _
Optional ByVal keywords As String = "") As Boolean
'Merge multiple pdf's into one with all bookmarks preserved
Public Shared Function MergePdfFilesWithBookmarks(ByVal sourcePdfs() As String, ByVal outputPdf As String) As Boolean
'Add document outline (bookmarks) to a pdf
Public Shared Sub AddDocumentOutline(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal outlineTable As System.Data.DataTable)
'Extract urls from a pdf
Public Shared Function ExtractURLs(ByVal sourcePdf As String, Optional ByVal pageNumbers() As Integer = Nothing) As System.Data.DataTable
'Extract images from a pdf
Public Shared Function ExtractImages(ByVal sourcePdf As String) As List(Of Image)
'Fill a form
Public Shared Sub FillAcroForm(ByVal sourcePdf As String, ByVal fieldData As DataRow, ByVal outputPdf As String)
Public Shared Sub FillMyForm(ByVal sourcePdf As String, ByVal fieldData As DataRow, ByVal outputPdf As String)
'Add annotatation
Public Shared Sub AddTextAnnotation(ByVal sourcePdf As String, ByVal outputPdf As String)
Public Shared Function GetAcroFieldData(ByVal sourcePdf As String) As Dictionary(Of String, String)
Public Shared Function GetPdfSummary(ByVal sourcePdf As String) As DataTable
Public Shared Function ReplacePagesWithBlank(ByVal sourcePdf As String, _
ByVal pagesToReplace As List(Of Integer), _
ByVal outPdf As String, _
Optional ByVal templatePdf As String = "") As Boolean
Public Shared Function InsertPages(ByVal sourcePdf As String, _
ByVal pagesToInsert As Dictionary(Of Integer, iTextSharp.text.pdf.PdfImportedPage), _
ByVal outPdf As String) As Boolean
Public Shared Function RemovePages(ByVal sourcePdf As String, ByVal pagesToRemove As List(Of Integer), ByVal outputPdf As String) As Boolean
'A demo on how to draw various shapes in itextsharp
Public Shared Sub DrawShapesDemo(ByVal sourcePdf As String, ByVal outputPdf As String)
Public Shared Sub AddImageToPage(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal imgPath As String, ByVal imgLocation As Point, ByVal imgSize As Size, Optional ByVal pages() As Integer = Nothing)
Any comments are welcomed.
Happy coding
Stanav.
Hello Stanav,
First of all thanks for your valuable post. It helped me a lot in few fuzzy things.
I am using the itextsharp 5.1.1.0 dll version along with your PDFManipulation2.vb code.
I want to remove restrictions of the PDF File which has 128 bit AES encryption. But i only have user password & do not have owner password.
For that i tried your method named "RemoveRestrictions" but it's throwing exception stating "Bad User Password". So could you please help me in this ?
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Originally Posted by rktech
Hello Stanav,
First of all thanks for your valuable post. It helped me a lot in few fuzzy things.
I am using the itextsharp 5.1.1.0 dll version along with your PDFManipulation2.vb code.
I want to remove restrictions of the PDF File which has 128 bit AES encryption. But i only have user password & do not have owner password.
For that i tried your method named "RemoveRestrictions" but it's throwing exception stating "Bad User Password". So could you please help me in this ?
Thanks in advance...
I've made some changes in the RemoveRestrictions method to allow a password to be passed in if the restricted pdf is password protected. You need to re-download the PdfManipulation2.vb class.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Originally Posted by stanav
I've made some changes in the RemoveRestrictions method to allow a password to be passed in if the restricted pdf is password protected. You need to re-download the PdfManipulation2.vb class.
================
Stanav,
Thanks for your reply. I tried the same steps mentioned by you. But still its giving "Bad User Password" when i am passing the User password , not the Owner password, as my requirements are to remove restrictions with user password not owner password.
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
It should work with user password. I've tried it myself.
Can you upload a sample password protected pdf and give me the user password?
It could be the version of iTextSharp you're using (5.1.1.0). I was testing it using the older version 5.0.2.0.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Dear Stanav,
Thanks for your valuable reply.
Yes i tried & it worked.I was doing some mistake earlier.
But thanks a ton to you for your valuable support.
Also i am stuck in some other dot net setup problem as mentioned below. Can you share your update in same if possible ?
i have 1 .net windows application & same needs to be distributed so for that i had made setup & deployment project that has created 3 files as below.
a) MSI installer file.
b) Setup file.
c) dotnetfx30 file as dotnet is prerequisite & required this application to work so it needs to be installed
first.
Target Area is to have single .Exe file instead of above 3 files. How can we accomplish this ?
Please help...
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Thank you stanav, itextsharp.dll ver. 5.1.2.0 works great with your class PdfManipulation2.vb
at first atempt without any problem. So, is there any way to donate you?
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Originally Posted by podpolanec
Thank you stanav, itextsharp.dll ver. 5.1.2.0 works great with your class PdfManipulation2.vb
at first atempt without any problem. So, is there any way to donate you?
I'm glad that the code I shared here has helped you. And thank you for your offer but it's my philosophy not to accept any monetary offers for helping others.
You can rep me though
Happy coding,
Stanav.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Dear Stanav,
Thanks for your valuable post that you have shared on this forum.
I have one scenario where your input is highly required i.e. i have tried your valuable code for removing the PDF restrictions whereas the encryption level were of 128 Bit Aes type with itextsharp dll version 4.0.3 & it worked awesome.
But when i am trying to remove pdf restrictions where the encryption type is 256 Bit aes then it throwing error & getting failed in removing restrictions.
This thread was originally about extracting and merging pdf files using iTextSharp. However, as time goes by, I have added a lot more code to do other stuff and put them all together into a handy class called PdfManipulation. There are 2 classes as below (choose the one that matches the iTextSharp version you're using):
1. The original PdfManipulation.vb class is coded based on itextsharp version 4. This class is obsolete and no longer maintained.
2. The updated PdfManipulation2.vb class is for the newer itextsharp version 5. This class also contains alot more methods than the original one and I highly recommend it over the old one. I will update this class from time to time to fix bugs and/or add more functionality. Consider it's a work in progress
Please verify the version of iTextSharp you're using and download the correct class.
Below is the list of public methods in the new PdfManipulation2 class
vb.net Code:
'Remove all restrictions from a pdf file
Public Shared Function RemoveRestrictions(ByVal restrictedPdf As String, Optional ByVal password As String = Nothing, Optional ByVal saveABackup As Boolean = True) As Boolean
'Parse text from a specified range of pdf pages
Public Shared Function ParsePdfText(ByVal sourcePDF As String, _
Optional ByVal fromPageNum As Integer = 0, _
Optional ByVal toPageNum As Integer = 0) As String
'Parse all text from a pdf
Public Shared Function ParseAllPdfText(ByVal sourcePDF As String) As Dictionary(Of Integer, String)
'Page to page comparision of 2 pdf files and write the differences to a resulting text file
Public Shared Sub ComparePdfs(ByVal pdf1 As String, ByVal pdf2 As String, _
ByVal resultFile As String, _
Optional ByVal fromPageNum As Integer = 0, _
Optional ByVal toPageNum As Integer = 0)
'Extract specified pages from a pdf to create a new pdf
Public Shared Sub ExtractPdfPages(ByVal sourcePdf As String, ByVal pageNumbersToExtract As Integer(), ByVal outPdf As String)
'Split a pdf into specified number of pdfs
Public Shared Sub SplitPdfByParts(ByVal sourcePdf As String, ByVal parts As Integer, ByVal baseNameOutPdf As String)
'Split a pdf into multiple pdfs each containing a specified number of pages.
Public Shared Sub SplitPdfByPages(ByVal sourcePdf As String, ByVal numOfPages As Integer, ByVal baseNameOutPdf As String)
'Extract pages from multiple source pdfs and merge into a final pdf
Public Shared Sub ExtractAndMergePdfPages(ByVal sourceTable As DataTable, ByVal outPdf As String)
'Set security password on an existing pdf file
Public Shared Sub SetSecurityPasswords(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal userPassword As String, ByVal ownerPassword As String)
'Add watermark to pdf pages using an image
Public Shared Sub AddWatermarkImage(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkImage As String)
'Add water mark to all pdf pages using text
Public Shared Sub AddWatermarkText(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkText() As String, _
Optional ByVal watermarkFont As iTextSharp.text.pdf.BaseFont = Nothing, _
Optional ByVal watermarkFontSize As Single = 48, _
Optional ByVal watermarkFontColor As iTextSharp.text.BaseColor = Nothing, _
Optional ByVal watermarkFontOpacity As Single = 0.3F, _
Optional ByVal watermarkRotation As Single = 45.0F)
'Merge multiple pdfs into a single one.
Public Shared Function MergePdfFiles(ByVal pdfFiles() As String, ByVal outputPath As String, _
Optional ByVal authorName As String = "", _
Optional ByVal creatorName As String = "", _
Optional ByVal subject As String = "", _
Optional ByVal title As String = "", _
Optional ByVal keywords As String = "") As Boolean
'Merge multiple pdf's into one with all bookmarks preserved
Public Shared Function MergePdfFilesWithBookmarks(ByVal sourcePdfs() As String, ByVal outputPdf As String) As Boolean
'Add document outline (bookmarks) to a pdf
Public Shared Sub AddDocumentOutline(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal outlineTable As System.Data.DataTable)
'Extract urls from a pdf
Public Shared Function ExtractURLs(ByVal sourcePdf As String, Optional ByVal pageNumbers() As Integer = Nothing) As System.Data.DataTable
'Extract images from a pdf
Public Shared Function ExtractImages(ByVal sourcePdf As String) As List(Of Image)
'Fill a form
Public Shared Sub FillAcroForm(ByVal sourcePdf As String, ByVal fieldData As DataRow, ByVal outputPdf As String)
Public Shared Sub FillMyForm(ByVal sourcePdf As String, ByVal fieldData As DataRow, ByVal outputPdf As String)
'Add annotatation
Public Shared Sub AddTextAnnotation(ByVal sourcePdf As String, ByVal outputPdf As String)
Public Shared Function GetAcroFieldData(ByVal sourcePdf As String) As Dictionary(Of String, String)
Public Shared Function GetPdfSummary(ByVal sourcePdf As String) As DataTable
Public Shared Function ReplacePagesWithBlank(ByVal sourcePdf As String, _
ByVal pagesToReplace As List(Of Integer), _
ByVal outPdf As String, _
Optional ByVal templatePdf As String = "") As Boolean
Public Shared Function InsertPages(ByVal sourcePdf As String, _
ByVal pagesToInsert As Dictionary(Of Integer, iTextSharp.text.pdf.PdfImportedPage), _
ByVal outPdf As String) As Boolean
Public Shared Function RemovePages(ByVal sourcePdf As String, ByVal pagesToRemove As List(Of Integer), ByVal outputPdf As String) As Boolean
'A demo on how to draw various shapes in itextsharp
Public Shared Sub DrawShapesDemo(ByVal sourcePdf As String, ByVal outputPdf As String)
Public Shared Sub AddImageToPage(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal imgPath As String, ByVal imgLocation As Point, ByVal imgSize As Size, Optional ByVal pages() As Integer = Nothing)
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Hi, Friends
I am new to this forum please help me with my problem both source and output pdf files are attached please help me producing the output file as i have more than 500 pages in one source file and more than 20 pdf files.
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Originally Posted by Skylimitz
Hi, Friends
I am new to this forum please help me with my problem both source and output pdf files are attached please help me producing the output file as i have more than 500 pages in one source file and more than 20 pdf files.
Its Very urgent
- Thanks in Advance
Are you asking me to do the work for you? Sorry, but it doesn't work that way. If you have a coding question than I'll be more than happy to try to give you an answer if I can.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Thanks for reply
but please let me know about some technique which can help me doing so please.. help me i don't want u to do the coding but u can post some techniques which can help
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Based on the sample pdf files you posted, there is no easy way you can split the source file to get the output you want. You are trying to split the data in 1 pdf page into several pages. To do this, you will need to read the source file data (if possible) and the create new output pdf files on the fly.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Dear Stanav,
Thanks for the valuable post that helped me in my projects.
I need 1 more input from your side i.e. the way out for removing the PDF file
restrictions which is encrypted with 256 bit encryption with user and/or owner password.
Really looking for your expert reply on this.
thanks n regards....
RkTech
==========================================================
Originally Posted by stanav
This thread was originally about extracting and merging pdf files using iTextSharp. However, as time goes by, I have added a lot more code to do other stuff and put them all together into a handy class called PdfManipulation. There are 2 classes as below (choose the one that matches the iTextSharp version you're using):
1. The original PdfManipulation.vb class is coded based on itextsharp version 4. This class is obsolete and no longer maintained.
2. The updated PdfManipulation2.vb class is for the newer itextsharp version 5. This class also contains alot more methods than the original one and I highly recommend it over the old one. I will update this class from time to time to fix bugs and/or add more functionality. Consider it's a work in progress
Please verify the version of iTextSharp you're using and download the correct class.
Below is the list of public methods in the new PdfManipulation2 class
vb.net Code:
'Remove all restrictions from a pdf file
Public Shared Function RemoveRestrictions(ByVal restrictedPdf As String, Optional ByVal password As String = Nothing, Optional ByVal saveABackup As Boolean = True) As Boolean
'Parse text from a specified range of pdf pages
Public Shared Function ParsePdfText(ByVal sourcePDF As String, _
Optional ByVal fromPageNum As Integer = 0, _
Optional ByVal toPageNum As Integer = 0) As String
'Parse all text from a pdf
Public Shared Function ParseAllPdfText(ByVal sourcePDF As String) As Dictionary(Of Integer, String)
'Page to page comparision of 2 pdf files and write the differences to a resulting text file
Public Shared Sub ComparePdfs(ByVal pdf1 As String, ByVal pdf2 As String, _
ByVal resultFile As String, _
Optional ByVal fromPageNum As Integer = 0, _
Optional ByVal toPageNum As Integer = 0)
'Extract specified pages from a pdf to create a new pdf
Public Shared Sub ExtractPdfPages(ByVal sourcePdf As String, ByVal pageNumbersToExtract As Integer(), ByVal outPdf As String)
'Split a pdf into specified number of pdfs
Public Shared Sub SplitPdfByParts(ByVal sourcePdf As String, ByVal parts As Integer, ByVal baseNameOutPdf As String)
'Split a pdf into multiple pdfs each containing a specified number of pages.
Public Shared Sub SplitPdfByPages(ByVal sourcePdf As String, ByVal numOfPages As Integer, ByVal baseNameOutPdf As String)
'Extract pages from multiple source pdfs and merge into a final pdf
Public Shared Sub ExtractAndMergePdfPages(ByVal sourceTable As DataTable, ByVal outPdf As String)
'Set security password on an existing pdf file
Public Shared Sub SetSecurityPasswords(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal userPassword As String, ByVal ownerPassword As String)
'Add watermark to pdf pages using an image
Public Shared Sub AddWatermarkImage(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkImage As String)
'Add water mark to all pdf pages using text
Public Shared Sub AddWatermarkText(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkText() As String, _
Optional ByVal watermarkFont As iTextSharp.text.pdf.BaseFont = Nothing, _
Optional ByVal watermarkFontSize As Single = 48, _
Optional ByVal watermarkFontColor As iTextSharp.text.BaseColor = Nothing, _
Optional ByVal watermarkFontOpacity As Single = 0.3F, _
Optional ByVal watermarkRotation As Single = 45.0F)
'Merge multiple pdfs into a single one.
Public Shared Function MergePdfFiles(ByVal pdfFiles() As String, ByVal outputPath As String, _
Optional ByVal authorName As String = "", _
Optional ByVal creatorName As String = "", _
Optional ByVal subject As String = "", _
Optional ByVal title As String = "", _
Optional ByVal keywords As String = "") As Boolean
'Merge multiple pdf's into one with all bookmarks preserved
Public Shared Function MergePdfFilesWithBookmarks(ByVal sourcePdfs() As String, ByVal outputPdf As String) As Boolean
'Add document outline (bookmarks) to a pdf
Public Shared Sub AddDocumentOutline(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal outlineTable As System.Data.DataTable)
'Extract urls from a pdf
Public Shared Function ExtractURLs(ByVal sourcePdf As String, Optional ByVal pageNumbers() As Integer = Nothing) As System.Data.DataTable
'Extract images from a pdf
Public Shared Function ExtractImages(ByVal sourcePdf As String) As List(Of Image)
'Fill a form
Public Shared Sub FillAcroForm(ByVal sourcePdf As String, ByVal fieldData As DataRow, ByVal outputPdf As String)
Public Shared Sub FillMyForm(ByVal sourcePdf As String, ByVal fieldData As DataRow, ByVal outputPdf As String)
'Add annotatation
Public Shared Sub AddTextAnnotation(ByVal sourcePdf As String, ByVal outputPdf As String)
Public Shared Function GetAcroFieldData(ByVal sourcePdf As String) As Dictionary(Of String, String)
Public Shared Function GetPdfSummary(ByVal sourcePdf As String) As DataTable
Public Shared Function ReplacePagesWithBlank(ByVal sourcePdf As String, _
ByVal pagesToReplace As List(Of Integer), _
ByVal outPdf As String, _
Optional ByVal templatePdf As String = "") As Boolean
Public Shared Function InsertPages(ByVal sourcePdf As String, _
ByVal pagesToInsert As Dictionary(Of Integer, iTextSharp.text.pdf.PdfImportedPage), _
ByVal outPdf As String) As Boolean
Public Shared Function RemovePages(ByVal sourcePdf As String, ByVal pagesToRemove As List(Of Integer), ByVal outputPdf As String) As Boolean
'A demo on how to draw various shapes in itextsharp
Public Shared Sub DrawShapesDemo(ByVal sourcePdf As String, ByVal outputPdf As String)
Public Shared Sub AddImageToPage(ByVal sourcePdf As String, ByVal outputPdf As String, ByVal imgPath As String, ByVal imgLocation As Point, ByVal imgSize As Size, Optional ByVal pages() As Integer = Nothing)
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Originally Posted by rktech
Dear Stanav,
Thanks for the valuable post that helped me in my projects.
I need 1 more input from your side i.e. the way out for removing the PDF file
restrictions which is encrypted with 256 bit encryption with user and/or owner password.
Really looking for your expert reply on this.
thanks n regards....
RkTech
==========================================================
As far as I know, the current version of iTextSharp doesn't support AES 256 encryption. Hopefully the developers will implement it in the next release of iTextSharp.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
thanx 4 ur reply stanav. itext 5.1.1 supports 256 bit encryption.
Originally Posted by stanav
As far as I know, the current version of iTextSharp doesn't support AES 256 encryption. Hopefully the developers will implement it in the next release of iTextSharp.
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Originally Posted by rktech
thanx 4 ur reply stanav. itext 5.1.1 supports 256 bit encryption.
Oh, really? I didn't know that. I'm still on 5.0.2 (no immediate need to upgrade yet).
I still wonder though, if that is the case as you said 5.1.1 supports 256 AES then why wouldn't it work? Have you tried using UTF-8 encoder to convert the password to bytes array and then passing it to the constructor of the pdfreader class? In my code, I was using the system default encoder, which might not be UTF8 in other regions.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Hi stanav,
Thank you for this information. It has been very helpful.
Can the SplitPdfByParts method split a single sheet into 4 seperate sheets by dividing the original sheet into 4 equal quadrants? What I mean by this is down the middle horizontally and vertically.
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Originally Posted by FullQuiver
Hi stanav,
Thank you for this information. It has been very helpful.
Can the SplitPdfByParts method split a single sheet into 4 seperate sheets by dividing the original sheet into 4 equal quadrants? What I mean by this is down the middle horizontally and vertically.
Thanks.
It's much easier to do it the other way around (merging 4 pages into 1 page)
As for your question, it depends on what kind of data you have in the source pdf page. If you can somehow extract the data from the page, you can then can use that data to create 4 new pages in a new pdf document.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Thank you for your quick reply. I have multi page pdf's where some of the pages look like the example provided. I need to split those 4 blocks off into individual sheets.
Thanks for the help.
Last edited by FullQuiver; Dec 21st, 2011 at 04:32 PM.
Reason: Removed Attachment
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Yes Stanav 5.1.1 supports 256 bit AES. As i treat you as an expert in this PDF subject so it would be great if you try your encoding permutation & combinations in same, as i do have less knowledge in same area.
Also please lemme know in case of any input or discussion.
Thanks....
Take Care..
============
Originally Posted by stanav
Oh, really? I didn't know that. I'm still on 5.0.2 (no immediate need to upgrade yet).
I still wonder though, if that is the case as you said 5.1.1 supports 256 AES then why wouldn't it work? Have you tried using UTF-8 encoder to convert the password to bytes array and then passing it to the constructor of the pdfreader class? In my code, I was using the system default encoder, which might not be UTF8 in other regions.
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Originally Posted by rktech
Yes Stanav 5.1.1 supports 256 bit AES. As i treat you as an expert in this PDF subject so it would be great if you try your encoding permutation & combinations in same, as i do have less knowledge in same area.
Also please lemme know in case of any input or discussion.
Thanks....
Take Care..
============
I downloaded the newest version of itextsharp 5.1.3 to try out and I can't seem to find any evidence of it supporting AES_256 encryption. If you look at all the encryption constants in the PdfEncryption class, there are only 3: standard_encryption_40, standard_encryption_128 and aes_128. If it supported aes 256, I should've seen the declaration of aes_256 constant.
Can you provide some links/source where it is confirmed that aes_256 is supported?
Last edited by stanav; Dec 15th, 2011 at 12:51 PM.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Dear Stanav,
I have checked same in itext 5.1.1 & found PdfWriter.ENCRYPTION_AES_256 in the PdfWriter class.
Please lemme know for any additional information.
thanks,
RkTech
===============
Originally Posted by stanav
I downloaded the newest version of itextsharp 5.1.3 to try out and I can't seem to find any evidence of it supporting AES_256 encryption. If you look at all the encryption constants in the PdfEncryption class, there are only 3: standard_encryption_40, standard_encryption_128 and aes_128. If it supported aes 256, I should've seen the declaration of aes_256 constant.
Can you provide some links/source where it is confirmed that aes_256 is supported?
Re: [VB.NET] Pdf Manipulation Class Using iTextSharp
Originally Posted by rktech
Dear Stanav,
I have checked same in itext 5.1.1 & found PdfWriter.ENCRYPTION_AES_256 in the PdfWriter class.
Please lemme know for any additional information.
thanks,
RkTech
===============
Dear RkTech,
After I saw your mentioning of PdfWriter.ENCRYPTION_AES_256 constant, I took a closer look at the PdfReader class source code and you're right, it does support AES256. According to Adobe's PDF specification, it uses a new algorithm, 3.2a, to compute the encryption key. This algorithm uses the 1st 127 bytes from an utf-8 password (anything longer gets truncated) + 8 bytes salt + 48 bytes U string and then computes the aes-256 hash of the result to be used as the password bytes array...
Anyway, I'd give it a try if you can provide me a sample aes-256 password protected pdf.
Happy Holidays.....
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Dear RkTech,
I've made some changes to the PdfManipulation2 class and it now supports opening pdf files with AES-256 password protection. Please download the new version and try it out.
Happy Holidays.
Stanav.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Hi, every one i want to write a program in VB .NET for find the invalid / unreferenced Keys in Registry and fix them please any one tell me the technique by which i can do this stuff or any one can feel free to provide me the Little code
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Hey Stan,
I have an access database that creates a PDF report. In this report each page is a separate invoice. Each invoice is the same layout only the data on the pages differ. What i'd like to do is take this PDF report and split each invoice into it's own separate pdf file. Is this something i can use what you have provided us with to do? If so do you have any suggestions on what i can use to complete this.
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Originally Posted by jjsaw5
Hey Stan,
I have an access database that creates a PDF report. In this report each page is a separate invoice. Each invoice is the same layout only the data on the pages differ. What i'd like to do is take this PDF report and split each invoice into it's own separate pdf file. Is this something i can use what you have provided us with to do? If so do you have any suggestions on what i can use to complete this.
Thanks very much for you time!
If all the invoices are in the same format (same number of pages) and you know before hand how many pages each individual rinvoice should have, you can use the PdfManipulation2.SplitPdfByPages method which can be found in the PdfManipulation2 class. On the other hand, if the number of pages in each invoice differs, as long as you know the number of pages for each of them, you can modify the above mentioned method a little to have it split the pdf the way you want (it tough to find out how many pages each invoice has though).
Best luck.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Hi All,
I was wondering if any of you can help me out with my problem - I am calling iTextSharp from VB .Net windows form to create PDF report.
Ho can I -
1. Create multiple headers(header1, header 2 etc, logo)
2. Multiple footers - Page X of Y, some other text etc.
3. Positioning data on PDF from SQL Server.
I would really appreciate if any kind soul can give me some direction or code sample.
then...
test1.pdf will be approx 1/3 the size of test.pdf
test2.pdf will be approx 2/3 the size of test.pdf
test3.pdf will be just shy of the full size of test.pdf
When viewed in a PDF viewer, each extracted document will show the proper single page and nothing else. Everything looks fine.
If i open up test3.pdf and look for the /CCITTFAXDECODE entries, I find 3 of them, one for each page of the original PDF.
Based on these results, it appears that the ExtractPdfPage function (or the iTextSharp code that it uses) is failing to remove vestiges of the pages which precede the extracted page -- specifically the images they contain.
Is this bug happening for anyone else? If so, does anyone know how to fix it?
then...
test1.pdf will be approx 1/3 the size of test.pdf
test2.pdf will be approx 2/3 the size of test.pdf
test3.pdf will be just shy of the full size of test.pdf
When viewed in a PDF viewer, each extracted document will show the proper single page and nothing else. Everything looks fine.
If i open up test3.pdf and look for the /CCITTFAXDECODE entries, I find 3 of them, one for each page of the original PDF.
Based on these results, it appears that the ExtractPdfPage function (or the iTextSharp code that it uses) is failing to remove vestiges of the pages which precede the extracted page -- specifically the images they contain.
Is this bug happening for anyone else? If so, does anyone know how to fix it?
Thanks for raising up the issue. Currently, I don't have much free time to investigate the bug. I'll look into it when I have a chance.
Happy coding.
Stanav.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Hey Stanav
I am first time working on PDF documents.I was searching on Rotation of a PDF page. I got some code samples regarding rotations by 90,180,270,360 degrees.
But my problem is that if there is a very small rotation required of the order of few degrees .....
Is there any way that we can specify an angle using a slider bar or use the mouse to click and rotate the PDF page...
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
I'm getting confused really bad on this :
All i need to do is get the bookmarks and the pdf file names they point to.
all of the bookmarks point to other pdf files which should be on the HD.however i've noticed that at the time i downloaded these files some of the files they were supposed have were not on the server..or i didn't download em or something..
so now i have 100's of files with missing pdf's..too many to go thru and correct manually.
So i thought that i could extract the bookmarks and the files they point to..then take those file names add the web address for each one(all located on the same server) and make a download list.
So i did this
Code:
Option Explicit On
Public Class Form1
'Specified the path to the source pdf file
Dim sourcePdf As String = "E:\pdfs\1.pdf"
'save as XML file
Dim outputXML As String = "E:\1.xml"
Public Shared Function ExportBookmarksToXML(ByVal sourcePdf As String, ByVal outputXML As String) As Boolean
Dim result As Boolean = False
Try
Dim reader As New iTextSharp.text.pdf.PdfReader(sourcePdf)
Dim bookmarks As System.Collections.Generic.List(Of System.Collections.Generic.Dictionary(Of String, Object)) = SimpleBookmark.GetBookmark(reader)
Using outFile As New IO.StreamWriter(outputXML)
SimpleBookmark.ExportToXML(bookmarks, outFile, "ISO8859-1", True)
End Using
reader.Close()
result = True
Catch ex As Exception
Throw New ApplicationException(ex.Message, ex)
End Try
Return result
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ExportBookmarksToXML(sourcePdf, outputXML)
End Sub
End Class
i get errors saying this is not declared so i searched thru the itextSharp zip file and found the ones that were missing..and those started saying this was missing ,that was missing ,this wasn't declared,,it never ended..
it was like i needed to have every single one of those class files in my project??
I had to convert those to vb.net tho..luckily i found a bulk converter which worked online.
So i'm gonna have to ask if someone could PLEASE tell me how i can fix this so i can get it to do what i need it to..i'm going around in circles here,,, or even better still, put all the subs that i need into one module file for me.
Thanks
Last edited by M@dH@tter; Jun 2nd, 2012 at 07:52 AM.
Reason: found problemo
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
well at the time i posted this i didnt know there was a dll hehe i was trying to add all the source code into the project..but now that i've added the .dll it's working good..how can i export to a txt file tho..not xml?
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Different question about this ..
is it possible to use this to edit bookmarks..
so if my main pdf file has bookmarks to say \1.pdf, \2.pdf. \3.pdf etc,..
and i wanted to put the bookmarked files into a separate folder instead of having them in with the main pdf file..can i alter the bookmarks to reflect the new directory where they can be found.
like \temp\1.pdf
Re: [VB.NET] Extract Pages and Split Pdf Files Using iTextSharp
Originally Posted by M@dH@tter
Different question about this ..
is it possible to use this to edit bookmarks..
so if my main pdf file has bookmarks to say \1.pdf, \2.pdf. \3.pdf etc,..
and i wanted to put the bookmarked files into a separate folder instead of having them in with the main pdf file..can i alter the bookmarks to reflect the new directory where they can be found.
like \temp\1.pdf
????
Yes, you can do that with iTextSharp. Bookmarks in pdf's are actually annotations, so you might want to look for examples of creating/editing annotations. I'm very busy at the moment and will not have time to write any example code for you. Sorry for that.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -