I want to show pdf from certain page to certain page not whole pdf. - Page 3 - RadaeePDF.com - Results from #12
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF

TOPIC: I want to show pdf from certain page to certain page not whole pdf.

I want to show pdf from certain page to certain page not whole pdf. 1 week 4 days ago #14405

  • apdeveloper
  • apdeveloper's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
Dear Team,
You have shared the same code which you have already shared with me in the above answer.
My question was to you that reader is nil and app gets crash when i am opening the pdf.

//Below is the code which i am calling for creating pdf and opening pdf from my swift project.

plugin.createAgendaPDf(filepath, pdfDestination: destFilePathforPDF, pdfPassword: Password, startPageNo: 1, endPageNo: 2)
let reader = plugin.show(destFilePathforPDF, atPage: 0, withPassword: "", readOnly: false, autoSave: true)

Please Log in or Create an account to join the conversation.

I want to show pdf from certain page to certain page not whole pdf. 1 week 4 days ago #14406

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 561
  • Karma: 21
  • Thank you received: 65
it is not the same code, please focus on these lines:
[doc_src open:@"your source path" :@"password"];
[doc_dst create:@"your destination path"];
PDFImportCtx *ctx = [doc_dst newImportCtx:doc_src];
Are you able to check if the new pdf file has been created correctly before calling show method?
We tried the shared method (with valid doc path) in Swift demo and we are able to create the new file correctly.
Could you please share also the implementation of createAgendaPDf method?
Are you able to open the original file with show method? (without calling createAgendaPDf)

Please Log in or Create an account to join the conversation.

I want to show pdf from certain page to certain page not whole pdf. 1 week 4 days ago #14407

  • apdeveloper
  • apdeveloper's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
Dear Team,
New Pdf file has been created and even i am able to open the original pdf file.
//Below is the code of Swift Project

//RadaeePDFPlugin.h file method created.
-(void)createAgendaPDf:(NSString *)PDFsource pdfDestination:(NSString *)pdfDestination pdfPassword:(NSString *)pdfPassword startPageNo:(int)startPageNo endPageNo:(int)endPageNo;

//Below is function to call the method.

var destFilePathforPdf = "\(filepath)\("_")\(outlineData.replacingOccurrences(of: " ", with: ""))"
destFilePathforPdf = destFilePathforPdf.replacingOccurrences(of: ".", with: "")

let fileManager = FileManager.default
if(!fileManager.fileExists(atPath: destFilePathforPdf)){
print("file Not Exits
")
plugin.createAgendaPDf(filepath, pdfDestination: destFilePathforPdf, pdfPassword: Password, startPageNo: 1, endPageNo: 2)

let reader = plugin.show(destFilePathforPdf, atPage: 0, withPassword: "", readOnly: false, autoSave: true)
if (reader == nil) {
alert(title: "No Such File", message: "")
}else{
let vc: UIViewController = reader1 as! UIViewController
self.navigationController?.navigationBar.isTranslucent = false;
self.navigationController?.pushViewController(vc, animated: true)
}
}else{
print("file Exits
")
let reader = plugin.show(destFilePathforPdf, atPage: 0, withPassword: "", readOnly: false, autoSave: true)
if (reader == nil) {
alert(title: "No Such File", message: "")
}else{
let vc: UIViewController = reader1 as! UIViewController
self.navigationController?.navigationBar.isTranslucent = false;
self.navigationController?.pushViewController(vc, animated: true)
}
}
//Below is code for Objective C project.

//RadaeePDFPlugin.h file method created.
-(void)createAgendaPDf:(NSString *)PDFsource pdfDestination:(NSString *)pdfDestination pdfPassword:(NSString *)pdfPassword startPageNo:(int)startPageNo endPageNo:(int)endPageNo;

//In RadaeePDFPlugin.m file
-(void)createAgendaPDf:(NSString *)PDFsource pdfDestination:(NSString *)pdfDestination pdfPassword:(NSString *)pdfPassword startPageNo:(int)startPageNo endPageNo:(int)endPageNo{
PDFDoc *doc_src;
PDFDoc *doc_dst;
doc_src = [[PDFDoc alloc] init];
doc_dst = [[PDFDoc alloc] init];
[doc_src open:PDFsource :pdfPassword];
[doc_dst create:pdfDestination];
PDFImportCtx *ctx = [doc_dst newImportCtx:doc_src];
int pgno = startPageNo;
int pgend = 2;
int pgdst = endPageNo;
while(pgno < pgend)
{
[ctx import :pgno :pgdst];
pgno++;
pgdst++;
}
[doc_dst save];
ctx = nil;
doc_src = nil;
doc_dst = nil;
NSLog(@"created Agenda");
}

Please Log in or Create an account to join the conversation.

I want to show pdf from certain page to certain page not whole pdf. 1 week 4 days ago #14408

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 561
  • Karma: 21
  • Thank you received: 65
I think that this part is wrong:
int pgno = startPageNo;
int pgend = 2;
int pgdst = endPageNo;

pgno it's the start page (it's ok), pgend it's the end page and you have to assign your endPageNo.
pgdest is the destination page of the new file, so, in this case, it must be initialized with 0.
Something like:
int pgno = startPageNo;
int pgend = endPageNo;
int pgdst = 0;

Please check if it fixes your code.

Please Log in or Create an account to join the conversation.

I want to show pdf from certain page to certain page not whole pdf. 1 week 4 days ago #14409

  • apdeveloper
  • apdeveloper's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
Dear Team,
This does not resolve my issue can you please check.

Please Log in or Create an account to join the conversation.

I want to show pdf from certain page to certain page not whole pdf. 1 week 4 days ago #14410

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 561
  • Karma: 21
  • Thank you received: 65
We are still not able to reproduce your issue, we are able to create a new pdf file with the shared method and open it.
Could you please share your test pdf file?

Here is the Swift code used to check the feature:
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        let path: String = documentsPath + "/test.pdf"
        let plugin: RadaeePDFPlugin = self.pluginInit()
        plugin.setDelegate(self);     
        plugin.createAgendaPDf(path, pdfDestination: documentsPath + "/new.pdf", pdfPassword: "", startPageNo: 1, endPageNo: 2);
        let reader = plugin.show(documentsPath + "/new.pdf", withPassword: "")

Another quick info: where are located your source and destination files?

Please Log in or Create an account to join the conversation.

Last edit: by emanuele.
Powered by Kunena Forum