void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int bps) { fz_context *ctx = app->ctx; char *password = ""; fz_try(ctx) { fz_register_document_handlers(ctx); #ifdef HAVE_CURL if (!strncmp(filename, "http://", 7)) { app->stream = fz_stream_from_curl(ctx, filename, pdfapp_more_data, app); while (1) { fz_try(ctx) { fz_seek(ctx, app->stream, 0, SEEK_SET); app->doc = fz_open_document_with_stream(ctx, filename, app->stream); } fz_catch(ctx) { if (fz_caught(ctx) == FZ_ERROR_TRYLATER) { pdfapp_warn(app, "not enough data to open yet"); continue; } fz_rethrow(ctx); } break; } } else #endif if (bps == 0)
HRESULT MuPDFDoc::InitDocument(unsigned char *buffer, int bufferLen, const char *mimeType) { fz_stream *stream = OpenStream(buffer, bufferLen); if (!stream) { return E_OUTOFMEMORY; } else { fz_try(m_context) { m_document = fz_open_document_with_stream(m_context, mimeType, stream); m_outline = fz_load_outline(m_document); //AlertsInit(); } fz_always(m_context) { fz_close(stream); } fz_catch(m_context) { return E_INVALIDARG; } return S_OK; } }
void ViewerWidget::load(const QByteArray &data) { scene->clear(); QList<QGraphicsItem *> items; QPixmap pixmap; if (pixmap.loadFromData(data)) { items << new QGraphicsPixmapItem(pixmap); } else if (data.startsWith("%PDF")) { fz_stream *stream = fz_open_memory(context, (unsigned char *)data.constData(), data.length()); fz_document *doc = fz_open_document_with_stream(context, ".pdf", stream); fz_close(stream); int pagecount = fz_count_pages(doc); for (int i = 0; i < pagecount; i++) { fz_page *page = fz_load_page(doc, i); fz_rect bounds; fz_bound_page(doc, page, &bounds); fz_display_list *list = fz_new_display_list(context); fz_device *dev = fz_new_list_device(context, list); fz_run_page(doc, page, dev, &fz_identity, NULL); fz_free_device(dev); fz_free_page(doc, page); PageItem *item = new PageItem(context, list, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); item->setCacheMode(QGraphicsItem::DeviceCoordinateCache); items << item; } fz_close_document(doc); } else { scene->setSceneRect(0, 0, 0, 0); return; } int top = 0; QPen outline(Qt::lightGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); outline.setCosmetic(true); foreach (QGraphicsItem *item, items) { QGraphicsRectItem *rim = new QGraphicsRectItem(item->boundingRect()); item->setPos(0, top); rim->setPos(0, top); rim->setPen(outline); rim->setBrush(Qt::NoBrush); scene->addItem(rim); scene->addItem(item); top += item->boundingRect().height() + SPACING; }