Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:13:57+00:00 2026-06-14T04:13:57+00:00

I have a long html page and wanted to convert it in to a

  • 0

I have a long html page and wanted to convert it in to a multipage PDF file.

I have followed the instructions provided in
apple and here – how to make multi page PDF for a given string content.

But the formatting the NSString ( with some like data ) is difficult than creating a html page. I have created this html and displaying it in a UIWebView.

Now I want to create a PDF out of this HTML to a Multi page PDF file.

The code I’m using can create single PDF.

- (void)createPDFfromUIView:(UIWebView *)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

Can any one give some help ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:13:58+00:00Added an answer on June 14, 2026 at 4:13 am

    I created a class based on every good advice I found around. I’ve been digging a lot and I hope my class will offer some good start for anyone trying to create multi-page PDF directly out of some HTML source.

    You’ll find the whole code here with some basic sample code : https://github.com/iclems/iOS-htmltopdf

    I had just the same issue as you and my requirements were:
    – full PDF (real text, no bitmap)
    – smart multi-pages (compared to cutting a full height webview every X pixels…)

    Thus, the solution I use is pretty nice as it resorts to the same tools iOS uses to split pages for print.

    Let me explain, I setup a UIPrintPageRenderer based on the web view print formatter (first tip) :

    UIPrintPageRenderer *render = [[UIPrintPageRenderer alloc] init];
    
    [render addPrintFormatter:webView.viewPrintFormatter startingAtPageAtIndex:0];
    
    CGRect printableRect = CGRectMake(self.pageMargins.left,
                                  self.pageMargins.top,
                                  self.pageSize.width - self.pageMargins.left - self.pageMargins.right,
                                  self.pageSize.height - self.pageMargins.top - self.pageMargins.bottom);
    
    CGRect paperRect = CGRectMake(0, 0, self.pageSize.width, self.pageSize.height);
    
    [render setValue:[NSValue valueWithCGRect:paperRect] forKey:@"paperRect"];
    [render setValue:[NSValue valueWithCGRect:printableRect] forKey:@"printableRect"];
    
    NSData *pdfData = [render printToPDF];
    
    [pdfData writeToFile: self.PDFpath  atomically: YES];
    

    In the meantime, I have created a category on UIPrintPageRenderer to support:

    -(NSData*) printToPDF
    {
        [self doNotRasterizeSubviews:self.view];
    
        NSMutableData *pdfData = [NSMutableData data];
    
        UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil );
    
        [self prepareForDrawingPages: NSMakeRange(0, self.numberOfPages)];
    
        CGRect bounds = UIGraphicsGetPDFContextBounds();
    
        for ( int i = 0 ; i < self.numberOfPages ; i++ )
        {
            UIGraphicsBeginPDFPage();
    
            [self drawPageAtIndex: i inRect: bounds];
        }
    
        UIGraphicsEndPDFContext();
    
        return pdfData;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I for example have <p> some long text </p> on my HTML page,
I have Active-X component on HTML page with long-run method (Process) that fires callback
I have a long HTML page as a string. Throughout, I have image tags
I have a sliding screen on a long HTML page with left and right
Let's say I have a single HTML page. 2000 pixels long for example. I
I have an HTML page which is completely generated from a Python file. I
I have 145064642 chars long HTML String which I am trying to print. When
Apple have long blocked mobile Safari from playing sounds – the usual JavaScript commands
I have long HTTP request ( generating large Excel file - about 60K records
I have long file with the following list: /drivers/isdn/hardware/eicon/message.c//add_b1() /drivers/media/video/saa7134/saa7134-dvb.c//dvb_init() /sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build() /drivers/s390/char/tape_34xx.c//tape_34xx_unit_check() (PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301() /drivers/scsi/sg.c//sg_ioctl()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.