Q: I am using following code to merge 2 PDF
Total of both PDF files size is 85K
When I was merged the files; size become 241K
Can you please let me know where am I doing wrong?
PDFNet.Initialize()
Dim url As String = "E:\temp\BMU01_ALBAM_1106_GSM.pdf"
If url <> "" Then
'Dim pageNumber As Integer =
dr.Item("ActualPageNumber")
Dim sourcePDFPathWithFileName As String = url
Dim sourcePDFdoc As PDFDoc = New
PDFDoc(sourcePDFPathWithFileName)
sourcePDFdoc.InitializeSecurityHandler()
'Dim sourcePDFIterator As PageIterator =
sourcePDFdoc.PageFind(pageNumber)
'Dim sourcePDFpage As Page = sourcePDFIterator.Current
Dim page_end As PageIterator = sourcePDFdoc.PageEnd()
Dim itr As PageIterator = sourcePDFdoc.PageBegin()
While Not itr.Equals(page_end)
' Place the first page
Dim sourcePDFpage As Page = itr.Current()
Dim mrec As Rect = sourcePDFpage.GetMediaBox
newPDF.PagePushBack(sourcePDFpage)
itr.Next()
End While
sourcePDFdoc.Close()
sourcePDFdoc.Dispose()
bFileToSave = True
sourcePDFdoc.Close()
sourcePDFdoc.Dispose()
End If
' Next
If bFileToSave = True Then
newPDF.Save("E:\temp\NEW\new1.pdf",
End If
newPDF.Close()
newPDF.Dispose()
----
A:
The output file size is large because you are importing PDF pages one
by one instead of all at once using ImportPages.
To keep the file size down, you need to use pdfdoc.ImportPages() before
placing the pages using pdfdoc.PagePushBack() etc.
For more information please see the following resources:
- Copying/Merging Pages: www.pdftron.com/net/usermanual.html#copy_pg
- How do I reduce the file size of a merged PDF document?:
www.pdftron.com/net/faq.html#merge_00
- The last code sample in PDFPage sample project:
www.pdftron.com/net/samplecode.html#PDFPage
Also make sure to specify SDF.Doc.SaveOptions.e_remove_unused or
SDF.Doc.SaveOptions.e_linearized as a hint to Save method. For example:
ew_doc.Save("c:/out.pdf", SDF.Doc.SaveOptions.e_remove_unused);