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 8411713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:29:34+00:00 2026-06-10T00:29:34+00:00

My first time dealing with this technology. Essentially I got a core data database

  • 0

My first time dealing with this technology.

Essentially I got a core data database of data I wish to generated table out of.

I have found this post here:

Is there any way to generate PDF file from a XML/HTML template in iOs

but I am stumbling on trying to get something visible out of the generated PDF.

So far, I have only managed to get the PDF to show 2 blank white pages, it doesn’t print my simple text.

Here’s my class file:

// PageRenderer Class header file
#import <UIKit/UIKit.h>

@interface PageRenderer : UIPrintPageRenderer
{
    BOOL _generatingPdf;
}

-(CGRect) paperRect;
-(CGRect) printableRect;
-(NSData*) printToPDF;

@end



// PageRenderer Class implementation file
#import "PageRenderer.h"

@implementation PageRenderer

- (CGRect) paperRect
{     
    if (!_generatingPdf)
    {
        return [super paperRect];
    }

    return UIGraphicsGetPDFContextBounds();
}

- (CGRect) printableRect
{
    if (!_generatingPdf)
        return [super printableRect];

    return CGRectInset( self.paperRect, 20, 20 );
}

- (NSData*) printToPDF
{
    _generatingPdf = YES;

    NSMutableData *pdfData = [NSMutableData data];

    UIGraphicsBeginPDFContextToData( pdfData, CGRectMake(0, 0, 792, 612), nil );  // letter-size, landscape

    [self prepareForDrawingPages: NSMakeRange(0, 1)];

    CGRect bounds = UIGraphicsGetPDFContextBounds();

    for ( int i = 0 ; i < self.numberOfPages ; i++ )
    {
        UIGraphicsBeginPDFPage();

        [self drawPageAtIndex: i inRect: bounds];
    }

    UIGraphicsEndPDFContext();

    _generatingPdf = NO;

    //    NSString* filename = @"/Volumes/Macintosh HD 2/test.pdf";
    //    [pdfData writeToFile: filename  atomically: YES];

    return pdfData;
}

- (NSInteger)numberOfPages
{
    return 1;
}

@end

Here is my code where I am generating the PDF file:

-(void)generateLog
{        
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];

    pic.delegate = self;

    PageRenderer *pageRenderer = [[PageRenderer alloc] init];

    pic.printPageRenderer = pageRenderer;

    UIMarkupTextPrintFormatter *html = [[UIMarkupTextPrintFormatter alloc] init];
    //html.markupText = @"<table border='1' width='500' height='200'>";
    html.markupText = @"<html><head></head><body><p>HTML TEXT HERE, <b>BOLD</b> THIS!</p></body></html>";
    html.startPage = 0;
    html.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
    html.maximumContentWidth = 6 * 72.0;

    pic.printFormatter = html;

    [pageRenderer drawPrintFormatter:html forPageAtIndex:0];    

    NSData *pdfData = [pageRenderer printToPDF];

    [pdfData writeToFile:[MediaDirectory mediaPathForFileName:@"triplog.pdf"] atomically:YES];

    NSLog(@"triplog.pdf written to %@", [MediaDirectory mediaPathForFileName:@"triplog.pdf"]);

    [html release];
}

Any ideas why I am getting a blank page?

  • 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-10T00:29:36+00:00Added an answer on June 10, 2026 at 12:29 am

    -_-! finally something!

    Seems like I need to use:

    [pageRenderer addPrintFormatter:html startingAtPageAtIndex:0];
    

    instead of:

    [pageRenderer drawPrintFormatter:html forPageAtIndex:0];
    

    After I did that, it started working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First time with this trouble when dealing with a MySQL table. I'm inserting bar
This was the first time I encountered this kind of error after dealing with
First time post. As an example, say I have a table with 12 entries;
Sorry for the kind of n00b question, but this is my first time dealing
First time dealing with json. I have a php file that processes the post
This is my first time dealing with windows. I tried to create thread, but
It's my first time dealing with cookies in JavaScript and the below script works
First time working with JSON in Rails and trying to figure out something which
first time posting here so be gentle :) On my web pages I have
Hi, ive been dealing with this for some time now and need your help.

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.